BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Josef Bacik" <josef@toxicpanda.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/8] net: skbuff: don't BUG() on leftover length in skb_checksum() and friends
Date: Thu, 08 Oct 2026 17:36:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-164424@kernel.org> (raw)
In-Reply-To: <20261007-b4-skbuff-bug-on-v2-4-b9a5f732895b@toxicpanda.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: UAF and double-free in axienet exposed by skb_to_sgvec error return
- [Low] mt76: memory leak of skb on skb_to_sgvec() error in mt76u_tx_queue_skb()
--

commit c07f21ad9448d85b0e365dbfeb75ae3c3a8b381b
Author: Josef Bacik <josef@toxicpanda.com>

net: skbuff: don't BUG() on leftover length in skb_checksum() and friends

This patch replaces system-halting BUG_ON calls with error returns in
skb_checksum, skb_crc32c, and __skb_to_sgvec when encountering leftover
length. It returns -EINVAL for __skb_to_sgvec and 0 for checksum functions,
allowing the system to recover gracefully.

> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
[ ... ]
> @@ -5339,7 +5345,10 @@ __skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len,
>  		}
>  		start = end;
>  	}
> -	BUG_ON(len);
> +	if (unlikely(len)) {
> +		DEBUG_NET_WARN_ON_ONCE(1);
> +		return -EINVAL;
> +	}

[Severity: High]
By replacing the BUG_ON with an error return, callers are now expected to
cleanly handle the failure, but does this expose an existing memory
corruption path in the axienet driver?

Looking at axienet_start_xmit_dmaengine in
drivers/net/ethernet/xilinx/xilinx_axienet_main.c, the TX ring head is
incremented before calling skb_to_sgvec:

    lp->tx_ring_head++;
    sg_init_table(skbuf_dma->sgl, sg_len);
    ret = skb_to_sgvec(skb, skbuf_dma->sgl, 0, skb->len);
    if (ret < 0)
        goto xmit_error_drop_skb;

On error, it jumps to xmit_error_drop_skb, frees the SKB, but fails to
decrement lp->tx_ring_head or submit the descriptor to the DMA engine:

xmit_error_drop_skb:
    dev_kfree_skb_any(skb);
    return NETDEV_TX_OK;

When subsequent successful transmissions complete, the DMA callback
axienet_dma_tx_cb monotonically increments lp->tx_ring_tail for each
completion. Will it process the abandoned ring slot and double-free the
stale skb pointer?

axienet_dma_tx_cb() {
    ...
    skbuf_dma = axienet_get_tx_desc(lp, lp->tx_ring_tail++);
    ...
    dev_consume_skb_any(skbuf_dma->skb);
}

[Severity: Low]
Does this error return also cause a memory leak in the mt76 driver?

In mt76u_tx_setup_buffers from drivers/net/wireless/mediatek/mt76/usb.c,
the negative error bypasses the zero check:

    urb->num_sgs = skb_to_sgvec(skb, urb->sg, 0, skb->len);
    if (!urb->num_sgs)
        return -ENOMEM;

    return urb->num_sgs;

In mt76u_tx_queue_skb, this negative error is caught and returned upstream:

    err = mt76u_tx_setup_buffers(dev, tx_info.skb, q->entry[idx].urb);
    if (err < 0)
        return err;

However, the caller mt76_tx_process_mcu_queue unlinks the skb before
attempting to queue it:

    __skb_unlink(skb, head);
    spin_unlock(&head->lock);

    sta = wcid_to_sta(wcid);
    spin_lock(&q->lock);
    __mt76_tx_queue_skb(phy, qid, skb, wcid, sta, NULL);

Since mt76u_tx_queue_skb aborts without calling dev_kfree_skb or
ieee80211_tx_status, will the unlinked skb be permanently leaked?

> 	return elt;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007-b4-skbuff-bug-on-v2-0-b9a5f732895b@toxicpanda.com?part=4

  reply	other threads:[~2026-10-08 17:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 17:35 [PATCH net-next v2 0/8] net: skbuff: replace most BUG_ON()s with error returns Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 1/8] net: skbuff: don't BUG() on bad arguments to pskb_expand_head() Josef Bacik
2026-10-07 17:36 ` [PATCH net-next v2 2/8] net: skbuff: don't BUG() on a bad frag_list layout in skb_segment() Josef Bacik
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 3/8] net: skbuff: don't BUG() when skb_copy_bits() fails in copy helpers Josef Bacik
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 4/8] net: skbuff: don't BUG() on leftover length in skb_checksum() and friends Josef Bacik
2026-10-08 17:36   ` sashiko-bot [this message]
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 5/8] net: skbuff: don't BUG() on a bad csum_start in skb_copy_and_csum_dev() Josef Bacik
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 6/8] net: skbuff: don't BUG() on leftover length in skb_copy_and_csum_bits() Josef Bacik
2026-10-08 17:36   ` sashiko-bot
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 7/8] net: skbuff: don't BUG() on a missing head_frag in skb_zerocopy() Josef Bacik
2026-10-11 17:00   ` netdev-bot+sashiko
2026-10-07 17:36 ` [PATCH net-next v2 8/8] net: skbuff: remove the BUG_ON()s from skb_shift() Josef Bacik

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=sashiko-outbox-164424@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=josef@toxicpanda.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