[PATCH net v2 1/2] nfp: fix double-free on timeout in __nfp_ccm_mbox_communicate()

From: Elkin Cruz

Date: Fri Dec 04 2026 - 13:21:39 EST


When wait_event_timeout() expires in __nfp_ccm_mbox_communicate() and
the message is not first in the queue, nfp_ccm_mbox_unlink_unlock() is
called to handle timeout cleanup. If another runner has already picked
up skb (nfp_ccm_mbox_in_progress(skb) is true), it waits for completion
and calls nfp_ccm_mbox_skb_return(skb), which frees skb when cb->err is
non-zero.

__nfp_ccm_mbox_communicate() then checks the returned error and jumps to
err_free_skb, freeing skb a second time.

Give nfp_ccm_mbox_unlink_unlock() the same ownership contract as
nfp_ccm_mbox_skb_return() (free skb on any error, keep it on success) by
freeing skb before returning -ETIMEDOUT, and return its result directly
from __nfp_ccm_mbox_communicate().

This issue was flagged during the netdev Sashiko AI review of v1 of this
series. 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@xxxxxxxxxxxxxxx
Signed-off-by: Elkin Cruz <elkin@xxxxxxxxxx>
---
drivers/net/ethernet/netronome/nfp/ccm_mbox.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/ccm_mbox.c b/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
index aa8aba4ff7aa..86d2569ff176 100644
--- a/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
+++ b/drivers/net/ethernet/netronome/nfp/ccm_mbox.c
@@ -457,6 +457,7 @@ nfp_ccm_mbox_unlink_unlock(struct nfp_net *nn, struct sk_buff *skb,

nn_dp_warn(&nn->dp, "time out waiting for mbox response to 0x%02x\n",
type);
+ dev_kfree_skb_any(skb);
return -ETIMEDOUT;
}

@@ -576,10 +577,7 @@ int __nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb,
if (!nfp_ccm_mbox_is_first(nn, skb)) {
WARN_ON(!to);

- err = nfp_ccm_mbox_unlink_unlock(nn, skb, type);
- if (err)
- goto err_free_skb;
- return 0;
+ return nfp_ccm_mbox_unlink_unlock(nn, skb, type);
}
}

--
2.56.1.987.g2ec0ab4260-goog