Skip to content

Commit

Permalink
can: dev: can_free_echo_skb(): don't crash the kernel if can_priv::ec…
Browse files Browse the repository at this point in the history
…ho_skb is accessed out of bounds

A out of bounds access to "struct can_priv::echo_skb" leads to a
kernel crash. Better print a sensible warning message instead and try
to recover.

This patch is similar to:

| e7a6994 ("can: dev: __can_get_echo_skb(): Don't crash the kernel
|               if can_priv::echo_skb is accessed out of bounds")

Link: https://lore.kernel.org/r/20210319142700.305648-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Mar 30, 2021
1 parent 7119d78 commit 4168d07
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/net/can/dev/skb.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx)
{
struct can_priv *priv = netdev_priv(dev);

BUG_ON(idx >= priv->echo_skb_max);
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);
return;
}

if (priv->echo_skb[idx]) {
dev_kfree_skb_any(priv->echo_skb[idx]);
Expand Down

0 comments on commit 4168d07

Please sign in to comment.