* [PATCH net] nfp: fix use-after-free in nfp_ccm_mbox_skb_return()
@ 2026-11-25 22:16 Elkin Cruz
2026-11-26 22:19 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:16 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Nathan Chancellor
Cc: Simon Horman, Nick Desaulniers, Bill Wendling, Justin Stitt,
oss-drivers, netdev, llvm, linux-kernel, irogers, Elkin Cruz,
stable
nfp_ccm_mbox_skb_return() casts skb->cb to struct nfp_ccm_mbox_cmsg_cb,
frees skb via dev_kfree_skb_any() when cb->err is non-zero, and then
reads cb->err from the freed skb to return it.
Read cb->err into a local variable before freeing skb.
This issue was found while trying out new Clang static analysis checks for
kernel bug classes. The finding was triaged and fixed, and this commit
description was drafted with the help of AI, then verified by code
inspection and compile-tested against linux-next (not reproduced and not
runtime-tested on hardware).
Fixes: d3e4dfe060cc ("nfp: add support for sending control messages via mailbox")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
drivers/net/ethernet/netronome/nfp/ccm_mbox.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/netronome/nfp/ccm_mbox.c b/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
index aa8aba4ff7aa..c0f1d84208a4 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;
}
/* If wait timed out but the command is already in progress we have
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH net] nfp: fix use-after-free in nfp_ccm_mbox_skb_return()
2026-11-25 22:16 [PATCH net] nfp: fix use-after-free in nfp_ccm_mbox_skb_return() Elkin Cruz
@ 2026-11-26 22:19 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 22:19 UTC (permalink / raw)
To: elkin
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, nathan, horms,
ndesaulniers, morbo, justinstitt, oss-drivers, netdev, llvm,
linux-kernel, irogers, stable
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 22:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 22:16 [PATCH net] nfp: fix use-after-free in nfp_ccm_mbox_skb_return() Elkin Cruz
2026-11-26 22:19 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®