Apply read-only and nodev flags in a separate remount - #2048
Open
DenisKimskku wants to merge 1 commit into
Open
Conversation
Signed-off-by: DenisKimskku <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
mount(2) silently ignores MS_RDONLY, MS_NODEV and MS_NOSYMFOLLOW when they are supplied alongside MS_BIND in a single call. Per the mount(2) man page, a bind mount takes its mount options from the source mount; the requested flags only take effect on a subsequent MS_REMOUNT | MS_BIND call. MS_PRIVATE is a propagation-type change and likewise cannot be combined with MS_BIND — it needs its own call.
Two bind mounts in the toolkit pass all of these flags in one call, so the resulting mounts are created read-write, with none of the four flags applied:
This change splits each into the three calls the kernel actually requires: the bind, then an MS_REMOUNT | MS_BIND carrying the restrictive flags, then MS_PRIVATE.
Observed on /proc/self/mountinfo for the affected mount:
before: rw,relatime
after: ro,nodev,relatime,nosymfollow
Note on impact. This is a correctness fix, not a security fix, and I don't think it warrants an advisory. For disable-device-node-modification in particular, access to devices the container was not assigned is independently enforced by the devices cgroup: a container that restores its own view of ModifyDeviceFiles: 1 can create a device node but still cannot open it (Operation not permitted). These flags are defence in depth — this change makes them actually apply rather than being silently dropped.
Checklist
make test)make lint)Testing