142 points · by masklinn · 6y ago · 160 comments
> Exploiting the bug does not require sudo permissions, merely that pwfeedback be enabled.
> the stack overflow may allow unprivileged users to escalate to the root account. Because the attacker has complete control of the data used to overflow the buffer, there is a high likelihood of exploitability.
https://github.com/sudo-project/sudo/commit/b5d2010b6514ff45...
Time to delete sudo.
We should have standardized a C API to safely read/write buffers from files, networks, etc. decades ago. But here we are in 2020 manually moving pointers around - and what a surprise that we're finding "whoops, another off-by-one error, you know how it goes."
No one should be writing new code to read/write bytes. This should be settled. It's like a carpenter building their own nail gun each time they want to build a house.
AFAICT, the only real changes are in (new) line 411, resetting the cp variable after the loop, and line 416, ignoring write errors. The former is probably the relevant one.
Maybe I'm missing something, but wasn't that a pointless change? The value of the expression was unused, so post- and pre- are equivalent.
The amount of anti-education authoritarian fearmongering in these discussions is disturbing. Then again, given how much everything seems to be rapidly moving in the direction of dystopian corporatocracy, perhaps that's not so surprising.
There's already a few comments about how "safer" languages don't really solve anything. They just push the problems up higher in the stack of abstractions... and when that time comes, what are the chances the "security" fearmongerers will just start blaming something else? It's fundamentally a problem of competence, and doing everything you can to make the world a prison in pursuit of that "perfect security" is really not a good idea. There's no replacement for intelligence.
$40 billion says whoever wrote this knew what they were doing.
There is a Linux port, too
alias sudo='doas'
It's tough to remember to type 'doas' instead of 'sudo', especially when you use both Linux and OpenBSD all the time (which is why I also have a "doas" alias on my Linux hosts!).All of sudo's command line options and config options are part of its complexity.
See https://www.openbsd.org/innovations.html and OpenBSD src commit dated Fri Jul 3 21:51:53 2015 +0000.
But all over the place in C code, you see people open-coding all sorts of fiddly nonsense over and over again. You see people manually manipulate buffer positions and lengths; they'll laboriously type "!strcmp(a, b)" instead of defining a tiny little "streq" function. It's silly. However unsafe C-the-language's memory safety is, the problem is exacerbated by C-the-culture's resistance to using the abstraction features of the language. Why so little imagination?
Maybe it's a kind of self-selection thing: maybe if you're the kind of person comfortable with abstraction, you switch to C++, which is much better at it than C and just as efficient, leaving only the open-code-all-string-manipulation people writing raw C.
Even C++ community is aware of the flaws inherited from C, hence why standard library supports arrays, strings with bounds checking enabled in debug builds and eventually in release as well, if one so wishes.
Papers are going forward to reduce amount of UB in C++.
Meanwhile, on C's side Annex K was moved into optional in C11, instead of trying to fix whatever implementation issues it might have had on C99.
Source, and more info: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm
I do agree that Annex K doesn't provide a proper solution, as data and length keep being separated.
However what I disagree is the way it was left to rotten without adoption, instead of actually fixing it.
Static analysis is not a solution, given that all surveys point out that only a minority cares to actually make use of them, or works in environments where they are welcomed, with supportive toolchains.
Also they don't work across third party binary dependencies, heavily used in the corporate environments.
So unwillingness to improve C language security in the standard shows how little those driving WG 14 care about security.
At least C11 made VLAs optional, which never were a good idea to start with.
> So I think that after the lengthy discussion here, this issue can now be closed. In summary: the use-after-free potential with string_view is accounted for in the Lifetime profile, even if there may be bugs or limitations in preliminary implementations that mean it is not diagnosed.
This is the big difference across both language communities, being willing to improve instead of being stuck with what was born alongside UNIX.
Likewise, even if you're the best programmer in the world, if you write a large C program, sooner or later, you're going to introduce a security vulnerability. Switching to a safe language isn't an admission of some personal inadequacy: it just reflects how the world works. But pride gets in the way.
But perhaps the bigger problem is that consuming third-party libraries in C is so painful. It's not too bad if you stick to shipping on Linux distributions which you're sure package the libraries you depend on. Otherwise, you basically have to vendor the library manually. It is always more convenient to just write "strcpy" in a few (more) places.
Reference-counted heap-allocated strings are fine in practice for almost all programs, and it's easy to write an API that implements this model.
Refcounted strings are actually very nasty to use in C because you have no RAII or other automatic memory management. You have to manually deref every string value when it goes out of scope, or get leaks --- and if you accidentally ever double-deref along some path, you get probably-exploitable use-after-free.
Once you've picked some tradeoffs for your program, you have to live with the fact any foreign C you call isn't using your library so you'll be converting to/from their types (typically const char*) all over the place anyway, so the temptation to "just use chars" will be ever-present.
Given those issues, I'm not surprised I actually haven't seen any C programs use this model.
A technical reason for GNU/Linux not to use Rust or Go is that C supports a lot more platforms so you can't replace core components at this moment, also I want to remind you that memory safe languages existed before Go and Rust and the only project I am aware to create a safe OS and utilities was Midori by Microsoft.
Firefox and it's dependencies is not yet 100% Rust so I honestly expect a new browser started from scratch in a safe language to be done before Firefox is "ported".
That is a gargantuan project considering all the standards you need to support to have a competitive web browser. Especially javascript engine, video codecs and webgl are attack surfaces that is difficult to replace with code written in a safe language.
I think is less work then pressuring existing projects to be rewritten in Rust. I would usggest Rust fans to pcik one of those dependencies like a codec and reimplementit in Rust or gather money to pay someone to do it, I think it would be faster and less hostile.
I think the real problem is
a) C and C++ need a divorce. Because the things that you would do to really fix C make it incompatible with C++.
b) The senior maintainers of the gcc compiler need to be replaced with people willing to take these issues seriously. Right now they are focused on how fast their micro benchmarks run at the expense of everything else.
C++ community mostly adopts ISO C libraries post C89 and everything that has safer alternatives in C++ has been left out.
C style coding is discouraged in modern teaching materials for C++.
Signed integer arithmetic has been partially fixed.
Core guidelines are being pushed and for C++23 there are a couple of papers regarding improving the whole UB stuff.
A lot less than 90% in the graphs at https://www.zdnet.com/article/microsoft-70-percent-of-all-se.... Use-after-free and type-confusion bugs definitely aren't addressed by bounds-checking or split-stack approaches; many heap corruption bugs aren't either.
alias sudo='sudo ./badscript; sudo'
Most Linux/Mac installations are single user anyway, so you can steal the user's private information without even gaining root.Otherwise you're right, despite much cargo cult, in practice pwning an user that can interactively run as root, is the same as pwning root.
If you do development for servers, though, (1) multiuser systems do exist where no or most users do not have sudo access, and (2) privilege separation accounts (such as www for httpd) generally do not run interactive shells. If you can escalate from an untrusted user on a multiuser system or from a non-interactive shell account to root, that's a problem. Dropping this alias won't help you on either of these kinds of system, which are important real world scenarios (but maybe not a scenario you need to care about personally).
It does require though that the user both is allowed to run an interactive shell with sudo, and actually does so, since you have to wait for him to run sudo in bash.
I should probably add a check for catching someone within the sudo timeout and give them a hard time if so.
Also there are userspace rewrites in Go and OCaml.
https://github.com/oreboot/oreboot
Userspace in Go for Core Boot/OreBoot, also started by Ron Minnich.
Similar effort for the PI,
F-Secure Go's bare metal implementation, https://github.com/f-secure-foundry/tamago
For OCaml, there is https://ocaml.github.io/ocamlunix/.
And then all the utilities that come out from MirageOS and Xen projects.
Argh. https://medium.com/elementaryos/loki-updates-for-the-new-yea...
>The code that erases the line of asterisks does not properly reset the buffer position if there is a write error, but it does reset the remaining buffer length...
Then the next paragraph: >Because the remaining buffer length is not reset correctly on write error when the line is erased, a buffer on the stack can be overflowed.
So which is it? Does it correctly reset the buffer remaining length or not?
These types of contradictions existing in bug descriptions do not fill me with confidence that someone has actually fixed the issue. Guess I'll have to dig into this one myself. Just what I wanted to have to do. Excuse me while I go and learn way more about the innards of sudo than I ever wanted to.
Or just disable pwfeedback, if you went out of your way to turn it on for some reason.
Seriously though, as others are saying sarcastically, I'll join them right up: "C is completely fine, you are just doing it wrong, it's a safe language when you know what you are doing".
Yeah, about that. <Glances the article again>
It's not a matter of "if", guys. It's only a matter of "when".
No, not yet. The Rust ecosystem is still not mature enough. One of the big problems is Cargo which sidesteps distro packaging and pulls dependencies from some random server. This doesn't fly if you actually want reproducible builds. The other problems are the complete disregard for dynamic linking and the amount of churn in the standard library and compiler. Give Rust a few more years for things to stabilize and for people to figure out a reasonable way to handle these problems. The work will probably fall on the distro maintainers.
My opinion is that if you're looking for a short-term investment that someone might want to make towards fixing these problems, try working on static analysis security tools for C and C++. It could not be easier to make these now with libclang. Alternatively, maybe get your company to fund a purchase of PVS-Studio or something like that.
So no, Cargo doesn't "sidestep" distribution packaging, it works with distribution packaging.
Also, neither the standard library nor the compiler have "churn"; we're very careful to make sure old code still compiles with current Rust.
>Also, neither the standard library nor the compiler have "churn"; we're very careful to make sure old code still compiles with current Rust.
When did this happen? Last I checked Rust still had no LTS policy and there were no stability guarantees around the syntax, ABI, API, compiler flags, Cargo file format, etc. If some policy has changed here, please link me to any info.
As well, pulling from a random server isn't the problem. Trusting a version to be a particular commit is, which crates.io handles as well as Cargo via cargo publish and the lock file. If you pull a dep, the lock file will guarantee that whatever you pull is going to be identical to what was published (assuming you didn't add a git field to the dependencies list or say version = "*").
As for churn in the std or dynamic linking, I've never had an issue using Rust in production and getting reproducible builds otherwise. Same is true for Clang or GCC/stdlib. APIs aren't being changed, binaries may shift, but unless you're on nightly you're probably not going to see anything break - just get better. But you can handle that, just don't update the compiler until you're ready.
Oracle has SPARC ADI, ARM MTE (now adopted by iOS, in the future Android as well), because the only way to have those magical excellent C coders, is to have the hardware be their tiny wheels.
I'm not really that concerned about C so I won't be able to fund the efforts, but I'm sure once you have a bootable operating system that works with existing software that people will be willing to donate to you on Patreon.