* [PATCH v3 1/3] can: skb: make echo skb freeing safe in any IRQ context
[not found] <20260731-master-v3-0-b56cd1e8d675@qq.com>
@ 2026-07-31 9:45 ` Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 2/3] can: skb: make CAN skb allocation failure paths IRQ-safe Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 3/3] can: dev: can_put_echo_skb(): free skb on invalid echo index Cunhao Lu
2 siblings, 0 replies; 3+ messages in thread
From: Cunhao Lu @ 2026-07-31 9:45 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol; +Cc: linux-can, linux-kernel, Cunhao Lu
can_put_echo_skb() can be called with hardware interrupts disabled. Its
direct drop paths use kfree_skb(), while can_create_echo_skb() uses
kfree_skb() when cloning fails and consume_skb() after a successful clone.
None of these helpers is safe in every IRQ context.
Use dev_kfree_skb_any() for all drop paths and dev_consume_skb_any() when
consuming a successfully cloned skb. This preserves the respective skb drop
and consumed semantics regardless of the caller IRQ context.
Signed-off-by: Cunhao Lu <1579567540@qq.com>
---
Changes in v3:
- Cover can_create_echo_skb() clone failure and successful-clone consume
paths with IRQ-context-independent helpers.
---
drivers/net/can/dev/skb.c | 4 ++--
include/linux/can/skb.h | 4 ++--
2 files changed, 4 insertions(+), 4 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;
}
diff --git a/include/linux/can/skb.h b/include/linux/can/skb.h
index a70a02967071..78c5870e2f9a 100644
--- a/include/linux/can/skb.h
+++ b/include/linux/can/skb.h
@@ -76,12 +76,12 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb)
nskb = skb_clone(skb, GFP_ATOMIC);
if (unlikely(!nskb)) {
- kfree_skb(skb);
+ dev_kfree_skb_any(skb);
return NULL;
}
can_skb_set_owner(nskb, skb->sk);
- consume_skb(skb);
+ dev_consume_skb_any(skb);
return nskb;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/3] can: skb: make CAN skb allocation failure paths IRQ-safe
[not found] <20260731-master-v3-0-b56cd1e8d675@qq.com>
2026-07-31 9:45 ` [PATCH v3 1/3] can: skb: make echo skb freeing safe in any IRQ context Cunhao Lu
@ 2026-07-31 9:45 ` Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 3/3] can: dev: can_put_echo_skb(): free skb on invalid echo index Cunhao Lu
2 siblings, 0 replies; 3+ messages in thread
From: Cunhao Lu @ 2026-07-31 9:45 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol
Cc: linux-can, linux-kernel, Cunhao Lu, stable
The CAN skb allocation helpers are used from hardware interrupt receive
handlers. If can_skb_ext_add() fails, they release the newly allocated skb
with kfree_skb(), which is not safe in hardware interrupt context.
Use dev_kfree_skb_any() for the allocation failure paths in
alloc_can_skb(), alloc_canfd_skb(), and alloc_canxl_skb().
Fixes: 96ea3a1e2d31 ("can: add CAN skb extension infrastructure")
Cc: stable@vger.kernel.org
Signed-off-by: Cunhao Lu <1579567540@qq.com>
---
drivers/net/can/dev/skb.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c
index d7b5a5d17ff2..d34d3e7d4c9f 100644
--- a/drivers/net/can/dev/skb.c
+++ b/drivers/net/can/dev/skb.c
@@ -223,7 +223,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
csx = can_skb_ext_add(skb);
if (!csx) {
- kfree_skb(skb);
+ dev_kfree_skb_any(skb);
goto out_error_cc;
}
@@ -254,7 +254,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,
csx = can_skb_ext_add(skb);
if (!csx) {
- kfree_skb(skb);
+ dev_kfree_skb_any(skb);
goto out_error_fd;
}
@@ -292,7 +292,7 @@ struct sk_buff *alloc_canxl_skb(struct net_device *dev,
csx = can_skb_ext_add(skb);
if (!csx) {
- kfree_skb(skb);
+ dev_kfree_skb_any(skb);
goto out_error_xl;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 3/3] can: dev: can_put_echo_skb(): free skb on invalid echo index
[not found] <20260731-master-v3-0-b56cd1e8d675@qq.com>
2026-07-31 9:45 ` [PATCH v3 1/3] can: skb: make echo skb freeing safe in any IRQ context Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 2/3] can: skb: make CAN skb allocation failure paths IRQ-safe Cunhao Lu
@ 2026-07-31 9:45 ` Cunhao Lu
2 siblings, 0 replies; 3+ messages in thread
From: Cunhao Lu @ 2026-07-31 9:45 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 d34d3e7d4c9f..e985616c062c 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 related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-31 9:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260731-master-v3-0-b56cd1e8d675@qq.com>
2026-07-31 9:45 ` [PATCH v3 1/3] can: skb: make echo skb freeing safe in any IRQ context Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 2/3] can: skb: make CAN skb allocation failure paths IRQ-safe Cunhao Lu
2026-07-31 9:45 ` [PATCH v3 3/3] can: dev: can_put_echo_skb(): free skb on invalid echo index Cunhao Lu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.