From patchwork Wed Jan 25 20:33:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sjur.brandeland@stericsson.com X-Patchwork-Id: 137858 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9076AB6EF7 for ; Thu, 26 Jan 2012 07:34:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752193Ab2AYUeE (ORCPT ); Wed, 25 Jan 2012 15:34:04 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:43234 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751025Ab2AYUeC (ORCPT ); Wed, 25 Jan 2012 15:34:02 -0500 Received: by eekc14 with SMTP id c14so2787260eek.19 for ; Wed, 25 Jan 2012 12:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:references:mime-version:content-type :content-transfer-encoding; bh=zdEbEjreJMrxd6wL83x1Xrts7VdYezgP4stXq+KnUos=; b=V8Fm/HRHKM05Wj8i5Ce/csL96s4c8cs4toWSS/CQC8J5BVYjkUxzlB1mSdkr/JlTSu n9mwSjOW9/Uzo03b6QaWYxxgS05Qko3R+IY5ggn28Cz5D/YH3utJNrOah6kb2qpOJTND +42G5fXTFXGO4CTj+pbjYm+yaJE5wbNacGYqg= Received: by 10.14.39.196 with SMTP id d44mr6290290eeb.108.1327523640879; Wed, 25 Jan 2012 12:34:00 -0800 (PST) Received: from localhost.localdomain (207.80-203-142.nextgentel.com. [80.203.142.207]) by mx.google.com with ESMTPS id y54sm5959210eef.8.2012.01.25.12.33.58 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 12:33:59 -0800 (PST) From: =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= To: levinsasha928@gmail.com, netdev@vger.kernel.org, davem@davemloft.net Cc: linux-kernel@vger.kernel.org, davej@redhat.com, sjurbren@gmail.com, =?UTF-8?q?Sjur=20Br=C3=A6ndeland?= Subject: [PATCH net] caif: Fix crash due to uninitialized net name-space. Date: Wed, 25 Jan 2012 21:33:51 +0100 Message-Id: <1327523631-3480-1-git-send-email-sjur.brandeland@stericsson.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: References: <1327444045-1033-1-git-send-email-sjur.brandeland@stericsson.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org net_generic() calls BUG_ON() if called with uninitialized network name-space. Add check if net is initialized before calling net_generic(). This fixes the following oops: [ 200.752016] kernel BUG at include/net/netns/generic.h:40! ... [ 200.752016] [] ? get_cfcnfg+0x3a/0x180 [ 200.752016] [] ? lockdep_rtnl_is_held+0x10/0x20 [ 200.752016] [] caif_device_notify+0x2e/0x530 [ 200.752016] [] notifier_call_chain+0x67/0x110 [ 200.752016] [] raw_notifier_call_chain+0x11/0x20 [ 200.752016] [] call_netdevice_notifiers+0x32/0x60 [ 200.752016] [] register_netdevice+0x196/0x300 [ 200.752016] [] register_netdev+0x19/0x30 [ 200.752016] [] loopback_net_init+0x4a/0xa0 [ 200.752016] [] ops_init+0x42/0x180 [ 200.752016] [] setup_net+0x6b/0x100 [ 200.752016] [] copy_net_ns+0x86/0x110 [ 200.752016] [] create_new_namespaces+0xd9/0x190 Signed-off-by: Sjur Brændeland Tested-by: Sasha Levin --- Hi Sasha and Dave, [Sasha] >Works for me. Thank you Sasha for reporting this bug and testing my patch, I appreciate it. [Dave] >Please post all networking patches CC:'d Sorry, I missed the obvious. I'm resending the same patch as yesterday, this time to:netdev and with "Tested-by: Sasha". Please apply to net. Thanks, Sjur net/caif/caif_dev.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c index 673728a..6110ade 100644 --- a/net/caif/caif_dev.c +++ b/net/caif/caif_dev.c @@ -371,6 +371,14 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what, struct cflayer *layer, *link_support; int head_room = 0; struct caif_device_entry_list *caifdevs; + int len; + + rcu_read_lock(); + len = rcu_dereference(dev_net(dev)->gen)->len; + rcu_read_unlock(); + + if (caif_net_id == 0 || caif_net_id > len) + return 0; cfg = get_cfcnfg(dev_net(dev)); caifdevs = caif_device_list(dev_net(dev));