Skip to content

Commit 435cc81

Browse files
committed
init: use securejoin for /proc/self/setgroups
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 77d217c commit 435cc81

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libcontainer/init_linux.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io"
89
"net"
910
"os"
1011
"path/filepath"
@@ -21,6 +22,7 @@ import (
2122

2223
"github.com/opencontainers/cgroups"
2324
"github.com/opencontainers/runc/internal/linux"
25+
"github.com/opencontainers/runc/internal/pathrs"
2426
"github.com/opencontainers/runc/libcontainer/capabilities"
2527
"github.com/opencontainers/runc/libcontainer/configs"
2628
"github.com/opencontainers/runc/libcontainer/system"
@@ -470,7 +472,12 @@ func setupUser(config *initConfig) error {
470472
// We don't need to use /proc/thread-self here because setgroups is a
471473
// per-userns file and thus is global to all threads in a thread-group.
472474
// This lets us avoid having to do runtime.LockOSThread.
473-
setgroups, err := os.ReadFile("/proc/self/setgroups")
475+
var setgroups []byte
476+
setgroupsFile, err := pathrs.ProcSelfOpen("setgroups", unix.O_RDONLY)
477+
if err == nil {
478+
setgroups, err = io.ReadAll(setgroupsFile)
479+
_ = setgroupsFile.Close()
480+
}
474481
if err != nil && !os.IsNotExist(err) {
475482
return err
476483
}

0 commit comments

Comments
 (0)