Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devices/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func setV2(dirPath string, r *cgroups.Resources) error {
if err != nil {
return err
}
dirFD, err := unix.Open(dirPath, unix.O_DIRECTORY|unix.O_RDONLY, 0o600)
dirFD, err := unix.Open(dirPath, unix.O_DIRECTORY|unix.O_RDONLY|unix.O_CLOEXEC, 0o600)
if err != nil {
return fmt.Errorf("cannot get dir FD for %s", dirPath)
}
Expand Down
7 changes: 4 additions & 3 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"sync"

Expand Down Expand Up @@ -153,8 +153,9 @@ func (m *Manager) AddPid(subcgroup string, pid int) (retErr error) {
c := m.cgroups

for _, dir := range m.paths {
path := path.Join(dir, subcgroup)
if !strings.HasPrefix(path, dir) {
path := filepath.Join(dir, subcgroup)
// Make sure path is either dir itself or below it.
if path != dir && !strings.HasPrefix(path, dir+"/") {
return fmt.Errorf("bad sub cgroup path: %s", subcgroup)
}

Expand Down
3 changes: 2 additions & 1 deletion fs2/fs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (m *Manager) Apply(pid int) error {
// a cgroup under under the manager's cgroup.
func (m *Manager) AddPid(subcgroup string, pid int) error {
path := filepath.Join(m.dirPath, subcgroup)
if !strings.HasPrefix(path, m.dirPath) {
// Make sure path is either m.dirPath itself or below it.
if path != m.dirPath && !strings.HasPrefix(path, m.dirPath+"/") {
return fmt.Errorf("bad sub cgroup path: %s", subcgroup)
}

Expand Down