diff mbox

[net-2.6] can: Use WARN_ONCE() instead of BUG_ON() for sanity check in receive path

Message ID 4A80040D.3030009@hartkopp.net
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Oliver Hartkopp Aug. 10, 2009, 11:27 a.m. UTC
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).

Additionally it changes the return values to the common NET_RX_xxx constants.

Signed-off-by: Oliver Hartkopp <oliver@hartkopp.net>
Signed-off-by: Urs Thuermann <urs@isnogud.escape.de>
CC: Michael Olbrich <m.olbrich@pengutronix.de>
CC: Luotao Fu <l.fu@pengutronix.de>

---

Comments

David Miller Aug. 13, 2009, 5:01 a.m. UTC | #1
From: Oliver Hartkopp <oliver@hartkopp.net>
Date: Mon, 10 Aug 2009 13:27:09 +0200

> Additionally it changes the return values to the common NET_RX_xxx constants.

Don't munge unrelated changes together like this, split it up.

Also, this is not net-2.6 material, I will only apply these changes
to net-next-2.6 at this point.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oliver Hartkopp Aug. 14, 2009, 5:57 a.m. UTC | #2
David Miller wrote:
> From: Oliver Hartkopp <oliver@hartkopp.net>
> Date: Mon, 10 Aug 2009 13:27:09 +0200
> 
>> Additionally it changes the return values to the common NET_RX_xxx constants.
> 
> Don't munge unrelated changes together like this, split it up.
> 
> Also, this is not net-2.6 material, I will only apply these changes
> to net-next-2.6 at this point.

No problem.

Btw. this patch was removed from patchwork and i was not able to find it in
your latest net-next-2.6 push this morning.

Best regards,
Oliver

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Aug. 14, 2009, 7:13 a.m. UTC | #3
From: Oliver Hartkopp <oliver@hartkopp.net>
Date: Fri, 14 Aug 2009 07:57:02 +0200

> David Miller wrote:
>> From: Oliver Hartkopp <oliver@hartkopp.net>
>> Date: Mon, 10 Aug 2009 13:27:09 +0200
>> 
>>> Additionally it changes the return values to the common NET_RX_xxx constants.
>> 
>> Don't munge unrelated changes together like this, split it up.
>> 
>> Also, this is not net-2.6 material, I will only apply these changes
>> to net-next-2.6 at this point.
> 
> No problem.
> 
> Btw. this patch was removed from patchwork and i was not able to find it in
> your latest net-next-2.6 push this morning.

It's not in net-next-2.6 because I didn't apply it, which is pretty
clealy implied when I'm asking you to split the change up into
multiple patches.

When I ask for changes, I mark the patch in patchwork with the
"changes requested" state and expect you to send me new updated stuff.

You can look for patches in various "done" states by simply modifying
the "Filters" setting in the patch list.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oliver Hartkopp Aug. 14, 2009, 8:11 a.m. UTC | #4
David Miller wrote:
> From: Oliver Hartkopp <oliver@hartkopp.net>
> Date: Fri, 14 Aug 2009 07:57:02 +0200
> 
>> David Miller wrote:
>>> From: Oliver Hartkopp <oliver@hartkopp.net>
>>> Date: Mon, 10 Aug 2009 13:27:09 +0200
>>>
>>>> Additionally it changes the return values to the common NET_RX_xxx constants.
>>> Don't munge unrelated changes together like this, split it up.
>>>
>>> Also, this is not net-2.6 material, I will only apply these changes
>>> to net-next-2.6 at this point.
>> No problem.
>>
>> Btw. this patch was removed from patchwork and i was not able to find it in
>> your latest net-next-2.6 push this morning.
> 
> It's not in net-next-2.6 because I didn't apply it, which is pretty
> clealy implied when I'm asking you to split the change up into
> multiple patches.

Sorry - i assumed this to be a hint for the next time. My fault.

> 
> When I ask for changes, I mark the patch in patchwork with the
> "changes requested" state and expect you to send me new updated stuff.
> 
> You can look for patches in various "done" states by simply modifying
> the "Filters" setting in the patch list.

Ah! I only had the filters on 'action required' and therefore is was not able
to see what happened after the patches were removed from the 'action required'
view ...

I'll re-send two separate patches for net-next-2.6 .

Thanks,
Oliver
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/can/af_can.c b/net/can/af_can.c
index e733725..ef1c43a 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -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;
 	int matches;
 
-	if (dev->type != ARPHRD_CAN || !net_eq(dev_net(dev), &init_net)) {
-		kfree_skb(skb);
-		return 0;
-	}
+	if (!net_eq(dev_net(dev), &init_net))
+		goto drop;
 
-	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 */
 	can_stats.rx_frames++;
@@ -682,7 +686,11 @@  static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 		can_stats.matches_delta++;
 	}
 
-	return 0;
+	return NET_RX_SUCCESS;
+
+drop:
+	kfree_skb(skb);
+	return NET_RX_DROP;
 }
 
 /*