14 ms·
Buffer overflow when pwfeedback is set in sudoers
- masklinn 7y agoJust in from “C is fine just know what you’re doing”. > 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.
- stefan_ 7y agoBest part is the fix: https://github.com/sudo-project/sudo/commit/b5d2010b6514ff45693509273bb07df3abb0bf0a https://github.com/sudo-project/sudo/commit/b5d2010b6514ff45... Time to delete sudo.
- akersten 7y agoEvery time I see a fiddly fix like this where we're changing a buffer counter to a postfix instead of a prefix increment, I always think "why are we doing this shit ourselves?" 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.
- deleted 7y ago[deleted]
- scintill76 7y ago> we're changing a buffer counter to a postfix instead of a prefix increment 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.
- sillysaurusx 7y agoYes. This thread is blind-leading-the-blind. Threads against C almost always are. When I was a pentester, out of more than 50 projects I was on, I always found at least a medium-severity bug (a bug which could allow an attacker to pwn the app using nothing but a web browser). Guess how many of those codebases were written in C? Zero. The smugness is endemic to people outside of security. I was smug too. There are comments I wrote that I cringe at, looking back. Pentesting changes your perspective on things. C isn't going away. Yes, let's make it safer (by pentesting). No, it's not a mortal sin to write C. I'll find ways to exploit your webapp regardless of the language.
- fulafel 7y agoCan I ask what kind of apps you typically worked on? A big part of why people make a big deal of C is that there are lots of code bases that have been under a lot of scrutiny from security minded code reviewers and pentesters and still keep on yielding more vulnerabilities. Ie it's hard to make C safe even when you really try and are a good programmer. In contrast IME most pentesters in the biz work on code bases that have seen much less scrutiny and are often in-house and/or "enterprise" apps whose code was written by people who are probably more domain experts than generally good programmers or security-aware developers...
- jaas 7y agoThis is a naive and dangerous perspective. You're basically saying that memory safe languages don't solve all problems so it's fine to use unsafe languages. Don't write code in unsafe languages unless you have to (almost never for new code). Period. You will have some problems either way, but you will have fewer problems in a memory safe language. Pen testing is not even remotely a good mitigation to depend on against the dangers of a language like C. Its fine to do for defense in depth and to find problems not related to memory safety, but it's no substitute for making a more sensible language choice.
- loeg 7y agoSudo isn't new code in any sense. "Rewrite the world in memory safe languages" is appealing if you completely discount the time and cost required to do so.
- codeflo 7y agoThe prefix/postfix change is a red herring, that doesn't do anything (since the expression result isn't used). Which means that the security fix is interspersed with code style changes. Maybe there's a reason to do this here, but it's often not considered good practice because it makes it harder to review the code. 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.
- MaulingMonkey 7y ago198 also disables password feedback mode in !tty mode. So, style changes, behavior changes, and security fixes all in one changelist. This is a small enough diff that I wouldn't complain if given this to review - but I probably also would've reverted the style changes (and would give myself at least 50/50 odds of splitting the changelist in two) Perhaps I've just been too broken by 1000+ LOC diffs that intersperse multiple behavior changes and style and refactoring and ...
- stanferder 7y ago> The prefix/postfix change is a red herring, that doesn't do anything The prefix/postfix change does something to the reader. It's a distraction trying to figure out if that change was intended, whether the author knows it has no effect, or whether I'm wrong about the change having no effect. I appreciate the author doing the hard work of fixing this, especially with the code in full view of the public, but if I were an official reviewer I'd ask to get all the unnecessary changes removed.
- nullc 7y agoBetter than OpenSSL putting out critical security fixes in a 400kloc diff...
- kohtatsu 7y agoPSA: git add -p and git commit -p exist and are beautiful.
- jwilk 7y ago
- userbinator 7y agoIf anything the solution is more low-level education, not the exact opposite. People who understand these essential basics, e.g. by starting with Asm, are going to be far less likely to make these sorts of mistakes and write less buggy code in general. I mean, a buffer overflow is a very simple concept and it's not hard to understand. How many bytes could be written, and how much storage is reserved? It's really just arithmetic. 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.
- pjmlp 7y agoSecurity reports from Google and Microsoft's teams prove otherwise. Also let's not forget that C exploits go back to the 80's, when most of us where doing full application in Assembly. Supposedly we knew our pointers pretty well.
- shakna 7y ago> Also let's not forget that C exploits go back to the 80's, when most of us where doing full application in Assembly. I'm not sure this statement adds anything to your argument. "Exploits go back as far as the language was in common use" doesn't really mean anything. I'm sure Ada has had exploits, especially around its early lifetime. But its a language that's supposed to be safe.
- AgentME 7y agoThe existence or non-existence of exploits isn't very interesting. The rate that users make vulnerable code is more interesting. The fact that remote-code execution vulnerabilities are still very common in C codebases even after people and the ecosystem have had decades to learn the ins and outs of C is concerning. Maybe the rate of RCE occurrences in C codebases has gone down over time as people have been educated about vulnerabilities more, but I would guess that the rate of RCE vulnerabilities in C codebases is still much higher than the rate ever was for safer languages.
- fiddlerwoaroof 7y agoAs far as I can tell, the prefix/postfix thing here is irrelevant and mostly done for style reasons? It’s on its own line and the value of the expression isn’t used, unless I’m missing something obvious.
- logicallee 7y ago>“C is fine just know what you’re doing”. $40 billion says whoever wrote this knew what they were doing.
- vortico 7y agoI've always considered root escalations to be pretty minor because you can just launch a phishing attack by adding the following to the user's .bashrc. 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.
- dooglius 7y agoDoesn't seem like a viable threat model--a user can edit the .bashrc of a sudo-enabled user but isn't sudo-enabled himself?
- vortico 7y agoRunning sudo requires the user password, which a script might not know. Unless of course sudo is configured with NOPASSWD.
- loeg 7y agoThis alias just prompts the user twice, as if the user made a typo the first time. Unless you know you're a perfect typist, it's somewhat subtle.
- NieDzejkob 7y agoNot even that, because sudo keeps your password in memory for a few minutes.
- vortico 7y agoNot if you have a sudo timeout enabled. Or, the proof of concept could be changed to alias sudo='sudo ./badscript' where badscript runs `exec $@`.
- loeg 7y agoGood considerations. Thanks.
- _-___________-_ 7y agoThis reiterates the idea that you should avoid rarely-used features of security-critical software, and is perhaps an argument that those features shouldn't exist in the first place. An extremely-minimal `sudo` alternative would be a nice idea.
- dharmab 7y agoThere is an alternative: OpenBSD's doas: https://man.openbsd.org/doas https://man.openbsd.org/doas There is a Linux port, too
- _-___________-_ 7y agoI'll have to look into that. Retraining 15 years of muscle memory to not type `sudo` would be hard, but I guess I could make an alias :)
- jlgaddis 7y agoYep, one of the first things I did after OpenBSD switched was: 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!).
- quotemstr 7y agoWhy change the name of the command just to switch to a different implemention? It should be possible to make a drop-in replacement for sufo itself in Rust or your favorite safe language, and a drop-in safe replacement is likely to get much more traction than some completely new thing.
- dharmab 7y agodoas is not intended to be a drop in placement for sudo. While the core feature (run a command as another user) is the same, many of the subfeatures are different.
- floatingatoll 7y ago> Sudo versions 1.7.1 to 1.8.25p1 inclusive are affected but only if the `pwfeedback` option is enabled in sudoers
- tyingq 7y ago"Just a tiny change, password feedback is now enabled by default. So when you type your sudo password you’ll see asterisks instead of wondering if you’re typing anything at all ;)" Argh. https://medium.com/elementaryos/loki-updates-for-the-new-year-ff6b6ba65531 https://medium.com/elementaryos/loki-updates-for-the-new-yea...
- staticassertion 7y agoSeems super reasonable tbh.
- nitrogen 7y agoThe standard for non-Windows/DOS terminals has always been to show nothing during password entry. Does elementary show password feedback in all terminal contexts, or just for sudo?
- staticassertion 7y agoI think my response to all of that is "Who cares?". It's a totally fine and reasonable UI change and it's incredibly unreasonable to think "Ah, this minor UI change might lead to a buffer overflow because we code like it's 98".
- tyingq 7y agoFwiw, my "argh" was a "been there" argh. Not a judgey one. Unintended consequences suck.
- staticassertion 7y agoI see. Sorry for the misunderstanding.
- Santosh83 7y agoJust a naive question probably but, is there any particular reason why security related executables like sudo aren't replaced with versions written with a bounds checked language like say Go or Rust?
- bsagdiyev 7y agoBecause this is a tired and tried question asked every time. You are welcome to do it yourself instead of forcing it upon others.
- _-___________-_ 7y agoNobody's done it yet.
- Jaxan 7y agoMicrosoft does this. They are reimplementing a lot of internet protocols using Fstar. So not only bounds checking, but also verified. But it’s a huge undertaking!
- simion314 7y agoThere are people doing that, there is one or more kernles written in Rust but still even Rust evangelist are not using it daily but demand for people to waste time rewriting in Rust. 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".
- the8472 7y ago> 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.
- based2 7y agohttps://www.reddit.com/r/netsec/comments/exmr98/buffer_overflow_in_sudo_versions_171_1825p1_when/ https://www.reddit.com/r/netsec/comments/exmr98/buffer_overf...
- jimrandomh 7y agoHas anyone started a project to rewrite `sudo` in Rust or some other memory-safe language? It seems like a prime candidate: very security sensitive, well-defined functionality and API, low total complexity.
- pjmlp 7y agoLong time ago there was a project to rewrite Linux userspace in Ada, but it died due to lack of support. Also there are userspace rewrites in Go and OCaml.
- pdimitar 7y agoCould you point us at them?
- vips7L 7y agoCore utils in Rust: https://github.com/uutils/coreutils https://github.com/uutils/coreutils
- pdimitar 7y agoAwesome, thank you.
- pjmlp 7y agoCoreBoot port to Rust, started by Ron Minnich. https://github.com/oreboot/oreboot https://github.com/oreboot/oreboot Userspace in Go for Core Boot/OreBoot, also started by Ron Minnich. http://u-root.tk/ http://u-root.tk/ Similar effort for the PI, https://gokrazy.org/ https://gokrazy.org/ F-Secure Go's bare metal implementation, https://github.com/f-secure-foundry/tamago https://github.com/f-secure-foundry/tamago For OCaml, there is https://ocaml.github.io/ocamlunix/ https://ocaml.github.io/ocamlunix/. And then all the utilities that come out from MirageOS and Xen projects.
- pdimitar 7y ago
- salawat 7y agoUh... >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.
- jlgaddis 7y ago> 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.
- pdimitar 7y agoI'm willing to work on replacing most GNU / UNIX tools with Rust equivalents. Anyone willing to fund such an effort? 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".
- pjmlp 7y agoMorris worm was caused by a buffer overflow, 30 years ago! 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.
- cycloptic 7y ago>Anyone willing to fund such an effort? 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.
- jcranmer 7y agocargo vendor will avoid downloading dependencies from "some random server."
- cycloptic 7y agoDistros still won't ship that because it causes needless code duplication. Edit: I don't mean this as a general dismissal of that strategy, but more to illustrate what problems you'll run into trying to get Rust packages into a distro. A huge amount of work has gone into most distros to "un-vendor" dependencies because it leads to a lot of problems.
- quotemstr 7y agoThe thing about C that's always baffled me is the resistance to abstraction that makes its lack of memory safety worse than it has to be. Nothing stops you, even in C, from defining a "string" data type that maintains an internal buffer size and read position. You can even give such a thing an elegant API, as many people have when they've implemented things like this. 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.
- pjmlp 7y agoExactly that, that is why every attempt to fix C security holes has failed, the culture just isn't willing to accept it. 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.
- loeg 7y agoAnnex K has never been non-optional. No one has ever implemented a full compliant Annex K, and it's a terrible abstraction. It predates basic static analysis and suffers from more or less the same problems as non-Annex K variants. E.g., if you pass in the wrong buffer length to the K variant, you still get buffer overflows. How do you tell if the wrong length is passed? Static analysis. The same analyzers work with existing libc functions. I do think C or at least POSIX should have adopted strlcpy and strlcat, though; strncpy doesn't do what most people think it does. Source, and more info: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm
- awinter-py 7y agothat logo
- yoningao 7y agoI want to make a presentation about this for school. How can I adapt that in order to, for example, make the normal user that execute became su?
- musicale 7y agoBuffer overflows in sudo (seen on debian/ubuntu mainly) have bothered me for a long time since they lead to crashes. I'm glad they are finally fixing some of them!