diff --git a/internal/cgroups/mountpoint.go b/internal/cgroups/mountpoint.go index d6238d5..91b95c3 100644 --- a/internal/cgroups/mountpoint.go +++ b/internal/cgroups/mountpoint.go @@ -34,6 +34,7 @@ const ( _mountInfoSep = " " _mountInfoOptsSep = "," _mountInfoOptionalFieldsSep = "-" + _miFieldIDMountPointSep = "/" ) const ( @@ -102,7 +103,11 @@ func NewMountPointFromLine(line string) (*MountPoint, error) { miFieldIDFSType := _miFieldOffsetFSType + fsTypeStart miFieldIDMountSource := _miFieldOffsetMountSource + fsTypeStart - miFieldIDSuperOptions := _miFieldOffsetSuperOptions + fsTypeStart + rootOpts := strings.Split(fields[_miFieldIDMountPoint], _miFieldIDMountPointSep) + if len(rootOpts) == 0 { + return nil, mountPointFormatInvalidError{line} + } + superOpts := strings.Split(rootOpts[len(rootOpts)-1], _mountInfoOptsSep) return &MountPoint{ MountID: mountID, @@ -114,7 +119,7 @@ func NewMountPointFromLine(line string) (*MountPoint, error) { OptionalFields: fields[_miFieldIDOptionalFields:(fsTypeStart - 1)], FSType: fields[miFieldIDFSType], MountSource: fields[miFieldIDMountSource], - SuperOptions: strings.Split(fields[miFieldIDSuperOptions], _mountInfoOptsSep), + SuperOptions: superOpts, }, nil } } @@ -130,6 +135,7 @@ func (mp *MountPoint) Translate(absPath string) (string, error) { if err != nil { return "", err } + if relPath == ".." || strings.HasPrefix(relPath, "../") { return "", pathNotExposedFromMountPointError{ mountPoint: mp.MountPoint, diff --git a/internal/cgroups/mountpoint_test.go b/internal/cgroups/mountpoint_test.go index afd7bc9..2bf4daa 100644 --- a/internal/cgroups/mountpoint_test.go +++ b/internal/cgroups/mountpoint_test.go @@ -47,7 +47,7 @@ func TestNewMountPointFromLine(t *testing.T) { OptionalFields: []string{}, FSType: "ext4", MountSource: "/dev/dm-0", - SuperOptions: []string{"rw", "errors=remount-ro", "data=ordered"}, + SuperOptions: []string{""}, }, }, { @@ -63,7 +63,7 @@ func TestNewMountPointFromLine(t *testing.T) { OptionalFields: []string{"shared:1"}, FSType: "cgroup", MountSource: "cgroup", - SuperOptions: []string{"rw", "cpu"}, + SuperOptions: []string{"cpu"}, }, }, } diff --git a/internal/cgroups/testdata/proc/cgroups/mountinfo b/internal/cgroups/testdata/proc/cgroups/mountinfo index e68af08..d99b05a 100644 --- a/internal/cgroups/testdata/proc/cgroups/mountinfo +++ b/internal/cgroups/testdata/proc/cgroups/mountinfo @@ -6,3 +6,4 @@ 6 5 0:5 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,cpuset 7 5 0:6 /docker /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,cpu,cpuacct 8 5 0:7 /docker /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory +9 5 0:8 /docker/memory.vmstat /sys/fs/cgroup/vmstat rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,memory