Skip to content

Commit 28d2e47

Browse files
committed
rootfs: always pivot_root(2) and treat --no-pivot as a fallback
Despite the hardenings we've added to the MS_MOVE+chroot dance over the years like commit 28a697c ("rootfs: umount all procfs and sysfs with --no-pivot"), --no-pivot is fundamentally insecure and the primary reason why people use it (to run containers from initramfs) can now be done safely with pivot_root(2). So we should always try to pivot_root(2) and give a warning to the user that their configuration is insecure if we have to use the --no-pivot fallback (users should not see this message in practice, because the primary users that couldn't use pivot_root(2) now can and will transparently use it if possible). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 16b45c8 commit 28d2e47

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

libcontainer/rootfs_linux.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,19 @@ func prepareRootfs(pipe *syncSocket, iConfig *initConfig) (err error) {
202202
return err
203203
}
204204

205-
if config.NoPivotRoot {
206-
err = msMoveRoot(config.Rootfs)
207-
} else if config.Namespaces.Contains(configs.NEWNS) {
205+
if config.Namespaces.Contains(configs.NEWNS) {
208206
err = pivotRoot(config.Rootfs)
207+
if config.NoPivotRoot {
208+
logrus.Warnf("--no-pivot is deprecated and may be removed or silently ignored in a future version of runc -- see <https://github.com/opencontainers/runc/issues/4435> for more details")
209+
if err != nil {
210+
// Always try to do pivot_root(2) because it's safe, and only fallback
211+
// to the unsafe MS_MOVE+chroot(2) dance if pivot_root(2) fails.
212+
logrus.Warnf("your container failed to start with pivot_root(2) (%v) -- please open a bug report to let us know about your usecase", err)
213+
err = msMoveRoot(config.Rootfs)
214+
} else {
215+
logrus.Warnf("despite setting --no-pivot, this container successfully started using pivot_root(2) -- consider removing the --no-pivot flag")
216+
}
217+
}
209218
} else {
210219
err = chroot()
211220
}

0 commit comments

Comments
 (0)