summaryrefslogtreecommitdiff
path: root/internal/eventloop_ipc_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-30 22:16:33 +0300
committerPaul Buetow <paul@buetow.org>2026-05-30 22:16:33 +0300
commitc5ef17c2b728eae057fae43db020d1023e5cc634 (patch)
tree3daee5dd2e6e86c61ce1c67b35f24c3801e4ff33 /internal/eventloop_ipc_test.go
parent04881431fb051fc9915184c54dffdcbb9aa5c65e (diff)
test(pipe): lock in pipe/pipe2 IPC classification and fd-pair exit reads
Audit of pipe(2)/pipe2(2) (task dx) confirmed the tracing implementation is correct: KindPipe (not KindFd, since args[0] is an output ptr to int[2], not an fd), FamilyIPC, and an UNCLASSIFIED int return. Enter stashes the output ptr (flags=0 for pipe, args[1] for pipe2); exit reads the fd pair via bpf_probe_read_user guarded by ret==0, mirroring the socketpair pipe-like pattern. The only gaps were missing lock-in tests, now added: - codegen: assert the exit handler reads the fd pair from the stashed output buffer (ret==0 guard, bpf_probe_read_user, fd0/fd1) and that the flag-less pipe variant hardcodes flags=0 and never reads args[1]. - classify: pipe/pipe2 are never KindFd and stay UNCLASSIFIED on ret. - runtime: a failed pipe (ret==-1) tracks no descriptors and attaches no file. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/eventloop_ipc_test.go')
-rw-r--r--internal/eventloop_ipc_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/eventloop_ipc_test.go b/internal/eventloop_ipc_test.go
index 53b8be7..7557bdf 100644
--- a/internal/eventloop_ipc_test.go
+++ b/internal/eventloop_ipc_test.go
@@ -42,6 +42,47 @@ func TestHandlePipeExitTracksReturnedFds(t *testing.T) {
verifyFileDescriptor(t, el, 53, "pipe:524288:52:53")
}
+// TestHandlePipeExitFailureTracksNoFds locks in the pipe(2) failure path:
+// when the syscall returns -1 the kernel writes nothing into the output buffer,
+// so the BPF exit handler leaves fd0/fd1 at -1 and the runtime must not register
+// any descriptor. Tracking a bogus fd here would attribute later reads/writes to
+// a pipe that was never created.
+func TestHandlePipeExitFailureTracksNoFds(t *testing.T) {
+ el := mustNewEventLoop(t, eventLoopConfig{})
+
+ enter := &types.PipeEvent{
+ EventType: types.ENTER_PIPE_EVENT,
+ TraceId: types.SYS_ENTER_PIPE,
+ Time: 100,
+ Pid: 72,
+ Tid: 73,
+ Flags: 0,
+ Fd0: -1,
+ Fd1: -1,
+ Ret: 0,
+ }
+ exit := &types.PipeEvent{
+ EventType: types.EXIT_PIPE_EVENT,
+ TraceId: types.SYS_EXIT_PIPE,
+ Time: 200,
+ Pid: 72,
+ Tid: 73,
+ Flags: 0,
+ Fd0: -1,
+ Fd1: -1,
+ Ret: -1,
+ }
+ ep := &event.Pair{EnterEv: enter, ExitEv: exit}
+
+ if ok := el.handlePipeExit(ep, enter); !ok {
+ t.Fatal("handlePipeExit returned false")
+ }
+ verifyFdNotTracked(t, el, -1)
+ if ep.File != nil {
+ t.Errorf("expected no file attached to failed pipe pair, got %q", ep.File.Name())
+ }
+}
+
func TestHandleEventfdExitTracksReturnedFd(t *testing.T) {
el := mustNewEventLoop(t, eventLoopConfig{})