Skip to content

mnt: make recursive read-only binds truly recursive - #277

Closed
Alb3e3 wants to merge 1 commit into
google:masterfrom
Alb3e3:alb3e3/recursive-bindmount-hardening
Closed

Alb3e3 wants to merge 1 commit into
google:masterfrom
Alb3e3:alb3e3/recursive-bindmount-hardening

Conversation

@Alb3e3

@Alb3e3 Alb3e3 commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #125.

Summary

--bindmount_ro / -R uses MS_REC while creating the bind, but the final MS_REMOUNT | MS_BIND | MS_RDONLY operation only changes the top mount. A writable nested mount such as /dev/shm therefore remains writable inside an otherwise read-only recursive bind.

  • Apply MOUNT_ATTR_RDONLY with mount_setattr(2) and AT_RECURSIVE before the existing top-level remount.
  • Use the same helper for the legacy and new mount backends.
  • Keep the existing ordered per-mount remount pass, so a later explicit writable child bind still overrides the recursive parent policy.
  • Fail sandbox setup when final mount attributes cannot be enforced instead of continuing with a weaker mount policy.

On kernels without mount_setattr(2) support, recursive read-only bind setup now fails closed rather than silently exposing writable nested mounts.

Verification

  • Confirmed the regression on the unmodified image with both --experimental_mnt=old and --experimental_mnt=new: -R /dev still allowed creating a file in /dev/shm.
  • Confirmed both patched backends reject the nested write with Read-only file system.
  • Confirmed a later -B /dev/shm remains writable with both backends.
  • Built with make -j2 and the project Dockerfile.

@Alb3e3
Alb3e3 force-pushed the alb3e3/recursive-bindmount-hardening branch from c6b70c6 to de2ccd7 Compare August 21, 2026 12:41
@Alb3e3

Alb3e3 commented Aug 21, 2026 •

Copy link
Copy Markdown
Author

Rebased this branch onto current master and reran the focused recursive-bind checks on both mount backends. -R /dev now blocks nested /dev/shm writes with Read-only file system, while an explicit child override with -B /dev/shm stays writable in both --experimental_mnt=old and --experimental_mnt=new. Docker build also still passes. Would appreciate another look when you have a moment.

@robertswiecki

Copy link
Copy Markdown
Collaborator

This has been superseded by #283 / #284 which goes a bit further (more flags)

@Alb3e3

Alb3e3 commented Aug 26, 2026

Copy link
Copy Markdown
Author

Makes sense. #284 applying the per-mount nosuid/nodev/noexec recursively is the more complete fix. Thanks for the pointer, and good to see the recursive-bind hardening land.

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.

Note about non-recursive readonly mounts?

2 participants