Skip to content

Commit

Permalink
can: dev: __can_get_echo_skb(): Don't crash the kernel if can_priv::e…
Browse files Browse the repository at this point in the history
…cho_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 <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
marckleinebudde committed Nov 9, 2018
1 parent 200f5c4 commit e7a6994
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/net/can/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8
{
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 NULL;
}

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

0 comments on commit e7a6994

Please sign in to comment.