diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-30 22:11:15 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-30 22:11:15 +0300 |
| commit | 04881431fb051fc9915184c54dffdcbb9aa5c65e (patch) | |
| tree | cd7a88571aaf0032ab8560f4abb51554d9517bee /internal/generate/codegen_test.go | |
| parent | dfb6190d109593227545df2e0caf82b6ee2c578f (diff) | |
test(perf_event_open): lock in audit findings
Audited perf_event_open(2) against the man page: it returns a new fd (or
-1), args[0] is a struct perf_event_attr* userspace pointer (NOT an fd),
args[1] is a monitored pid, and only args[3] group_fd is a real fd.
The existing implementation is correct (KindPerfOpen by name, not KindFd;
FamilySecurity; exit as UNCLASSIFIED RetEvent). Add lock-in tests:
- codegen: assert args[0] is read via bpf_probe_read_user as the attr
struct and never captured as an fd (negative assertions on args[0]/args[1]).
- eventloop: a failed return (-1) registers no fd in fdState.
- perfDescriptorName format pin (perf: prefix).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/generate/codegen_test.go')
| -rw-r--r-- | internal/generate/codegen_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/internal/generate/codegen_test.go b/internal/generate/codegen_test.go index e841f45..58ed60c 100644 --- a/internal/generate/codegen_test.go +++ b/internal/generate/codegen_test.go @@ -1992,6 +1992,16 @@ func TestGeneratePerfEventOpenHandler(t *testing.T) { requireContains(t, output, "ev->target_pid = (__s32)ctx->args[1];") requireContains(t, output, "ev->group_fd = (__s32)ctx->args[3];") requireContains(t, output, "ev->event_type = EXIT_RET_EVENT;") + + // Audit lock-in (perf_event_open(2)): args[0] is a + // `struct perf_event_attr *` userspace pointer, NOT an fd, and args[1] + // is a pid (not an fd). The handler must read args[0] only via + // bpf_probe_read_user (the attr struct) and never capture args[0] or + // args[1] as an fd. Only group_fd at args[3] is a genuine fd. + requireContains(t, output, "bpf_probe_read_user(&attr, sizeof(attr), (void *)ctx->args[0])") + requireNotContains(t, output, "ev->fd = (__s32)ctx->args[0];") + requireNotContains(t, output, "ev->fd = (__s32)ctx->args[1];") + requireNotContains(t, output, "ev->group_fd = (__s32)ctx->args[0];") } func TestGenerateNameToHandleAtHandler(t *testing.T) { |
