Skip to content

Commit

Permalink
Merge pull request #2717 from kolyshkin/check-proc-opt
Browse files Browse the repository at this point in the history
libct/checkProcMounts: optimize
  • Loading branch information
AkihiroSuda authored Jan 29, 2021
2 parents 8e062f1 + 692fab0 commit e7bd1fb
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,29 +489,6 @@ func getCgroupMounts(m *configs.Mount) ([]*configs.Mount, error) {
// if source is nil, don't stat the filesystem. This is used for restore of a checkpoint.
func checkProcMount(rootfs, dest, source string) error {
const procPath = "/proc"
// White list, it should be sub directories of invalid destinations
validDestinations := []string{
// These entries can be bind mounted by files emulated by fuse,
// so commands like top, free displays stats in container.
"/proc/cpuinfo",
"/proc/diskstats",
"/proc/meminfo",
"/proc/stat",
"/proc/swaps",
"/proc/uptime",
"/proc/loadavg",
"/proc/slabinfo",
"/proc/net/dev",
}
for _, valid := range validDestinations {
path, err := filepath.Rel(filepath.Join(rootfs, valid), dest)
if err != nil {
return err
}
if path == "." {
return nil
}
}
path, err := filepath.Rel(filepath.Join(rootfs, procPath), dest)
if err != nil {
return err
Expand All @@ -537,6 +514,30 @@ func checkProcMount(rootfs, dest, source string) error {
}
return fmt.Errorf("%q cannot be mounted because it is not of type proc", dest)
}

// Here dest is definitely under /proc. Do not allow those,
// except for a few specific entries emulated by lxcfs.
validProcMounts := []string{
"/proc/cpuinfo",
"/proc/diskstats",
"/proc/meminfo",
"/proc/stat",
"/proc/swaps",
"/proc/uptime",
"/proc/loadavg",
"/proc/slabinfo",
"/proc/net/dev",
}
for _, valid := range validProcMounts {
path, err := filepath.Rel(filepath.Join(rootfs, valid), dest)
if err != nil {
return err
}
if path == "." {
return nil
}
}

return fmt.Errorf("%q cannot be mounted because it is inside /proc", dest)
}

Expand Down

0 comments on commit e7bd1fb

Please sign in to comment.