> diff --git a/tools/testing/selftests/bpf/prog_tests/stream.c 
> b/tools/testing/selftests/bpf/prog_tests/stream.c
> index e4e9374309e2..9a21f055d80a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/stream.c
> +++ b/tools/testing/selftests/bpf/prog_tests/stream.c

[ ... ]

> +void test_stream_partial_read(void)
> +{
> +     LIBBPF_OPTS(bpf_test_run_opts, opts);
> +     struct stream *skel;
> +     int ret, prog_fd;
> +     long page_size;
> +     char *page, *buf;
> +     char rest[8] = {};
> +
> +     skel = stream__open_and_load();
> +     if (!ASSERT_OK_PTR(skel, "stream__open_and_load"))
> +             return;
> +
> +     prog_fd = bpf_program__fd(skel->progs.stream_syscall);
> +     ret = bpf_prog_test_run_opts(prog_fd, &opts);
> +     ASSERT_OK(ret, "ret");
> +     ASSERT_OK(opts.retval, "retval");
> +
> +     page_size = sysconf(_SC_PAGESIZE);
> +     page = mmap(NULL, page_size * 2, PROT_READ | PROT_WRITE,
> +                 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +     if (!ASSERT_NEQ(page, MAP_FAILED, "mmap")) {
> +             stream__destroy(skel);
> +             return;
> +     }
> +     /* Leave only the first page mapped so a straddling copy faults. */
> +     ASSERT_OK(munmap(page + page_size, page_size), "munmap second page");
                     ^^^^

Should this munmap() be gated like the other setup steps?  The mmap() above
returns early on failure, but this munmap() just records the result and
continues.

If the unmap fails, page + page_size stays mapped, copy_to_user() in
bpf_stream_read() no longer faults, and the first bpf_prog_stream_read()
returns 3 instead of 1.  The test then reports confusing failures
('partial bytes: actual 3 != expected 1' and 'remaining bytes: actual 0
!= expected 2') that point away from the real cause.

Also, the trailing cleanup only unmaps the first page:

> +     munmap(page, page_size);
> +     stream__destroy(skel);
> +}

so the still-mapped second page would be leaked for the remainder of the
test-runner process.  Would gating it the same way as the surrounding
checks work here?

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32645868670

Reply via email to