Skip to content

eBPF-based security platform

testing: distinguish kernel observability exec cases

John Fastabend650231e9d4bb
diff --git a/testing/upatch/kernel-obs/exec/exec_paths.c b/testing/upatch/kernel-obs/exec/exec_paths.c
index 2a50d257..6dbf8a2b 100644
--- a/testing/upatch/kernel-obs/exec/exec_paths.c
+++ b/testing/upatch/kernel-obs/exec/exec_paths.c
@@ -177,14 +177,15 @@ static int drop_euid_exec_path(const char *path)
return wait_child(pid);
}
-static int make_script(const char *directory, char *path, size_t path_size)
+static int make_script(const char *directory, const char *name, char *path,
+ size_t path_size)
{
static const char script[] = "#!/bin/sh\nexit 0\n";
ssize_t written;
int length;
int fd;
- length = snprintf(path, path_size, "%s/exec-script", directory);
+ length = snprintf(path, path_size, "%s/%s", directory, name);
if (length < 0 || (size_t)length >= path_size)
return -1;
fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0700);
@@ -216,6 +217,7 @@ static int thread_exec_path(const char *path)
int main(int argc, char **argv)
{
+ char script_fd[4096];
char script[4096];
const char *self = argv[0];
@@ -231,7 +233,10 @@ int main(int argc, char **argv)
return dirfd_exec_path(argv[2], argv[3]) ? 1 : 0;
if (argc == 3 && !strcmp(argv[1], "--drop-euid"))
return drop_euid_exec_path(argv[2]) ? 1 : 0;
- if (argc != 2 || make_script(argv[1], script, sizeof(script))) {
+ if (argc != 2 || make_script(argv[1], "exec-script", script,
+ sizeof(script)) ||
+ make_script(argv[1], "exec-script-fd", script_fd,
+ sizeof(script_fd))) {
fprintf(stderr, "could not create shebang test executable\n");
return 1;
}
@@ -255,7 +260,7 @@ int main(int argc, char **argv)
fprintf(stderr, "fork() -> shebang execve() case failed\n");
return 1;
}
- if (fd_exec_path(script, 1)) {
+ if (fd_exec_path(script_fd, 1)) {
fprintf(stderr, "fexecve() -> shebang case failed\n");
return 1;
}
diff --git a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
index f8081aa5..4d730322 100755
--- a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
+++ b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
@@ -104,7 +104,7 @@ self_exec = [r for r in tables["exec"]
if (r["executable"]["dev"], r["executable"]["ino"]) == helper_id
and (r.get("caller", {}).get("dev"),
r.get("caller", {}).get("ino")) == helper_id]
-assert sum(int(r["exec_count"]) for r in self_exec) >= 5, self_exec
+assert sum(int(r["exec_count"]) for r in self_exec) == 5, self_exec
assert all(not r["caller_inferred"] and "caller" in r
for r in self_exec), self_exec
assert any(r["uid"] == 0 and r["euid"] == 0 and
@@ -120,23 +120,35 @@ for method in ("execveat-empty", "fexecve"):
if r["path"].endswith(f"/true-{method}") and
(r.get("caller", {}).get("dev"),
r.get("caller", {}).get("ino")) == helper_id]
- assert fd_exec, (method, tables["exec"])
+ assert len(fd_exec) == 1 and int(fd_exec[0]["exec_count"]) == 1, fd_exec
+dirfd_exec = [r for r in tables["exec"]
+ if r["path"].endswith("/true-execveat-dirfd") and
+ (r.get("caller", {}).get("dev"),
+ r.get("caller", {}).get("ino")) == helper_id]
+assert len(dirfd_exec) == 1 and int(dirfd_exec[0]["exec_count"]) == 1, dirfd_exec
drop_euid_exec = [r for r in tables["exec"]
if r["path"].endswith("/true-drop-euid") and
(r.get("caller", {}).get("dev"),
r.get("caller", {}).get("ino")) == helper_id]
-assert any(r["uid"] == 65534 and r["euid"] == 65534 and
- int(r["cap_effective"]) == 0 for r in drop_euid_exec), drop_euid_exec
-script = [r for r in tables["exec"]
- if r["path"].endswith("/exec-script") and
- (r.get("caller", {}).get("dev"),
- r.get("caller", {}).get("ino")) == helper_id]
-assert script and not any(r["interpreter"] for r in script), script
-script_id = (script[0]["executable"]["dev"], script[0]["executable"]["ino"])
-assert any(r["interpreter"] and
- (r.get("caller", {}).get("dev"), r.get("caller", {}).get("ino")) ==
- script_id and r["pid"] == script[0]["pid"]
- for r in tables["exec"]), tables["exec"]
+assert len(drop_euid_exec) == 1, drop_euid_exec
+assert (drop_euid_exec[0]["uid"] == 65534 and
+ drop_euid_exec[0]["euid"] == 65534 and
+ int(drop_euid_exec[0]["cap_effective"]) == 0), drop_euid_exec
+for name in ("exec-script", "exec-script-fd"):
+ scripts = [r for r in tables["exec"]
+ if r["path"].endswith("/" + name) and
+ (r.get("caller", {}).get("dev"),
+ r.get("caller", {}).get("ino")) == helper_id]
+ assert len(scripts) == 1 and not scripts[0]["interpreter"], scripts
+ assert int(scripts[0]["exec_count"]) == 1, scripts
+ script_id = (scripts[0]["executable"]["dev"],
+ scripts[0]["executable"]["ino"])
+ interpreters = [r for r in tables["exec"]
+ if r["interpreter"] and
+ (r.get("caller", {}).get("dev"),
+ r.get("caller", {}).get("ino")) == script_id and
+ r["pid"] == scripts[0]["pid"]]
+ assert len(interpreters) == 1, (scripts, interpreters)
for name in ("net", "dns"):
assert any((r["executable"]["dev"], r["executable"]["ino"]) in exec_ids
for r in tables[name]), (name, tables[name])