Skip to content

Commit b4cb2f5

Browse files
committed
rootfs: re-allow dangling symlinks in mount targets
It seems there are a fair few images where dangling symlinks are used as path components for mount targets, which pathrs-lite does not support (and it would be difficult to fully support this in a race-free way). This was actually meant to be blocked by commit 63c2908 ("rootfs: try to scope MkdirAll to stay inside the rootfs"), followed by commit dd827f7 ("utils: switch to securejoin.MkdirAllHandle"). However, we still used SecureJoin to construct mountpoint targets, which means that dangling symlinks were "resolved" before reaching pathrs-lite. This patch basically re-adds this hack in order to reduce the breakages we've seen so far. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent ee56b85 commit b4cb2f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libcontainer/rootfs_linux.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,17 @@ func (m *mountEntry) createOpenMountpoint(rootfs string) (Err error) {
530530
dstIsFile = !fi.IsDir()
531531
}
532532

533+
// In previous runc versions, we would tolerate nonsense paths with
534+
// dangling symlinks as path components. pathrs-lite does not support
535+
// this, so instead we have to emulate this behaviour by doing
536+
// SecureJoin *purely to get a semi-reasonable path to use* and then we
537+
// use pathrs-lite to operate on the path safely.
538+
newUnsafePath, err := securejoin.SecureJoin(rootfs, unsafePath)
539+
if err != nil {
540+
return err
541+
}
542+
unsafePath = utils.StripRoot(rootfs, newUnsafePath)
543+
533544
if dstIsFile {
534545
dstFile, err = pathrs.CreateInRoot(rootfs, unsafePath, unix.O_CREAT|unix.O_EXCL|unix.O_NOFOLLOW, 0o644)
535546
} else {

0 commit comments

Comments
 (0)