10 ms·
New Linux glibc flaw lets attackers get root on major distros
- tomsmeding 3y agoDuplicate, more discussion here: https://news.ycombinator.com/item?id=39194093 https://news.ycombinator.com/item?id=39194093
- wslh 3y agoI have not found Rust mentioned there. Am I right if we say that using Rust will reduce the security attack surface in Linux? I see now it is mentioned in this thread and there are different views about this.
- tialaramex 3y agoThe obvious ways to do this in Rust are safe, on the other hand, if you write some Rust where all it does is call this glibc function then Rust didn't magically save you because the function is broken. Does that help?
- smolder 3y agoBeing that it is a buffer overflow, yes, if glibc were in Rust I think it shouldn't have happened. I believe I saw a libc reimplementation project in Rust, but that's a big effort and not something I would expect to be drop-in for a long time. That said, I think we should try to avoid turning every vulnerability discussion into one about the merits of Rewriting it in Rust.
- stevev96 3y ago[dead]
- shirro 3y agoMemory safety isn't exclusive to Rust. Language designers and implementers solved these problems years ago with safer languages (better type systems, removing pointers) or safer runtimes (jvm, .net etc). Rust is notable because it brings a lot of prior art together in one place and the compiler prevents most problems at compile time. As long as programmers don't use unsafe Rust it can produce safer code without runtime overhead. There are a lot of safer languages than C. Not all are suitable for writing system libraries.
- WirelessGigabit 3y agoMind you that there is a runtime overhead. If we look at access beyond on a slice's boundary: https://github.com/rust-lang/rust/blob/ea37e8091fe87ae0a7e204c034e7d55061e56790/library/core/src/slice/index.rs#L315-L322 https://github.com/rust-lang/rust/blob/ea37e8091fe87ae0a7e20... This bounds check is what enables Rust code to fail with a panic vs continuing (which is what triggers a lot of bugs). Post about the impact on performance: https://blog.readyset.io/bounds-checks/ https://blog.readyset.io/bounds-checks/
- deleted 3y ago[deleted]
- nextaccountic 3y agoYes, but only if the relevant code can be written in Safe Rust (that is, without using unsafe). This is not always a given, but surprisingly, a huge amount of code can be written in Safe Rust and therefore won't have buffer overflows.
- GoblinSlayer 3y agoFWIW C can do it too to some extent, here's postfix: https://github.com/vdukhovni/postfix/blob/master/postfix/src/util/base64_code.c https://github.com/vdukhovni/postfix/blob/master/postfix/src...
- cutler 3y agoJust curious whether Rust would have averted these issues?
- voxl 3y agoThe answer is probably yes. The issue is caused by a heap-memory overflow. In Rust, if you're storing an array on the heap then there will be bounds checks on the array access. If you're using a vec then it would automatically grow (so again bounds checks).
- ape4 3y agoIt would be quite something to rewrite glibc in Rust! Of course, its the C/C++ run time.
- yjftsjthsd-h 3y agoIt's a funny thought, but I don't think there's any reason it shouldn't work; IIRC redoxos is providing a libc written in rust for compatibility.
- Retr0id 3y agoThe redox impl is here: https://github.com/redox-os/relibc https://github.com/redox-os/relibc Apparently it also supports linux!
- Retr0id 3y agoIt would be quite amusing, but there's no reason in principle that it couldn't be done. The user-facing APIs would be just as dangerous as ever, but the internal implementation-detail stuff - like this "__vsyslog_internal" - could presumably be made safer.
- pjmlp 3y agoAs C++ advocate on C vs C++ flamewars, I already find quite ironic that GCC, clang, clang's libc and Windows Universal C Runtime are all written in C++. All those C users hatting on C++, while being forced to use tooling that has dropped C for C++.
- spookie 3y agoThis makes me think the musl people are right. Glibc is quite a large attack surface.
- loeg 3y agoFwiw, the analogous logic in musl libc[1] uses log_ident set to the empty string if openlog() was called with NULL ident[2]. It also formats twice to buf[1024] without checking that the first format's length isn't in excess of the stack buffer but that's likely always safe given how short the stuff printed in the first format is. [1]: https://git.musl-libc.org/cgit/musl/tree/src/misc/syslog.c#n105 https://git.musl-libc.org/cgit/musl/tree/src/misc/syslog.c#n... [2]: https://git.musl-libc.org/cgit/musl/tree/src/misc/syslog.c#n68 https://git.musl-libc.org/cgit/musl/tree/src/misc/syslog.c#n...
- knorker 3y agoInteresting. The first snprintf() could return a negative value (at least by the glibc snprintf manpage), and then therefore the second vsnprintf will overwrite... something. Maybe their implementation can't return negative, or only if the fmt string (constant, here) is invalid? I wouldn't count on it, especially of it being true forever. That's pretty sloppy code.
- loeg 3y agoI believe the first snprintf only returns a negative value if the format string is broken. Musl has decided to avoid that by not breaking the format string. If that changes, returning -1 is the least of their problems. You can see the implementation here: https://git.musl-libc.org/cgit/musl/tree/src/stdio/vsnprintf.c https://git.musl-libc.org/cgit/musl/tree/src/stdio/vsnprintf... and https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c https://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.... .
- bodyfour 3y agoProbably the person you're replying to is just confused because before it was standardized some snprintf() implementations returned -1 on overflow. If you were trying to be portable and defensive you'd need to check for either error return. Not really a concern inside musl because those implementations are probably long gone and because it's calling its own snprintf() anyway.
- PhilipRoman 3y agoMeh, local privilege escalation. I think by now everyone has accepted that the Unix/Linux account system is insecure by design and exists just to prevent accidental damage. There are ways to restrict it but the default configuration simply exposes too much of an attack surface. I still give separate accounts to some services as defense in depth, but it mostly exists to slow down untargeted attacks.
- smarkov 3y agoWhat's the preferred method of limiting permissions then? Virtualization? Containerization? AppArmor?
- christophilus 3y agoI use containerization, but it’s not perfect. Also on the front page today: https://news.ycombinator.com/item?id=39250975 https://news.ycombinator.com/item?id=39250975
- PhilipRoman 3y agoFor normal services namespaces are enough (make sure to set no_new_privs, one of the best Linux features). Run it with the bare minimum of mounts required, no shared /tmp, etc. For all its faults, systemd actually gets this right, by allowing to easily harden services. Note that this exploit relies on being able to run as root (typically through setuid). If you don't fully trust a service, don't let it ever talk to code running as root in the first place. No opening sockets in /tmp, no listing processes in /proc, no dbus shenanigans, no sudo or su. One of this issues with this was that some programs require setuid for bad reasons (IIRC historically ping was setuid to be able to send ICMP packets). From a quick check (find -type f -perm -4000) most of these problems have been eliminated, via linux capabilities or otherwise. These tactics successfully saved me from log4shell.
- worksonmine 3y agoDepends on what you want to achieve. AppArmor/SELinux prevent access to files and directories. Virtualization and containerization tries to build a jail. You can combine the solutions, a container running a distro with SELinux like any from the Red Hat ecosystem. They have all had vulnerabilities, My preferred method is to not install stuff I don't need, and fix any dangerous configuration for the programs I do need. I prefer Podman over Docker because of rootless for example.
- blibble 3y agoat this point I think it's beyond clear any setuid root binaries shouldn't be written in C
- hannob 3y agoI mean, I don't disagree, but it probably would not have helped in this case. This is based on a buffer overflow in glibc itself. It is my understanding that rust still calls into libc for many lowlevel system functions. And if you call C code from rust, well, it's still C code with C code bugs. Ultimately, if you want to get rid of those, you'd have to rewrite the libc in Rust.
- blibble 3y agoI very much doubt a rust program is going to pull in glibc syslog() in this case it was in a pam module and dynamic modules loaded into setuid binaries (pam/nss/...) are also super-high risk and should be memory safe too
- grayhatter 3y ago> Ultimately, if you want to get rid of those, you'd have to rewrite the libc in Rust. No, you can eliminate these bugs by getting better at writing code. The language is independent from the quality of any given code. Rust is capable of introducing theses bugs, but the language is more explicit when you do. One languages isn't more secure than another. They each attempt to fill a niche, some trade language usability for correctness, some trade correctness for being easy to use.
- dcsommer 3y ago> you can eliminate these bugs by getting better at writing code. No, the data doesn't show this. This is the "anger" response to being confronted with the reality of the inherent insecurity of C and C++. https://www.usenix.org/conference/enigma2021/presentation/gaynor https://www.usenix.org/conference/enigma2021/presentation/ga...
- 3y ago
- tremon 3y ago> "Although [$reasons], we decided to not pursue this avenue of exploitation, because:" I see lots of ground for further research. (from https://www.qualys.com/2024/01/30/cve-2023-6246/syslog.txt https://www.qualys.com/2024/01/30/cve-2023-6246/syslog.txt, the article from the duplicate HN thread)
- charcircuit 3y agoThere is 0 reasons to have setuid binaries. Additionally, having users escalate a program to root, with no restrictions on what root can do, is even worse. setuid is a total hack and is embarrassing how many Linux distros are using it.
- PlutoIsAPlanet 3y agoHow are users supposed to change their password?
- rleigh 3y agoWhile using a setuid binary to edit the password/group "databases" is the historical default, there's no real technical reason why it must be that way. The passwd program could communicate with the database service via a socket. Likewise the NSS and PAM stuff could communicate with the same service via a socket. No reason for it to be lots of in-process loadable modules in this day and age.
- deathanatos 3y ago… this C is code is just a case exemplar of the problems with C. We have `l` and `1` being used in the same passage. Single letter variables are bad to start with, but `l` is particularly cursed since, if you happen to be using a font where `l` and `1` are homoglyphs, good luck reading that passage. But that's sadly the default in a number of OSes/environments, and indeed, the site this code is hosted on. One might presume `l` stands for length, … but there's also `vl`, `bufsize` and `sizeof bufs`. `bufs` and `buf`, although the former, `bufs`, is a singular buffer, leading one to wonder why the variable name is pluralized. I'm pretty such it's because it's stack-allocated (as opposed to the heap alloc'd `buf`, and thus `bufs` is "buf[fer], s[tack]". This is just nuts, and it should be no surprise there are multiple CVEs. The OG code was had CVEs. The commit that "introduced" this — which I almost feel is wrong to say — attempted to use `bufsize` for the buffer size, which certainly feels more right that the OG, but alas, the variable is never meaningfully initialized. This CVE is on the patch to fix a CVE! And in the original CVE's bug report, the ominous words of "Doesn't seem too serious" were uttered. I'm sure it's fixed now, though, right? syslog is just a bad interface logging interface, to boot.
- GoblinSlayer 3y agoEven Comic Sans differentiates between l and 1. I wonder how many confuse them.
- deleted 3y ago[deleted]