mnt: apply per-mount nosuid/nodev/noexec recursively to recursive binds - #284
Open
h1-mrz wants to merge 1 commit into
Open
mnt: apply per-mount nosuid/nodev/noexec recursively to recursive binds#284h1-mrz wants to merge 1 commit into
h1-mrz wants to merge 1 commit into
Conversation
Every bind mount is forced recursive (MS_REC is OR'd on in prepareMountPoint), so the source subtree -- including any nested submounts -- is cloned into the jail. The requested per-mount flags (nosuid/nodev/noexec) were only applied to the top mount: - newapi: applyMountFlags() called mount_setattr() with AT_EMPTY_PATH only, even though doBindMountAt() clones the tree with open_tree(AT_RECURSIVE); - legacy: remountPt() issued a single non-recursive MS_REMOUNT|MS_BIND on dst. As a result, a bind whose source subtree contains a nested mount (a dev-bearing fs, or one holding a setuid binary) kept that submount's original dev/suid/exec-permitting attributes inside the jail, so an explicitly requested nodev/nosuid was not enforced on it. The recursive read-only pass already applies MOUNT_ATTR_RDONLY with AT_RECURSIVE, so the restriction flags were the only per-mount attributes left non-recursive. Apply the flags recursively when the bind is recursive: thread a `recursive` bool into the newapi applyMountFlags() (OR AT_RECURSIVE into mount_setattr), and re-apply the flags to every submount under dst in the legacy remountPt() by walking /proc/self/mountinfo. Verified (legacy backend): with a nodev,nosuid recursive bind of a tree containing a nested tmpfs, the nested submount inside the jail now shows nosuid,nodev (previously it kept the host's dev/suid-honoring attributes).
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.
Every bind mount is forced recursive (MS_REC is OR'd on in prepareMountPoint), so the source subtree -- including any nested submounts -- is cloned into the jail. The requested per-mount flags (nosuid/nodev/noexec) were only applied to the top mount:
As a result, a bind whose source subtree contains a nested mount (a dev-bearing fs, or one holding a setuid binary) kept that submount's original dev/suid/exec-permitting attributes inside the jail, so an explicitly requested nodev/nosuid was not enforced on it. The recursive read-only pass already applies MOUNT_ATTR_RDONLY with AT_RECURSIVE, so the restriction flags were the only per-mount attributes left non-recursive.
Apply the flags recursively when the bind is recursive: thread a
recursivebool into the newapi applyMountFlags() (OR AT_RECURSIVE into mount_setattr), and re-apply the flags to every submount under dst in the legacy remountPt() by walking /proc/self/mountinfo.Verified (legacy backend): with a nodev,nosuid recursive bind of a tree containing a nested tmpfs, the nested submount inside the jail now shows nosuid,nodev (previously it kept the host's dev/suid-honoring attributes).