Skip to content

Commit d4f0f9a

Browse files
committed
specconv: emit an error when using MS_PRIVATE with --no-pivot
Due to the semantics of chroot(2) when it comes to mount namespaces, it is not generally safe to use MS_PRIVATE as a mount propgation when using chroot(2). The reason for this is that this effectively results in a set of mount references being held by the chroot'd namespace which the namespace cannot free. pivot_root(2) does not have this issue because the @old_root can be unmounted by the process. Ultimately, --no-pivot is not really necessary anymore as a commonly used option since f8e6b5a ("rootfs: make pivot_root not use a temporary directory") resolved the read-only issue. But if someone really needs to use it, MS_PRIVATE is never a good idea. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent dc1552a commit d4f0f9a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

libcontainer/specconv/spec_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
203203
if config.RootPropagation, exists = mountPropagationMapping[spec.Linux.RootfsPropagation]; !exists {
204204
return nil, fmt.Errorf("rootfsPropagation=%v is not supported", spec.Linux.RootfsPropagation)
205205
}
206+
if config.NoPivotRoot && (config.RootPropagation&unix.MS_PRIVATE != 0) {
207+
return nil, fmt.Errorf("rootfsPropagation of [r]private is not safe without pivot_root")
208+
}
206209

207210
for _, ns := range spec.Linux.Namespaces {
208211
t, exists := namespaceMapping[ns.Type]

0 commit comments

Comments
 (0)