Skip to content
Open
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
3 changes: 2 additions & 1 deletion fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func (m *Manager) AddPid(subcgroup string, pid int) (retErr error) {

for _, dir := range m.paths {
path := path.Join(dir, subcgroup)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use filepath.Join here as well; even though it's identical here, it's the package intended for file-path operations.

if !strings.HasPrefix(path, dir) {
// 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