BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Joshua Washington" <joshwash@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 3/6] gve: fix XSK buffer leak on error descriptor
Date: Sat, 15 Aug 2026 23:49:27 +0000	[thread overview]
Message-ID: <20260815234927.C21A11F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260814234845.773189-4-joshwash@google.com>

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

Pre-existing issues:
- [Critical] Fragment desynchronization resulting in truncated or malformed packets being incorrectly pushed to the network stack upon intermediate descriptor errors.
- [High] Massive unmitigated leak of AF_XDP zero-copy buffers (`xsk_buff`) and XDP frames (`xdpf`) on XDP_TX and XDP_REDIRECT paths.
- [High] `gve_rx_xsk_dqo` unconditionally overwrites `rx->ctx.skb_head` on multi-fragment XDP sequences, causing leaks.
- [High] The driver inherently trusts the `packet_len` provided by the device DMA completion descriptor without verifying it against the allocated buffer size.
- [High] Missing bounds check on `compl_desc->header_len` allows out-of-bounds reads from the header buffer array.
--

--- Patch [3]: [PATCH net 3/6] gve: fix XSK buffer leak on error descriptor ---
commit 92aa7b2aab7b9d9aa0aed8717f991d9e6e5c13b2
Author: Joshua Washington <joshwash@google.com>

gve: fix XSK buffer leak on error descriptor

When the error bit is set in the RX completion descriptor, the buf_state
and its attached buffer should be freed. In the case of AF_XDP ZC, the
XSK buffer was not freed, leading to a leak.

Fixes: c1fffc5d66a7 ("gve: implement DQO RX datapath and control path for AF_XDP zero-copy")
Cc: stable@vger.kernel.org

> diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
> index 2c1ce23d15508..811db42d05c67 100644
> --- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c
> +++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
> @@ -845,7 +845,12 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
>  	}
>  
>  	if (unlikely(compl_desc->rx_error)) {
> -		gve_free_buffer(rx, buf_state);
> +		if (buf_state->xsk_buff) {
> +			xsk_buff_free(buf_state->xsk_buff);
> +			gve_free_buf_state(rx, buf_state);
> +		} else {
> +			gve_free_buffer(rx, buf_state);
> +		}
>  		return -EINVAL;
>  	}

[Severity: High]
This is a pre-existing issue, but does the driver verify the length fields
provided by the device DMA completion descriptor?

In gve_rx_dqo(), the driver reads packet_len and header_len directly from
the untrusted descriptor:

        buf_len = compl_desc->packet_len;
        hdr_len = compl_desc->header_len;

It then uses hdr_len to copy data:

        rx->ctx.skb_head =
                gve_rx_copy_data(priv->dev, napi,
                                 rx->dqo.hdr_bufs.data + offset,
                                 hdr_len);

Could a buggy or malicious device supply a large header length (up to 1023
bytes), causing out-of-bounds memory reads from the header buffer array?
Similarly, could an unchecked packet_len result in out-of-bounds memory
reads being copied into SKBs and pushed to the network stack?

[Severity: High]
This isn't a bug introduced by this patch, but are there other paths where
AF_XDP zero-copy buffers or XDP frames can leak?

In drivers/net/ethernet/google/gve/gve_rx_dqo.c:gve_xsk_done_dqo(), the
XDP_REDIRECT failure path appears to fall through without freeing the
original xsk_buff:

        case XDP_REDIRECT:
                if (unlikely(xdp_do_redirect(priv->dev, xdp, xprog)))
                        goto err;

Also, in drivers/net/ethernet/google/gve/gve_tx_dqo.c:gve_xdp_xmit_one_dqo(),
the error path nullifies the packet frame without calling xdp_return_frame():

err:
        pkt->xdpf = NULL;
        pkt->num_bufs = 0;
        gve_free_pending_packet(tx, pkt);
        return err;

Does this lead to resource exhaustion if XDP_TX or XDP_REDIRECT actions fail?

[Severity: Critical]
This is a pre-existing issue, but does the RX poll loop correctly track
dropped packets across multiple descriptors?

In gve_rx_poll_dqo(), an error causes the skb to be freed:

        if (err < 0) {
                gve_rx_free_skb(napi, rx);

However, if this was the first or intermediate descriptor of a multi-fragment
packet, there doesn't seem to be a flag (like rx->ctx.drop_pkt) to ignore
the remaining descriptors. As a result, when the next fragment is processed in
gve_rx_dqo(), a new skb is allocated:

        rx->ctx.skb_head = napi_get_frags(napi);

Could this fragment desynchronization allow subsequent fragments of the same
packet to be parsed as the start of an entirely new packet?

[Severity: High]
This isn't a bug introduced by this patch, but does gve_rx_xsk_dqo() leak
skbs on multi-fragment XDP sequences?

If a multi-fragment packet arrives while AF_XDP zero-copy is active,
gve_rx_xsk_dqo() unconditionally overwrites rx->ctx.skb_head:

        /* Copy the data to skb */
        rx->ctx.skb_head = gve_rx_copy_data(priv->dev, napi,
                                            xdp->data, buf_len);

Could this unconditionally overwrite the globally stored skb_head and
skb_tail without appending to or freeing the existing partial SKB,
causing a permanent leak of SKBs allocated for prior fragments?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260814234845.773189-1-joshwash@google.com?part=3

  reply	other threads:[~2026-08-15 23:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 23:48 [PATCH net 0/6] gve: various XDP fixes Joshua Washington
2026-08-14 23:48 ` [PATCH net 1/6] gve: increment work_done for XDP and error packets Joshua Washington
2026-08-15 23:49   ` sashiko-bot
2026-08-14 23:48 ` [PATCH net 2/6] gve: fix XSK buffer leak when rings are stopped Joshua Washington
2026-08-15 23:49   ` sashiko-bot
2026-08-14 23:48 ` [PATCH net 3/6] gve: fix XSK buffer leak on error descriptor Joshua Washington
2026-08-15 23:49   ` sashiko-bot [this message]
2026-08-14 23:48 ` [PATCH net 4/6] gve: don't register xsk pool on pre-existing queues in RDA mode Joshua Washington
2026-08-15 23:49   ` sashiko-bot
2026-08-14 23:48 ` [PATCH net 5/6] gve: fix napi_disable deadlock when attempting to disable XSK pools Joshua Washington
2026-08-15 23:49   ` sashiko-bot
2026-08-14 23:48 ` [PATCH net 6/6] gve: fix NULL dereference from premature XSK pool DMA unmap Joshua Washington
2026-08-15 23:49   ` sashiko-bot

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=20260815234927.C21A11F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=joshwash@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox