Commit 1758c094 authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by David S. Miller

can: Use WARN_ONCE() instead of BUG_ON() for sanity check in receive path

To ensure a proper handling of CAN frames transported in skbuffs some checks
need to be performed at receive time.

As stated by Michael Olbrich and Luotao Fu BUG_ON() might be to restrictive.
This is right as we can just drop the non conform skbuff and the Kernel can
continue working.

This patch replaces the BUG_ON() with a WARN_ONCE() so that the system remains
healthy but we made the problem visible (once).
Signed-off-by: default avatarOliver Hartkopp <oliver@hartkopp.net>
Signed-off-by: default avatarUrs Thuermann <urs@isnogud.escape.de>
CC: Michael Olbrich <m.olbrich@pengutronix.de>
CC: Luotao Fu <l.fu@pengutronix.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 49d4b8ba
...@@ -651,12 +651,16 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -651,12 +651,16 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
struct can_frame *cf = (struct can_frame *)skb->data; struct can_frame *cf = (struct can_frame *)skb->data;
int matches; int matches;
if (dev->type != ARPHRD_CAN || !net_eq(dev_net(dev), &init_net)) { if (!net_eq(dev_net(dev), &init_net))
kfree_skb(skb); goto drop;
return 0;
}
BUG_ON(skb->len != sizeof(struct can_frame) || cf->can_dlc > 8); if (WARN_ONCE(dev->type != ARPHRD_CAN ||
skb->len != sizeof(struct can_frame) ||
cf->can_dlc > 8,
"PF_CAN: dropped non conform skbuf: "
"dev type %d, len %d, can_dlc %d\n",
dev->type, skb->len, cf->can_dlc))
goto drop;
/* update statistics */ /* update statistics */
can_stats.rx_frames++; can_stats.rx_frames++;
...@@ -683,6 +687,10 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -683,6 +687,10 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
} }
return 0; return 0;
drop:
kfree_skb(skb);
return 0;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment