On 2024-05-28, Jeff Xu <jeffxu@xxxxxxxxxx> wrote: > Hi Aleksa, > > On Fri, May 24, 2024 at 9:12 AM Aleksa Sarai <cyphar@xxxxxxxxxx> wrote: > > > > On 2024-05-23, Jeff Xu <jeffxu@xxxxxxxxxx> wrote: > > > > Regarding vm.memfd_noexec, on another topic. > > > I think in addition to vm.memfd_noexec = 1 and 2, there still could > > > be another state: 3 > > > > > > =0. Do nothing. > > > =1. This will add MFD_NOEXEC_SEAL if application didn't set EXEC or > > > MFD_NOEXE_SEAL (to help with the migration) > > > =2: This will reject all calls without MFD_NOEXEC_SEAL (the whole > > > system doesn't allow executable memfd) > > > =3: Application must set MFD_EXEC or MFD_NOEXEC_SEAL explicitly, or > > > else it will be rejected. > > > > > > 3 is useful because it lets applications choose what to use, and > > > forces applications to migrate to new semantics (this is what 2 did > > > before 9876cfe8). > > > The caveat is 3 is less restrictive than 2, so must document it clearly. > > > > As discussed at the time, "you must use this flag" is not a useful > > setting for a general purpose operating system because it explicitly > > disables backwards compatibility (breaking any application that was > > written in the past 10 years!) for no reason other than "new is better". > > > Are you referring to ratcheting in the sysctl in my original patch or > is this something else ? > I do not disagree with your change of "removing the ratcheting" from > the admin point of view. I'm referring to your original patch making vm.memfd_noexec=2 reject memfd_create() when called without MFD_EXEC or MFD_NOEXEC_SEAL (which is what every program written pre-mid-2023 did, since those flags didn't exist yet). This was fixed in 202e14222fad, and is separate to ratcheting (which was fixed in 9876cfe8ec1c). We definitely had a long discussion about it at the time. > > As I suggested when we fixed the semantics of vm.memfd_noexec, if you > > really want to block a particular flag from not being set, seccomp lets > > you do this incredibly easily without acting as a footgun for admins. > > seccomp can but it requires more work for the container, e.g. > container needs to allow-list all the syscalls. If you're applying the rule for a single syscall you can create a deny-list, so no need for a full-on filter for everything. Also, most containers already have allow-list seccomp filters applied, so adjusting them to add a restriction for one syscall is not that complicated. > I'm trying to point out that seccomp might not cover all user-cases. One of the reasons I'm suggesting seccomp because I think that this "use-case" probably only exists within ChromeOS, and so adding more kernel infrastructure around it makes little sense. seccomp has effectively no performance overhead for something this simple and lets you block this if you really want to. For general purpose distributions and systems, an administrative knob to make working programs error out if they don't pass an effectively-noop flag to memfd_create(2) doesn't help pressure anyone into migrating because the random unmaintained program using memfd_create(2) isn't developed by the same company making the distribution... How would an admin setting vm.memfd_break_random_programs=1 help random_app_downloaded_from_the_internet get patched to use MFD_EXEC/MFD_NOEXEC_SEAL? (It doesn't.) > "ratcheting" in the vm.memfd_noexec is lightweight and can be applied > to the sandbox of the container in advance, but since admin doesn't > like ratcheting in sysctl, maybe prctl or LSM are ways to implement > such restriction. > > > Yes, vm.memfd_noexec can break programs that use executable memfds, but > > that is the point of the sysctl -- making vm.memfd_noexec break programs > > that don't use executable memfds (they are only guilty of being written > > before mid-2023) is not useful. > > > > In addition, making 3 less restrictive than 2 would make the original > > restriction mechanism useless. A malicious process could raise the > > setting to 3 and disable the "protection" (as discussed before, I really > > don't understand the threat model here, but making it possible to > > disable easily is pretty clearly). > > You could change the policy, but now > > you're adding more complexity for a feature that IMO doesn't really make > > sense in the first place. > > > The reason of 3 is help with migration (not for threat-model), e.g. a > container can force every apps run in the container migrates their > memfd_create to use either MFD_EXEC or MFD_NOEXEC_SEAL. This is the argument you had for the behaviour of vm.memfd_noexec=2 at the time. In the discussion we had last year, I explained that this is not "helpful" for the reasons explained above. There are plenty of old interfaces in Linux and we don't generally push people to migrate to newer interfaces, especially since in this case we're talking about a flag that is a no-op for the vast majority of programs on most systems. Only programs that need MFD_EXEC actually _need_ to switch (if distros eventually make vm.memfd_noexec=1 the default in a decade or two) and the most well-known programs that use MFD_EXEC have already been patched (runc is probably the most obvious one, and we patched this last year). Not to mention that a lot of programs that are maintained have already switched to the mostly-noop MFD_NOEXEC_SEAL, so the only programs that would be affected by this migration "help" would be older programs that won't be pressured to update because they're unmaintained. > But I understand what you mean, with current code, adding 3 would > cause more confusion to vm.memfd_noexec. Perhaps a new sysctl or prctl > is the way to go if the app wants to force migration. > In the hinder sight: two sysctls would work betters: the first deal > with migration, the second enforces NO_EXEC_SEAL. The "help with migration" feature shouldn't exist, and I removed it in 9876cfe8ec1c for a reason. -- Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH <https://www.cyphar.com/>
Attachment:
signature.asc
Description: PGP signature