-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix rootfs propagation mode to shared / unbindable #4724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Yusuke Sakurai <[email protected]>
# Set rootfsPropagation to shared | ||
update_config ' .linux.rootfsPropagation = "shared" ' | ||
|
||
update_config ' .process.args = ["sh", "-c", "findmnt --noheadings -o PROPAGATION /"] ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to wrap findmnt
in sh
} | ||
|
||
@test "runc run [rootfsPropagation shared]" { | ||
# Set rootfsPropagation to shared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is obvious from the code and does not need to be explained in a code comment line
# Run the container and capture the output | ||
runc run test_shared_rootfs | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"shared"* ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[ "$output" == *"shared"* ]] | |
[ "$output" == "shared" ] |
@@ -232,6 +236,27 @@ func prepareRootfs(pipe *syncSocket, iConfig *initConfig) (err error) { | |||
return nil | |||
} | |||
|
|||
// adjustRootMountPropagation applies mount propagation flags such as MS_SHARED or MS_UNBINDABLE | |||
// to the root mount after the pivot_root or chroot has taken place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment to explain why this cannot be done in prepareRoot
:
runc/libcontainer/rootfs_linux.go
Lines 1012 to 1027 in 3d8a278
func prepareRoot(config *configs.Config) error { | |
flag := unix.MS_SLAVE | unix.MS_REC | |
if config.RootPropagation != 0 { | |
flag = config.RootPropagation | |
} | |
if err := mount("", "/", "", uintptr(flag), ""); err != nil { | |
return err | |
} | |
if err := rootfsParentMountPrivate(config.Rootfs); err != nil { | |
return err | |
} | |
return mount(config.Rootfs, config.Rootfs, "bind", unix.MS_BIND|unix.MS_REC, "") | |
} | |
This PR adds support for applying mount propagation settings (MS_SHARED or MS_UNBINDABLE) to the container root based on the value of config.RootPropagation.
We apply mount propagation after executing pivot_root and rootfsParentMountPrivate
Fixes #1755
Related:
#1815
youki-dev/youki#3141
Signed-off-by: Yusuke Sakurai [email protected]