eBPF-based security platform
testing: assert exec caller attribution
John Fastabend9b5c855520fb
diff --git a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh b/testing/upatch/kernel-obs/network/t1210-kernel-obs.shindex f4e6c7cc..782d3d93 100755--- a/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh+++ b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh@@ -91,6 +91,8 @@ exec_ids = {(r["executable"]["dev"], r["executable"]["ino"])assert any(r["name"] == "true" and r["path"].endswith("/true")for r in tables["exec"]), tables["exec"]assert any("caller" in r for r in tables["exec"]), tables["exec"]+assert any(r["caller_inferred"] and "caller" in r+ for r in tables["exec"]), tables["exec"]helper_records = [r for r in tables["exec"]if r["path"].endswith("/kernel-obs/exec/exec-paths")]helper = next(r for r in helper_records@@ -103,6 +105,8 @@ self_exec = [r for r in tables["exec"]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 all(not r["caller_inferred"] and "caller" in r+ 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"),diff --git a/testing/upatch/kernel-obs/priv/kernel-obs-priv.sh b/testing/upatch/kernel-obs/priv/kernel-obs-priv.shindex 13c1db47..c0f7e5b8 100755--- a/testing/upatch/kernel-obs/priv/kernel-obs-priv.sh+++ b/testing/upatch/kernel-obs/priv/kernel-obs-priv.sh@@ -2,7 +2,7 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo-cd "$(dirname "$0")/.."+cd "$(dirname "$0")/../../..". ./integration-lib.shtarget_guardcommand -v python3 >/dev/null 2>&1 || test_skip_all "no python3"@@ -61,7 +61,7 @@ test_expect_success 'non-executable mappings do not produce exec protection recoSHIRUDO_TEST_WORK_DIR="$WORK/events" \python3 upatch/kernel-obs/priv/priv_events.py negative &&export_priv "$WORK/negative.ndjson" &&- python3 upatch/kernel-obs/priv/priv_events.py check-negative "$WORK/negative.ndjson"+ python3 upatch/kernel-obs/priv/priv_events.py check-negative "$WORK/negative.ndjson"'test_expect_success 'privilege events produce attributed priv records' '@@ -71,6 +71,10 @@ test_expect_success 'privilege events produce attributed priv records' 'python3 upatch/kernel-obs/priv/priv_events.py generate "$WORK/expected.json" &&cat "$MODPROBE_BACKUP" >"$MODPROBE_FILE" &&rm -f "$MODPROBE_BACKUP" &&+ "$SHIRUDO_BIN" upatch map "$NAME" exec \+ --json="$WORK/exec.ndjson" >/dev/null &&+ python3 upatch/kernel-obs/priv/priv_events.py \+ check-exec-unknown "$WORK/exec.ndjson" &&export_priv "$WORK/priv.ndjson" &&python3 upatch/kernel-obs/priv/priv_events.py check \"$WORK/expected.json" "$WORK/priv.ndjson"diff --git a/testing/upatch/kernel-obs/priv/priv_events.py b/testing/upatch/kernel-obs/priv/priv_events.pyindex e392c181..e6a974be 100644--- a/testing/upatch/kernel-obs/priv/priv_events.py+++ b/testing/upatch/kernel-obs/priv/priv_events.py@@ -288,6 +288,18 @@ def check_negative(path):for record in records), records+def check_exec_unknown(path):+ with open(path, encoding="utf-8") as source:+ documents = [json.loads(line) for line in source]+ document = next(doc for doc in documents if doc.get("map") == "exec")+ records = document["records"]+ unknown = [record for record in records+ if record["path"].endswith("/false")]+ assert unknown, records+ assert any("caller" not in record and not record["caller_inferred"]+ for record in unknown), unknown++def check_positive(expected_path, records_path):with open(expected_path, encoding="utf-8") as source:expected = json.load(source)@@ -365,7 +377,7 @@ def check_positive(expected_path, records_path):def main():if len(sys.argv) < 2:- raise SystemExit("usage: priv_events.py negative | generate FILE | check EXPECTED NDJSON | check-negative NDJSON")+ raise SystemExit("usage: priv_events.py negative | generate FILE | check EXPECTED NDJSON | check-negative NDJSON | check-exec-unknown NDJSON")mode = sys.argv[1]if mode == "negative":nonexec_mapping_events()@@ -375,6 +387,8 @@ def main():check_positive(sys.argv[2], sys.argv[3])elif mode == "check-negative" and len(sys.argv) == 3:check_negative(sys.argv[2])+ elif mode == "check-exec-unknown" and len(sys.argv) == 3:+ check_exec_unknown(sys.argv[2])else:raise SystemExit("invalid priv_events.py arguments")