From patchwork Mon Aug 10 11:27:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 31073 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 4612CB6F1F for ; Mon, 10 Aug 2009 21:27:31 +1000 (EST) Received: by ozlabs.org (Postfix) id 35A2BDDD0B; Mon, 10 Aug 2009 21:27:31 +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 A3F60DDD01 for ; Mon, 10 Aug 2009 21:27:30 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752905AbZHJL1S (ORCPT ); Mon, 10 Aug 2009 07:27:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752789AbZHJL1R (ORCPT ); Mon, 10 Aug 2009 07:27:17 -0400 Received: from mo-p00-ob.rzone.de ([81.169.146.162]:24251 "EHLO mo-p00-ob.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752776AbZHJL1R (ORCPT ); Mon, 10 Aug 2009 07:27:17 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1249903636; l=2182; s=domk; d=hartkopp.net; h=Content-Type:Subject:CC:To:MIME-Version:From:Date:X-RZG-CLASS-ID: X-RZG-AUTH; bh=p9SVXdwCcBXMpfEmwHGZ71DR+P0=; b=d2e6N9Z4VYIUzheCtiLb/pf9T0lDyvkRXMmH2es3oM+G5qUDbUri/KEyJlu/H5KjNVa z7U8FnSg2WQGQ2JWRTuKC3xhwqEFPqwd0sXavtWNXvYtvcqMvPTLKiv4h0xGItCqV6uqw imgvUtSDsHBD9DLKNkXCb8zefDZ8noRVi7s= X-RZG-AUTH: :I2ANY0W6W/eA95XfH/xfO6gOxLxTty/udEMngcJ/VAKW226kDNBZ04ov0gErEbw= X-RZG-CLASS-ID: mo00 Received: from [90.187.34.33] (ip-90-187-34-33.web.vodafone.de [90.187.34.33]) by post.strato.de (mrclete mo15) (RZmta 20.4) with ESMTP id U04beel7AA5WLT ; Mon, 10 Aug 2009 13:27:12 +0200 (MEST) Message-ID: <4A80040D.3030009@hartkopp.net> Date: Mon, 10 Aug 2009 13:27:09 +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-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). Additionally it changes the return values to the common NET_RX_xxx constants. 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..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; } /*