Skip to content

Commit e7a6994

Browse files
can: dev: __can_get_echo_skb(): Don't crash the kernel if can_priv::echo_skb is accessed out of bounds
If the "struct can_priv::echo_skb" is accessed out of bounds would lead to a kernel crash. Better print a sensible warning message instead and try to recover. Cc: linux-stable <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 200f5c4 commit e7a6994

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/net/can/dev.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
481481
{
482482
struct can_priv *priv = netdev_priv(dev);
483483

484-
BUG_ON(idx >= priv->echo_skb_max);
484+
if (idx >= priv->echo_skb_max) {
485+
netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
486+
__func__, idx, priv->echo_skb_max);
487+
return NULL;
488+
}
485489

486490
if (priv->echo_skb[idx]) {
487491
/* Using "struct canfd_frame::len" for the frame

0 commit comments

Comments
 (0)