Repository navigation
Open
Description
Try running this in one terminal to cause the mount table to change frequently:
$ mkdir from to
$ while true; do sudo mount --bind from to && sudo umount to; done
And run bwrap repeatedly in another terminal:
$ while true; do bwrap --bind / / -- /bin/true && echo -n .; done
...................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
.....................................................................................................................................................................................................................................................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
..............................................................................................................................................................................................................................................................................................................................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
.....................................
This likely happens because the bind_mount function grabs the current mount table (
Line 438 in 973fe36
| mount_tab = parse_mountinfo (proc_fd, kernel_case_combination); |
--bind works recursively but fails if any of the sub-mounts fail (Line 472 in 973fe36
| mount ("none", mount_tab[i].mountpoint, |
It already checks that errno != EACCES; perhaps this failure can be excluded in the same way.
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]`--bind` can cause bwrap to crash during startup if it races with the mount table changing[/-][+]`--bind` can cause bwrap to fail during startup if it races with the mount table changing[/+]smcv commentedon Aug 6, 2024
Retitled because this is a graceful failure (inasmuch as anything bwrap does is ever graceful), not really a crash.
In principle yes, but we need to be careful with making bwrap more robust against unexpected situations, because when it's used as a sandboxing tool (a security boundary), it's better for it to fail to start than to start successfully but without the desired security properties.
I'm not sure whether
--bindhas this sort of security implication (possibly fornodev,nosuidand similar?), but when we're doing a--ro-bindit's certainly security-sensitive that we successfully remount all of the filesystems below the requested mount point as read-only. If we fail to make one of them read-only, it's better to fail than to leave it read/write in the sandbox.rusty-snake commentedon Aug 6, 2024
The hole recursive apply flags topic (which all drawbacks like #384) can be avoided on kernels with
mount_setattr(Linux 5.12 - 2021) AFAICTY. Leaving the inefficient resursive remount for older kernels as fallback.smcv commentedon Aug 6, 2024
Please do send a pull request if you have a
mount_setattr-based code path ready!rusty-snake commentedon Aug 6, 2024
Unfortunately not. And my C skills are too limited.
artli commentedon Aug 17, 2024
Yeah, that sounds totally reasonable; in this case though the specific error is that the mount point is just not found, which is hopefully different enough from "the mount point exists but we failed to mount it" that we can continue? I can see how this is tricky from the security standpoint if we cannot easily pinpoint the cause of the error.
For my use case, I resorted to heuristically detecting this condition by parsing bwrap's stderr, which is obviously a sad hack.
smcv commentedon Aug 19, 2024
Yeah, sorry, if there is any doubt, we have to "fail closed". Sysadmins and users are trusting bubblewrap to provide the security boundary that was asked for.
If you can put together a PR to handle this more gracefully (either by using
mount_setattror by cleverer error handling), I'd consider it (time permitting), but you would have to be able to justify how it isn't a security vulnerability.smcv commentedon May 29, 2026
I've opened #754 for the
mount_setattridea.Use `mount_setattr()` to set mount flags
Use `mount_setattr()` to set mount flags
Use `mount_setattr()` to set mount flags
Use `mount_setattr()` to set mount flags
Use `mount_setattr()` to set mount flags
Use `mount_setattr()` to set mount flags