eBPF-based security platform
testing: cover exec credential transitions
John Fastabend1b5e070848a2
diff --git a/testing/upatch/kernel-obs/exec/exec_paths.c b/testing/upatch/kernel-obs/exec/exec_paths.cindex f412ba32..2a50d257 100644--- a/testing/upatch/kernel-obs/exec/exec_paths.c+++ b/testing/upatch/kernel-obs/exec/exec_paths.c@@ -159,6 +159,24 @@ static int dirfd_exec_path(const char *directory, const char *path)return wait_child(pid);}+static void exec_drop_euid(const char *path)+{+ if (setresuid(65534, 0, 65534))+ _exit(125);+ exec_payload(path);+}++static int drop_euid_exec_path(const char *path)+{+ pid_t pid = fork();++ if (pid == 0)+ exec_drop_euid(path);+ if (pid < 0)+ return -1;+ return wait_child(pid);+}+static int make_script(const char *directory, char *path, size_t path_size){static const char script[] = "#!/bin/sh\nexit 0\n";@@ -211,6 +229,8 @@ int main(int argc, char **argv)return fd_exec_path(argv[2], 1) ? 1 : 0;if (argc == 4 && !strcmp(argv[1], "--execveat-dirfd"))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))) {fprintf(stderr, "could not create shebang test executable\n");return 1;diff --git a/testing/upatch/kernel-obs/network/kernel_obs_events.py b/testing/upatch/kernel-obs/network/kernel_obs_events.pyindex e6039658..7dc7d4f1 100755--- a/testing/upatch/kernel-obs/network/kernel_obs_events.py+++ b/testing/upatch/kernel-obs/network/kernel_obs_events.py@@ -38,6 +38,11 @@ def exec_event():subprocess.run(["./upatch/kernel-obs/exec/exec-paths","--execveat-dirfd", directory,os.path.basename(dirfd_executable)], check=True)+ dropped_uid_executable = os.path.join(directory, "true-drop-euid")+ shutil.copyfile("/bin/true", dropped_uid_executable)+ os.chmod(dropped_uid_executable, 0o755)+ subprocess.run(["./upatch/kernel-obs/exec/exec-paths",+ "--drop-euid", dropped_uid_executable], check=True)subprocess.run(["./upatch/kernel-obs/exec/exec-paths", "--replace", executable],check=True)diff --git a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh b/testing/upatch/kernel-obs/network/t1210-kernel-obs.shindex 782d3d93..f8081aa5 100755--- a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh+++ b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh@@ -107,6 +107,8 @@ self_exec = [r for r in tables["exec"]assert sum(int(r["exec_count"]) for r in self_exec) >= 5, self_execassert all(not r["caller_inferred"] and "caller" in rfor r in self_exec), self_exec+assert any(r["uid"] == 0 and r["euid"] == 0 and+ int(r["cap_effective"]) > 0 for r in self_exec), self_execreplace_exec = [r for r in tables["exec"]if r["path"].endswith("/true") and(r.get("caller", {}).get("dev"),@@ -119,6 +121,12 @@ for method in ("execveat-empty", "fexecve"):(r.get("caller", {}).get("dev"),r.get("caller", {}).get("ino")) == helper_id]assert fd_exec, (method, tables["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_execscript = [r for r in tables["exec"]if r["path"].endswith("/exec-script") and(r.get("caller", {}).get("dev"),