From patchwork Fri Aug 14 08:54:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 31381 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id BFA09B6F34 for ; Fri, 14 Aug 2009 18:54:47 +1000 (EST) Received: by ozlabs.org (Postfix) id ACD81DDD04; Fri, 14 Aug 2009 18:54:47 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 23981DDD01 for ; Fri, 14 Aug 2009 18:54:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbZHNIyg (ORCPT ); Fri, 14 Aug 2009 04:54:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752586AbZHNIyg (ORCPT ); Fri, 14 Aug 2009 04:54:36 -0400 Received: from mo-p00-ob.rzone.de ([81.169.146.160]:28585 "EHLO mo-p00-ob.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752323AbZHNIyf (ORCPT ); Fri, 14 Aug 2009 04:54:35 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1250240075; l=2037; s=domk; d=hartkopp.net; h=Content-Type:Subject:CC:To:MIME-Version:From:Date:X-RZG-CLASS-ID: X-RZG-AUTH; bh=jfTTxSqZTKWqduDHyr875hb2XzE=; b=MCNdLwD6YoeoXg/9KVhX4w/mGmt9AN6VKSxM/aPKZ58z/nZwhXZxZfA0VXtv2vMHu6I ZMoLUU4qeVn6NJtIc+KqswBrzAye9QR1AivacwMW+/CyMjhw/UCKeTR5hd091BaGynqy7 CVs9Bmhuw+JQFDIa7woUB4pt+iaUiFMG/10= X-RZG-AUTH: :I2ANY0W6W/eA95XfH/xfO6gOxLxTty/udEMngcJ/VAKW226kDNBZ04ou0x02E9CBuA== X-RZG-CLASS-ID: mo00 Received: from [90.187.252.114] (ip-90-187-252-114.web.vodafone.de [90.187.252.114]) by post.strato.de (mrclete mo36) (RZmta 20.5) with ESMTP id x06d76l7E8s933 ; Fri, 14 Aug 2009 10:54:30 +0200 (MEST) Message-ID: <4A852641.80305@hartkopp.net> Date: Fri, 14 Aug 2009 10:54:25 +0200 From: Oliver Hartkopp User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: David Miller CC: Urs Thuermann , Luotao Fu , Michael Olbrich , Linux Netdev List Subject: [PATCH net-next-2.6] can: Use WARN_ONCE() instead of BUG_ON() for sanity check in receive path X-Enigmail-Version: 0.96.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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: Oliver Hartkopp Signed-off-by: Urs Thuermann CC: Michael Olbrich CC: Luotao Fu diff --git a/net/can/af_can.c b/net/can/af_can.c index e733725..f9c027b 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++; @@ -683,6 +687,10 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev, } return 0; + +drop: + kfree_skb(skb); + return 0; } /*