mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/2] can: dev: can_put_echo_skb(): use dev_kfree_skb_any()
       [not found] <20260731-master-v2-0-204d772f2e36@qq.com>
@ 2026-07-31  8:23 ` Cunhao Lu
  2026-07-31  8:23 ` [PATCH v2 2/2] can: dev: can_put_echo_skb(): free skb on invalid echo index Cunhao Lu
  1 sibling, 0 replies; 2+ messages in thread
From: Cunhao Lu @ 2026-07-31  8:23 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can, linux-kernel, Cunhao Lu

can_put_echo_skb() is a public helper used by CAN drivers, so its callers
do not have a guaranteed IRQ context.  kfree_skb() cannot be called from
hardware interrupt context or with hardware interrupts disabled.

Use dev_kfree_skb_any() for the existing skb drop paths so that they are
safe regardless of the caller's IRQ context.

Signed-off-by: Cunhao Lu <1579567540@qq.com>
---
 drivers/net/can/dev/skb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c
index 95fcdc1026f8..d7b5a5d17ff2 100644
--- a/drivers/net/can/dev/skb.c
+++ b/drivers/net/can/dev/skb.c
@@ -62,7 +62,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
 	    (skb->protocol != htons(ETH_P_CAN) &&
 	     skb->protocol != htons(ETH_P_CANFD) &&
 	     skb->protocol != htons(ETH_P_CANXL))) {
-		kfree_skb(skb);
+		dev_kfree_skb_any(skb);
 		return 0;
 	}
 
@@ -90,7 +90,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
 	} else {
 		/* locking problem with netif_stop_queue() ?? */
 		netdev_err(dev, "%s: BUG! echo_skb %d is occupied!\n", __func__, idx);
-		kfree_skb(skb);
+		dev_kfree_skb_any(skb);
 		return -EBUSY;
 	}
 

-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] can: dev: can_put_echo_skb(): free skb on invalid echo index
       [not found] <20260731-master-v2-0-204d772f2e36@qq.com>
  2026-07-31  8:23 ` [PATCH v2 1/2] can: dev: can_put_echo_skb(): use dev_kfree_skb_any() Cunhao Lu
@ 2026-07-31  8:23 ` Cunhao Lu
  1 sibling, 0 replies; 2+ messages in thread
From: Cunhao Lu @ 2026-07-31  8:23 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol
  Cc: linux-can, linux-kernel, Cunhao Lu, stable

can_put_echo_skb() consumes the skb on all paths except when the echo index
is out of bounds. This leaves ownership with the caller on -EINVAL, unlike
the other error paths, and can leak the skb if the caller expects
consistent semantics.

Free the skb before returning -EINVAL so that all return paths consume it.

Fixes: 6411959c10fe ("can: dev: can_put_echo_skb(): don't crash kernel if can_priv::echo_skb is accessed out of bounds")
Cc: stable@vger.kernel.org
Reviewed-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Cunhao Lu <1579567540@qq.com>
---
Changes in v2:
- Free the skb with dev_kfree_skb_any() on an invalid echo index.
- Collect Vincent's Reviewed-by tag
---
 drivers/net/can/dev/skb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c
index d7b5a5d17ff2..c996cc2b417b 100644
--- a/drivers/net/can/dev/skb.c
+++ b/drivers/net/can/dev/skb.c
@@ -54,6 +54,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
 	if (idx >= priv->echo_skb_max) {
 		netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
 			   __func__, idx, priv->echo_skb_max);
+		dev_kfree_skb_any(skb);
 		return -EINVAL;
 	}
 

-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-31  8:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260731-master-v2-0-204d772f2e36@qq.com>
2026-07-31  8:23 ` [PATCH v2 1/2] can: dev: can_put_echo_skb(): use dev_kfree_skb_any() Cunhao Lu
2026-07-31  8:23 ` [PATCH v2 2/2] can: dev: can_put_echo_skb(): free skb on invalid echo index Cunhao Lu

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®