mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct: optimize maskPaths for single-directory case
This is a follow-up to #5275. That change reused a single tmpfs mount
to mask multiple directories, which is efficient when masking more than
one path. However, it introduced unnecessary overhead when only one
directory is masked. This commit restores the original behavior for the
single-path case while preserving shared tmpfs logic for multiple paths.
Signed-off-by: lifubang <lifubang@acmcoder.com>
(cherry picked from commit e7e2f00248)
Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
@@ -400,7 +400,7 @@ func mountCgroupV2(m mountEntry, c *mountConfig) error {
|
|||||||
// Mask `/sys/fs/cgroup` to ensure it is read-only, even when `/sys` is mounted
|
// Mask `/sys/fs/cgroup` to ensure it is read-only, even when `/sys` is mounted
|
||||||
// with `rbind,ro` (`runc spec --rootless` produces `rbind,ro` for `/sys`).
|
// with `rbind,ro` (`runc spec --rootless` produces `rbind,ro` for `/sys`).
|
||||||
err = utils.WithProcfdFile(m.dstFile, func(procfd string) error {
|
err = utils.WithProcfdFile(m.dstFile, func(procfd string) error {
|
||||||
return maskPaths(c.root, []string{procfd}, c.label)
|
return maskDir(procfd, c.label)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -1335,6 +1335,11 @@ func verifyDevNull(f *os.File) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// maskDir mounts a read-only tmpfs on top of the specified path.
|
||||||
|
func maskDir(path, mountLabel string) error {
|
||||||
|
return mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=1", mountLabel))
|
||||||
|
}
|
||||||
|
|
||||||
// maskPaths masks the top of the specified paths inside a container to avoid
|
// maskPaths masks the top of the specified paths inside a container to avoid
|
||||||
// security issues from processes reading information from non-namespace aware
|
// security issues from processes reading information from non-namespace aware
|
||||||
// mounts ( proc/kcore ).
|
// mounts ( proc/kcore ).
|
||||||
@@ -1392,7 +1397,7 @@ func maskPaths(rootFd *os.File, paths []string, mountLabel string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bindFailed || sharedMaskSrc == nil {
|
if bindFailed || sharedMaskSrc == nil {
|
||||||
err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=1", mountLabel))
|
err = maskDir(path, mountLabel)
|
||||||
if err == nil && !bindFailed && sharedMaskSrc == nil {
|
if err == nil && !bindFailed && sharedMaskSrc == nil {
|
||||||
// Establish this mount as the reusable shared source. reopenAfterMount
|
// Establish this mount as the reusable shared source. reopenAfterMount
|
||||||
// resolves the underlying inode via procfs and re-opens it through
|
// resolves the underlying inode via procfs and re-opens it through
|
||||||
|
|||||||
Reference in New Issue
Block a user