11 ms·
Linux kernel heap buffer overflow in fs_context.c since version 5.1
- caaqil 5y agoSee it in action: https://twitter.com/ryaagard/status/1483592308352294917 https://twitter.com/ryaagard/status/1483592308352294917
- encryptluks2 5y agoArch shows some warnings about unprivileged user namespaces but it is enabled by default I believe which allows for rootless podman/docker. I didn't realize we'd actually see an exploit so soon
- tremon 5y agoWhat's the origin of the legacy_parse_param size parameter (from struct fs_context->fs_private->data_size)? Is this a mount option, a format-time fs configuration option, or does it require writing a specially-crafted inode to disk? The exploit says the user needs CAP_SYS_ADMIN, so I'm guessing it's the first one?
- shakna 5y agoFrom the commit [0] that added it: > Legacy filesystems are supported by the provision of a set of legacy fs_context operations that build up a list of mount options and then invoke fs_type->mount() from within the fs_context ->get_tree() operation. This allows all filesystems to be accessed using fs_context. And then the description of the function itself: > Add a parameter to a legacy config. We build up a comma-separated list of options. It looks to be the second one. [0] https://github.com/torvalds/linux/commit/3e1aeb00e6d132efc151dacc062b38269bc9eccc https://github.com/torvalds/linux/commit/3e1aeb00e6d132efc15...
- AshamedCaptain 5y agoI am surprised that mounting is now allowed inside containers. Doesn't this expose a load of new surface attack for the kernel? All these pesky academical filesystem code does not inspire a lot of confidence when parsing user data/disk images....
- da-x 5y agoThis is a compatibility layer for the older mount APIs, for file system drivers hat don't utilize the newer API yet. The newer mount API is called `fs_context`, and you can read the LWN article about it here: https://lwn.net/Articles/780267/ https://lwn.net/Articles/780267/ ["VFS: Introduce filesystem context"]
- deleted 5y ago[deleted]
- mjw1007 5y agoThe Debian 11 release notes say: « From Linux 5.10, all users are allowed to create user namespaces by default. This will allow programs such as web browsers and container managers to create more restricted sandboxes for untrusted or less-trusted code, without the need to run as root or to use a setuid-root helper. The previous Debian default was to restrict this feature to processes running as root, because it exposed more security issues in the kernel. However, as the implementation of this feature has matured, we are now confident that the risk of enabling it is outweighed by the security benefits it provides. If you prefer to keep this feature restricted, set the sysctl: user.max_user_namespaces = 0 Note that various desktop and container features will not work with this restriction in place, including web browsers, WebKitGTK, Flatpak and GNOME thumbnailing. » Does anyone know a reason to keep this feature enabled on a server, other than Docker's rootless mode?
- dathinab 5y agosome programs use it to sandbox themself without needing root. Through currently I can only think about desktop apps which do so.
- prpl 5y agoIf you have a multi tenant server and don’t want to provide root access to users but want them to be able to run containers, otherwise it’s probably not necessary
- Diggsey 5y agoI assume that `size + len + 2` can't overflow :)
- pxeger1 5y agoThis is CVE-2022-0185 if you need to know it
- jakeinspace 5y agoSorry to be somewhat off-topic, but I have a Linux kernel bug question. I found a very small kernel bug (no obvious security implication, only affecting 32-bit builds) at work a few weeks back while working on a custom kernel patch. I sent an email to the maintainers for that kernel subsystem, but didn't hear back. I'm not quite sure if I should keep pestering them until I get a response, or if I should be doing something else to get it addressed. Any suggestions from someone with experience?
- tych0 5y agoStandard advice is to wait two full weeks, then bump your thread (or rebase the patch and send a v2 if there's new conflicts with the maintainer's tree).
- charcircuit 5y agoIt sounded like he just filed a bug.
- jakeinspace 5y agoIt’s a 1-line patch, I didn’t send it in my initial email but maybe that was a faux pas.
- tych0 5y agoI'd say sending the patch with git send-email --in-reply-to=<the header of your last email> is good. A patch is much easier to apply than write :)
- jakeinspace 5y agoThanks! Would you recommend I send to the maintainer(s), and Cc the mailing list?
- tych0 5y agoYeah, I'd just use whatever the output of ./scripts/get_maintainer.pl says. It will also suggest any recent committers to that area of the code, which I've found useful in the past. Usually I put the maintainers as To:, and everyone else as Cc:.
- phendrenad2 5y agoDoes anyone offer security fix backports for Linux? If I'm stuck on Linux 5.1, is my only recourse to update or patch it myself?
- singron 5y agoThere are Linux stable branches that backport fixes. It looks like all the affected branches have the fix now: linux-5.16.y linux-5.15.y linux-5.10.y linux-5.4.y linux-rolling-lts linux-rolling-stable EDIT: notably absent are linux-5.1.y and other non-lts releases. If you can't stay on the most recent stable release, you should use lts releases.
- adfsdsaf 5y agoIf you're stuck on 5.1, you probably have a ton of other vulnerabilities too. 5.1 isn't even an LTS release, so support for it was dropped in 2019. 5.4 is the first LTS of 5.x, and is supported through 2025. You should try to find a way to get on an LTS kernel, or plan on managing a lot of kernel patches.
- rwmj 5y agoIt's a one line patch in old code so it should apply easily. However if you encounter this kind of problem a lot I'd highly advise some kind of long-term supported Linux distribution. (I work at Red Hat on RHEL, and that's what people pay us for)
- _rdvw 5y agoYou can use my program here along with its database: https://github.com/Divested-Mobile/CVE_Checker https://github.com/Divested-Mobile/CVE_Checker Just adjust the loose versioning check to apply 5.4 patches to 5.1.
- whimsicalism 5y agoThe compiler can't warn about something like this? I guess unsigned integer underflow can be the intended behavior often.
- mustache_kimono 5y agoIt could, for other reasons, never underflow. C expects that you know what you're doing, and C expected you did a bounds check. But I agree. Cases like this should have a lint warn on them, saying -- "Wake up programmer!"
- menaerus 5y agoFundamentally this problem cannot be solved at the compile-time level because, well, code is dealing with the values which are only known during code execution runtime. So I don't think compiler can do much here other than providing you with a hint that you may rewrite your expression but only to reduce the risk of a potential error, e.g. `if (len + 2 + size > PAGE_SIZE)` still still remains feasible to unsigned integer overflow and to handle the problem fully one must either: 1. Write a lot of convoluted if..else logic such as https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensure+that+unsigned+integer+operations+do+not+wrap https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensur... and https://wiki.sei.cmu.edu/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow https://wiki.sei.cmu.edu/confluence/display/c/INT32-C.+Ensur... 2. Or use compiler built-in intrinsics, e.g. https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins... But almost nobody does that ... except probably where it really matters (not the OS kernel).
- whimsicalism 5y agoNot solved at compile-time, but warned at compile time?
- touisteur 5y agoCould be solved at compile time with proof of absence of runtime errors, which somehow forces you to handle all cases for any input.
- faisal_ksa 5y agoI wander if rust (or any other memory safe system language in the future) could have avoided this exploit. If not, what could we do to avoid such exploits?
- mustache_kimono 5y agoI'm not an expert, but I will say it may be easier to avoid an over/underflow with: https://doc.rust-lang.org/std/primitive.u32.html#method.saturating_add https://doc.rust-lang.org/std/primitive.u32.html#method.satu... And to check if one has occurred with: https://doc.rust-lang.org/std/primitive.u32.html#method.checked_add https://doc.rust-lang.org/std/primitive.u32.html#method.chec...
- gpm 5y agoOne method of forbidding the entire category of bugs is "bounds checks on integer arithmetic". Rust implements this in debug mode, but not by default in release mode, because it comes at a performance cost. To make this sort of solution ubiquitous you really want better hardware support to make bounds checking cheap. Realistically I think it is unlikely you would have written the same exploit in rust even with integer overflow wrapping by default, because in idiomatic rust you end up using types with lengths attached to them, and memcpy methods that check that you didn't fuck up the lengths before copying. You absolutely could end up writing it in rust though (using unsafe code, but at some level unsafe code is inevitable for this sort of work), and you could if you really wanted to implement a similar set of safer buffer types in C that would provide a similar degree of prevention (though it would be more cumbersome to use than in rust).
- AceJohnny2 5y ago> To make this sort of solution ubiquitous you really want better hardware support to make bounds checking cheap. It's funny because it's trivial to implement underflow/overflow reporting in an ALU, but somehow that kind of event doesn't get reported to the offending program, at least at the naive C level.
- 5y ago
- lillecarl 5y agoSomehow I first thought I was affected personally, but I'm on 5.15. Version numbers crossing 10 messes my head up more often than I'd be willing to admit in person.
- stormbrew 5y ago> An unprivileged user can use unshare(CLONE_NEWNS|CLONE_NEWUSER) to enter a namespace with the CAP_SYS_ADMIN permission, and then proceed with exploitation to root the system. I'm confused by this, don't you need CAP_SYS_ADMIN to unshare(CLONE_NEWNS) to begin with? From unshare(2): > CLONE_NEWNS > This flag has the same effect as the clone(2) CLONE_NEWNS flag. Unshare the mount namespace, so that the calling process has a private copy of its namespace which is not shared with any other process. Specifying this flag automatically implies CLONE_FS as well. Use of CLONE_NEWNS requires the CAP_SYS_ADMIN capability. For further information, see mount_namespaces(7). Edit: Oh does this work specifically because you're also unsharing into a new user namespace where you have that capability? This is kind of wild tbh.
- staticassertion 5y agoYeah, a lot of the Linux kernel code was reachable by root, and for a long time the attitude of a lot of kernel maintainers was that privesc from root didn't matter much. But now any code can be root in its own namespace... so all of this code that's far less scrutinized is now reachable.
- boring_twenties 5y agoExactly the main argument that was being made against enabling this by default all those years ago.
- octoberfranklin 5y agoIndeed, this is exactly why containers are not a security feature. Counterintuitively, using containers makes your system less secure because you have to expose this huge kernel attack surface to non-root users.
- deleted 5y ago[deleted]
- alerighi 5y ago
- snvzz 5y agoThere's likely many more of these. As a reminder, Linux has millions of lines of code, and all of them run with supervisor privileges. This is not a good architecture. Generally, you'd try to minimize the attack surface. Multiserver, microkernel systems based on capabilities is where it's at. seL4 is the better microkernel to build such a system on.
- athrowaway3z 5y agoThere exist people who own their own hardware and are not providing an API to run arbitrary code. If they get together and build an OS they are generally more interested in throughput than security models. Both have pro's and con's but the fact is: one is more popular with the "just get something working" crowd for better and worse.
- VWWHFSfQ 5y agoIt's my understanding that the microkernel architecture is slow. Nearly unusably slow. And that's why nobody uses it. Am I off-base? I'm interested!
- dijit 5y agoYes, it’s going to be slower All of those security checks between components and memory passing will cause it to be slower. But that doesn’t mean it’s a worthy trade off. People write software in python despite it being slower than C++.
- hutrdvnj 5y agoExcept that anything that is actually performance critical is written as a C extension python module. I think that low level filesystem operations are very performance critical.
- jeffbee 5y agoI doubt that mounting a filesystem is performance-critical. You could afford to fork an unprivileged user-space process written in Perl to parse these mount options and that would be fast enough for everyone.
- kidd0 5y agoDoes it effect Amazon Linux2?
- jftuga 5y agoAmazon Linux 2 AMI is now available with kernel 5.10[0] Posted On: Nov 19, 2021 Amazon Linux 2 is now available with an updated Linux kernel (5.10) as an Amazon Machine Image (AMI). Kernel 5.10 brings a number of features and performance improvements, including optimizations for Intel Ice Lake processors and AWS Graviton2 processors powering the latest generation Amazon EC2 instances. Live patching for Kernel 5.10 is supported in Amazon Linux 2 for both x86 and ARM architectures. [0]https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-linux-2-ami-kernel-5-10/ https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-li...
- brobdingnagians 5y agoIt seems like this `if (len > PAGE_SIZE - 2 - size);` is less natural than the correct code of `size + len + 2 > PAGE_SIZE`. Can anyone more familiar with C comment on why someone would write it the first way instead of the second way?
- pixelbeat__ 5y agoOverflow https://www.pixelbeat.org/programming/gcc/integer_overflow.html https://www.pixelbeat.org/programming/gcc/integer_overflow.h...
- AceJohnny2 5y agoAs a long-time embedded C coder: I agree that (with the added benefit on hindsight) the original code "smells". I'm well-tuned to consider overflows, and adding numbers together instinctively makes me consider whether there's a risk... Similarly, subtracting numbers should make one consider underflows. Perhaps the original author was used to working with signed values and forgot to consider the risk of underflow with these unsigned variables. (I used to have C's type promotion rules on quickdraw, but I very soon learned that if I needed to refer to them, I was probably doing something wrong)
- comex 5y agoThe problem is that neither option is correct if `size` and `len` can both be arbitrary unsigned integers. They can both overflow (counting underflow as a type of overflow). To be correct regardless of their values, you would have to write something like: if (size + len < size || size + len > PAGE_SIZE - 2) But broadly speaking, adding explicit overflow checks everywhere makes code more verbose, and it isn't even a panacea, since it can be non-obvious whether any given overflow check is even correct (especially when C's arcane type conversion rules come into play). Plus, in theory every extra check makes the code larger and slower. Therefore, it's common to see C code try to perform computations in a way that can't overflow in the first place. But that often requires putting them in a less natural form, as well as making assumptions about which things are bounded in which ranges. For example, even in the above example that does have an overflow check, I had to unnaturally put the 2 on the right hand side of the equation rather than the left, and assume that `PAGE_SIZE - 2` doesn't underflow. The fully natural computation would require two overflow checks: if (size + len < size || size + len + 2 < size + len || size + len + 2 > PAGE_SIZE) On the other hand, the buggy single comparison that was actually used: if (len > PAGE_SIZE - 2 - size) would be correct, and reasonably idiomatic, if `size` was known to be bounded below `PAGE_SIZE - 2`. Perhaps the author thought it was. This is really an unfortunate limitation of C, though. It would be nice to be able to succinctly express "if size + len + 2 > PAGE_SIZE or the computation overflowed, then return error". From the hardware's perspective, that sort of check is really cheap; from the compiler's perspective, it's ripe for optimization. So if C had an ergonomic overflow-check feature, you could standardize your codebase on using it for any calculation that's remotely related to buffer sizes, at very little performance cost. With GCC extensions you can at least do this: size_t tmp; if (__builtin_add_overflow(size, len, &tmp) || __builtin_add_overflow(tmp, 2, &tmp) || tmp > PAGE_SIZE) Using these builtins standardizes the form of overflow checks and avoids "is the overflow check correct" worries. But the ergonomics are arguably even worse, since you need to declare a temporary variable, and use long function names instead of normal mathematical operators.
- _prototype_ 5y agodid Linus talk about this exploit in a mailing list? if so, can someone link it here? its always interesting to read Linus' perspective