Skip to content

Commit 8866b6c

Browse files
authored
addon fix for the old issue to /proc full paths not being recorded (kubescape#872)
* addon fix for the old issue to /proc full paths not being recorded Signed-off-by: entlein <einentlein@gmail.com> * that regex was too narrow, adding the obvious ones, but might need to RCA why this regressed in the first place Signed-off-by: entlein <einentlein@gmail.com> --------- Signed-off-by: entlein <einentlein@gmail.com>
1 parent 780bbc6 commit 8866b6c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

pkg/utils/normalize_path_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,30 @@ func TestNormalizePath(t *testing.T) {
5050
input: "/46/task",
5151
expected: "/proc/46/task",
5252
},
53+
{
54+
// #721 regression: runc:[2:INIT] user-namespace-setup paths outside
55+
// the old (task|fd) allowlist previously leaked /proc-less.
56+
name: "headless proc path (setgroups)",
57+
input: "/17/setgroups",
58+
expected: "/proc/17/setgroups",
59+
},
60+
{
61+
name: "headless proc path (gid_map)",
62+
input: "/1/gid_map",
63+
expected: "/proc/1/gid_map",
64+
},
65+
{
66+
name: "headless proc path (uid_map)",
67+
input: "/1/uid_map",
68+
expected: "/proc/1/uid_map",
69+
},
70+
{
71+
// A non-proc path whose leading segment is non-numeric must be
72+
// untouched even though a later segment looks proc-like.
73+
name: "non-proc path with data dir",
74+
input: "/data/appendonlydir/x",
75+
expected: "/data/appendonlydir/x",
76+
},
5377
{
5478
name: "relative path (not dot)",
5579
input: "usr/bin/ls",

pkg/utils/path.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ import (
66
"strings"
77
)
88

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

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

0 commit comments

Comments
 (0)