All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maciej Fijalkowski" <maciej.fijalkowski@intel.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 net 3/6] xsk: provide sufficient space in pool->tx_descs
Date: Mon, 20 Jul 2026 13:58:20 +0000	[thread overview]
Message-ID: <20260720135820.EE7AD1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260719135609.147823-4-maciej.fijalkowski@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Heap Buffer Overflow in batched Tx descriptor API when a shared XDP socket has a larger Tx ring.
--

--- Patch [3]: [PATCH v4 net 3/6] xsk: provide sufficient space in pool->tx_descs ---
commit 16fadec5330bdab35c81e060269bbbba543bb7cd
Author: Maciej Fijalkowski <maciej.fijalkowski@intel.com>

xsk: provide sufficient space in pool->tx_descs

The temporary Tx descriptor array in an XSK buffer pool is sized from the Tx
ring of the socket that creates the pool. This commit sizes the temporary
descriptor array to the larger of the first Tx ring and the device's
xdp_zc_max_segs capability to prevent stalls in batch parsing for shared-UMEM.

> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 12a845d012f6f..091792d1d82de 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
[ ... ]
> @@ -1557,7 +1558,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr_unsized *addr, int addr
>  			 * utilizes
>  			 */
>  			if (xs->tx && !xs->pool->tx_descs) {
> -				err = xp_alloc_tx_descs(xs->pool, xs);
> +				err = xp_alloc_tx_descs(xs->pool, xs,
> +							dev->xdp_zc_max_segs);

[Severity: Critical]
This is a pre-existing issue, but does this logic leave the system vulnerable
to a heap buffer overflow?

When a primary socket is configured with a small Tx ring, pool->tx_descs is
allocated with a small capacity. If a secondary shared-UMEM socket is then
bound with a much larger Tx ring, this check skips reallocating or resizing
pool->tx_descs.

Later, during batch reading, xsk_tx_peek_release_desc_batch() can overflow
this array:

net/xdp/xsk.c:xsk_tx_peek_release_desc_batch()
    ...
    nb_pkts = xskq_cons_read_desc_batch(xs->tx, pool, nb_pkts);
    ...

Since nb_pkts is not clamped to pool->tx_descs_nentries, the batch size
can exceed the allocated capacity. This leads to an out-of-bounds write
when xskq_cons_read_desc_batch() copies descriptors:

net/xdp/xsk_queue.h:xskq_cons_read_desc_batch()
    ...
    descs[nb_entries] = ring->desc[idx];
    ...

The same out-of-bounds write can occur in the fallback path:

net/xdp/xsk.c:xsk_tx_peek_release_fallback()
    ...
    while (nb_pkts < max_entries && xsk_tx_peek_desc(pool, &descs[nb_pkts]))
        nb_pkts++;
    ...

Since max_entries isn't clamped to the actual allocated capacity, couldn't
this corrupt adjacent kernel memory?

>  				if (err) {
>  					xp_put_pool(xs->pool);
>  					xs->pool = NULL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260719135609.147823-1-maciej.fijalkowski@intel.com?part=3

  reply	other threads:[~2026-07-20 13:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-19 13:56 [PATCH v4 net 0/6] xsk: fix AF_XDP multi-buffer Tx descriptor reclaim Maciej Fijalkowski
2026-07-19 13:56 ` [PATCH v4 net 1/6] xsk: fix buffer leak in xsk_drop_skb() for AF_XDP multi-buffer Tx Maciej Fijalkowski
2026-07-19 13:56 ` [PATCH v4 net 2/6] xsk: drain continuation descs after overflow in xsk_build_skb() Maciej Fijalkowski
2026-07-20 13:58   ` sashiko-bot
2026-07-21 18:04   ` Maciej Fijalkowski
2026-07-19 13:56 ` [PATCH v4 net 3/6] xsk: provide sufficient space in pool->tx_descs Maciej Fijalkowski
2026-07-20 13:58   ` sashiko-bot [this message]
2026-07-19 13:56 ` [PATCH v4 net 4/6] xsk: reclaim invalid Tx descriptors in ZC batch path Maciej Fijalkowski
2026-07-19 13:56 ` [PATCH v4 net 5/6] selftests/xsk: fix too-many-frags multi-buffer Tx test Maciej Fijalkowski
2026-07-19 13:56 ` [PATCH v4 net 6/6] selftests/xsk: account reclaimed invalid Tx descriptors Maciej Fijalkowski
2026-07-20 19:30 ` [PATCH v4 net 0/6] xsk: fix AF_XDP multi-buffer Tx descriptor reclaim Stanislav Fomichev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260720135820.EE7AD1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.