summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2018-10-31 14:05:26 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-01 09:44:20 +0100
commit8aa60a6d605d1598fc3a3a36c37d9f568db5b0fc (patch)
tree1f474c1887820790564b624bfa97fbba0040aaa3
parent5adc1c548aa5e684fd312c8a7c822f2f47a04b4e (diff)
can: dev: __can_get_echo_skb(): Don't crash the kernel if can_priv::echo_skb is accessed out of bounds
commit e7a6994d043a1e31d5b17706a22ce33d2a3e4cdc upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/net/can/dev.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index c43078f48b78..214a48703a4e 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -457,7 +457,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