Re: [PATCH net] nfp: fix use-after-free in nfp_ccm_mbox_skb_return()

From: netdev-bot+sashiko

Date: Thu Nov 26 2026 - 17:19:48 EST


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

Critical: 1 · High: 0 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Critical] The patch is incomplete.

--

nfp: fix use-after-free in nfp_ccm_mbox_skb_return()

This commit changes nfp_ccm_mbox_skb_return() to save cb->err in a local
variable before the skb is freed. Before the change, cb->err was read
from skb->cb after dev_kfree_skb_any() had already run.

> diff --git a/drivers/net/ethernet/netronome/nfp/ccm_mbox.c b/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
> index aa8aba4ff7aac..c0f1d84208a41 100644
> --- a/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
> +++ b/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
> @@ -420,10 +420,11 @@ static void nfp_ccm_mbox_run_queue_unlock(struct nfp_net *nn)
> static int nfp_ccm_mbox_skb_return(struct sk_buff *skb)
> {
> struct nfp_ccm_mbox_cmsg_cb *cb = (void *)skb->cb;
> + int err = cb->err;
>
> - if (cb->err)
> + if (err)
> dev_kfree_skb_any(skb);
> - return cb->err;
> + return err;
> }

[Severity: Critical]
Is this fix complete? This change makes a non-zero return from
nfp_ccm_mbox_skb_return() mean the skb has already been freed. One
caller still frees the skb again after that return.

The in-progress branch of nfp_ccm_mbox_unlink_unlock() passes the
helper's result straight back:

drivers/net/ethernet/netronome/nfp/ccm_mbox.c:nfp_ccm_mbox_unlink_unlock() {
...
if (nfp_ccm_mbox_in_progress(skb)) {
spin_unlock_bh(&nn->mbox_cmsg.queue.lock);

wait_event(nn->mbox_cmsg.wq, nfp_ccm_mbox_done(skb));
smp_rmb(); /* pairs with smp_wmb() after data is written */
return nfp_ccm_mbox_skb_return(skb);
}
...
return -ETIMEDOUT;
}

__nfp_ccm_mbox_communicate() treats every non-zero return as "the caller
still owns the skb":

drivers/net/ethernet/netronome/nfp/ccm_mbox.c:__nfp_ccm_mbox_communicate() {
...
err = nfp_ccm_mbox_unlink_unlock(nn, skb, type);
if (err)
goto err_free_skb;
return 0;
...
err_free_skb:
dev_kfree_skb_any(skb);
return err;
}

Only the -ETIMEDOUT branch, which unlinks the skb without freeing it,
matches what the caller expects.

Here is one sequence that seems to reach the double free:

1. A thread that is not first in the queue waits in
wait_event_timeout() with NFP_CCM_TIMEOUT.

2. Another thread's nfp_ccm_mbox_run_queue_unlock() adds that skb to
its batch and marks it busy with nfp_ccm_mbox_set_busy().

3. The waiter times out before the skb is done. It is still not first,
so it calls nfp_ccm_mbox_unlink_unlock(). nfp_ccm_mbox_in_progress()
is true, so it waits for done.

4. The batch fails in one of two ways:

- nfp_net_mbox_reconfig() fails and nfp_ccm_mbox_mark_all_err() sets
-EIO.
- nfp_ccm_mbox_copy_out() sets cb->err to -EIO or -ENOENT.

5. nfp_ccm_mbox_skb_return() frees the skb and returns the error.

6. __nfp_ccm_mbox_communicate() jumps to err_free_skb and calls
dev_kfree_skb_any() on the same skb a second time.

The commit message says this fixes the free-then-use of the skb around
nfp_ccm_mbox_skb_return(), but that path is still reachable here.

Should the skb be freed in exactly one place? Either the in-progress
branch could leave the skb alone, or the caller could return the error
directly instead of going to err_free_skb.

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125221658.1420387-1-elkin%40google.com