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
24 changes: 24 additions & 0 deletions pkg/utils/normalize_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ func TestNormalizePath(t *testing.T) {
input: "/46/task",
expected: "/proc/46/task",
},
{
// #721 regression: runc:[2:INIT] user-namespace-setup paths outside
// the old (task|fd) allowlist previously leaked /proc-less.
name: "headless proc path (setgroups)",
input: "/17/setgroups",
expected: "/proc/17/setgroups",
},
{
name: "headless proc path (gid_map)",
input: "/1/gid_map",
expected: "/proc/1/gid_map",
},
{
name: "headless proc path (uid_map)",
input: "/1/uid_map",
expected: "/proc/1/uid_map",
},
{
// A non-proc path whose leading segment is non-numeric must be
// untouched even though a later segment looks proc-like.
name: "non-proc path with data dir",
input: "/data/appendonlydir/x",
expected: "/data/appendonlydir/x",
},
{
name: "relative path (not dot)",
input: "usr/bin/ls",
Expand Down
12 changes: 11 additions & 1 deletion pkg/utils/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import (
"strings"
)

var headlessProcRegex = regexp.MustCompile(`^/\d+/(task|fd)(/|$)`)
// headlessProcRegex matches a headless /proc/<pid>/<file> path — a /proc/<pid>/...
// path stripped of its /proc root — which NormalizePath re-roots under /proc.
//
// The allowlist enumerates the /proc/<pid> entries opened by runc:[2:INIT]
// during container/user-namespace setup. It was previously only (task|fd),
// which let the sibling entries (setgroups, gid_map, uid_map, status, cgroup,
// ...) leak /proc-less into learned ContainerProfiles — a regression of #721.
// It stays an explicit allowlist rather than a bare `^/\d+` catch-all so a
// genuine top-level numeric directory is never misread as a PID; extend it if
// another /proc/<pid> entry is observed leaking.
var headlessProcRegex = regexp.MustCompile(`^/\d+/(task|fd|setgroups|gid_map|uid_map|status|stat|cgroup|mountinfo|maps|environ|comm|cmdline|ns)(/|$)`)

// NormalizePath normalizes a path by:
// 1. Prepending "/proc" to "headless" proc paths (e.g. /46/task/46/fd -> /proc/46/task/46/fd)
Expand Down
Loading