Skip to content

mnt: apply readonly recursively to new-api bind mounts - #371

Merged
robertswiecki merged 1 commit into
google:masterfrom
mcc0nnell:fix/newapi-recursive-readonly
Oct 28, 2026
Merged

robertswiecki merged 1 commit into
google:masterfrom
mcc0nnell:fix/newapi-recursive-readonly

Conversation

@mcc0nnell

Copy link
Copy Markdown
Contributor

Summary

Fixes #369.

doBindMountAt() previously stripped MS_RDONLY before applyMountFlags(), so recursive mount_setattr(AT_RECURSIVE) propagated nosuid, nodev, and noexec but not read-only. The later remountPt() affects only the top-level bind mount. When is_root_rw: true skips the root-wide readonly pass, a nested submount could remain writable.

This change:

  • Applies MS_RDONLY to the cloned bind subtree before move_mount(); AT_RECURSIVE is selected when MS_REC is present.
  • Fails closed if applying read-only attributes fails, rather than degrading to a top-level-only remount.
  • Adds a privilege-gated regression with a real nested tmpfs and a make target. It skips when mount privileges are unavailable.

Validation

Reproduced on Linux 6.8 in an isolated privileged Docker mount namespace, explicitly forcing --experimental_mnt=new and writable jail root (--rw):

Test Upstream master Patch
Readonly recursive bind, top-level ro ro
Readonly recursive bind, nested tmpfs rw (bug) ro
Writable recursive bind, top-level and nested tmpfs — Both rw, writes allowed
Readonly file bind — ro, write rejected

The exact committed regression (make test-newapi-recursive-readonly) fails against upstream master (exit 1) and passes against the patched commit (exit 0). With insufficient privileges, the test reports a skip.

Additional checks against the exact commit:

  • make -j4 nsjail — exit 0.
  • make test-cmdline — 7/7 pass.
  • Four native test binaries — all exit 0.
  • git diff --check — clean.

The full network-dependent make test suite was not executed. Real mount behavior was verified as described above.

Only mnt_newapi.cc, tests/newapi_recursive_readonly.sh, and Makefile changed.

@mcc0nnell
mcc0nnell force-pushed the fix/newapi-recursive-readonly branch from fd3e50a to bf8d5af Compare October 23, 2026 14:15
@robertswiecki

Copy link
Copy Markdown
Collaborator

Thank you!

@robertswiecki
robertswiecki merged commit d8415bc into google:master Oct 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mnt_newapi: MS_RDONLY not applied recursively to nested submounts of bind mounts when root is rw

2 participants