Skip to content

Commit e264c9f

Browse files
committed
tests: test_seccomp_validate: check for syscalls not in the filter
For each filter, we track which syscalls we have already seen, and at the end we check for the ones we haven't seen. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 30d0260 commit e264c9f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/integration_tests/security/test_seccomp_validate.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def test_validate_filter(seccompiler, bin_test_syscall, monkeypatch, tmp_path):
9494
fc_filter_path = Path(f"../resources/seccomp/{ARCH}-unknown-linux-musl.json")
9595
fc_filter = json.loads(fc_filter_path.read_text(encoding="ascii"))
9696

97+
# As of linux v6.12 both x786_64 and aarch64 are below this number
98+
syscall_id_max = 512
99+
97100
# cd to a tmp dir because we may generate a bunch of intermediate files
98101
monkeypatch.chdir(tmp_path)
99102
# prevent coredumps
@@ -105,14 +108,16 @@ def test_validate_filter(seccompiler, bin_test_syscall, monkeypatch, tmp_path):
105108
for thread, filter_data in fc_filter.items():
106109
filter_path = Path(f"{thread}.bpf")
107110
filter_path.write_bytes(filters[thread])
111+
seen_syscalls = set()
108112
# for each rule, run the helper program and execute a syscall
109113
for rule in filter_data["filter"]:
110114
print(filter_path, rule)
111115
syscall = rule["syscall"]
116+
syscall_id = seccomp.resolve_syscall(arch, syscall)
117+
seen_syscalls.add(syscall_id)
112118
# this one cannot be called directly
113119
if syscall in ["rt_sigreturn"]:
114120
continue
115-
syscall_id = seccomp.resolve_syscall(arch, syscall)
116121
cmd = f"{bin_test_syscall} {filter_path} {syscall_id}"
117122
if "args" not in rule:
118123
# syscall should be allowed with any arguments and exit 0
@@ -136,3 +141,11 @@ def test_validate_filter(seccompiler, bin_test_syscall, monkeypatch, tmp_path):
136141
# if we call it with unallowed args, it should exit 159
137142
# 159 = 128 (abnormal termination) + 31 (SIGSYS)
138143
assert outcome.returncode == 159
144+
print("now we test syscalls we didn't see in the filter")
145+
for syscall_id in range(syscall_id_max):
146+
if syscall_id in seen_syscalls:
147+
continue
148+
cmd = f"{bin_test_syscall} {filter_path} {syscall_id}"
149+
print(cmd)
150+
# and they should all exit 159
151+
assert utils.run_cmd(cmd).returncode == 159

0 commit comments

Comments
 (0)