Re: [PATCH net-next 5/5] selftests/xsk: make pkt_stream_even_odd_sequence rollback-safe

[email protected]
Newsgroups org.kernel.vger.netdev,org.kernel.vger.bpf
Message-ID <1a2ae9d8a6c2ddae7f910225c821cbc06838bb7689c39c6606970f03f2c469f4@mail.kernel.org>
> If __pkt_stream_generate() fails midway through building per-socket
> streams, the original code overwrites xsk_arr[i].pkt_stream with a
> partial or NULL pointer before all allocations complete.
>
> Allocate all TX and RX streams into temporary arrays first and only
> assign them to xsk_arr after every allocation succeeds.  On any failure
> free the already-allocated temporaries and return -ENOMEM with no
> xsk_arr pointers modified.

Does the commit message accurately describe the problem being fixed?

The pre-patch code NULL-checked the allocation before assigning it to
xsk_arr[i].pkt_stream:

    pkt_stream = __pkt_stream_generate(pkt_stream->nb_pkts / 2,
                                       pkt_stream->pkts[0].len, i, 2);
    if (!pkt_stream)
            return -ENOMEM;
    test->ifobj_tx->xsk_arr[i].pkt_stream = pkt_stream;

so xsk_arr[i].pkt_stream would never hold a NULL pointer from a failed
allocation. __pkt_stream_generate() either returns a fully initialized
stream or NULL (it frees any partial allocations on failure), so no
"partial" pointer can exist either.

The actual bug appears to be different: when an allocation for socket i
fails, sockets 0..i-1 already have new streams installed in xsk_arr,
and both callers (testapp_xdp_shared_umem() and run_shared_umem_test())
return immediately on error without calling release_even_odd_sequence().
This leaks the already-published streams and leaves xsk_arr with a
half-replaced stream set.


---
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/31554903166
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.