From patchwork Wed Nov 16 09:49:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 695484 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 3tJfcl1qLhz9t5m for ; Wed, 16 Nov 2016 20:49:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935727AbcKPJtr (ORCPT ); Wed, 16 Nov 2016 04:49:47 -0500 Received: from host.76.145.23.62.rev.coltfrance.com ([62.23.145.76]:44453 "EHLO proxy.6wind.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932820AbcKPJtp (ORCPT ); Wed, 16 Nov 2016 04:49:45 -0500 Received: from elsass.dev.6wind.com (unknown [10.16.0.149]) by proxy.6wind.com (Postfix) with ESMTPS id A90E724818; Wed, 16 Nov 2016 10:49:39 +0100 (CET) Received: from root by elsass.dev.6wind.com with local (Exim 4.84_2) (envelope-from ) id 1c6wqY-0000Su-AI; Wed, 16 Nov 2016 10:49:38 +0100 From: Nicolas Dichtel To: avagin@gmail.com Cc: davem@davemloft.net, netdev@vger.kernel.org, xiyou.wangcong@gmail.com, Nicolas Dichtel Subject: [PATCH net v2] net: nsid cannot be allocated for a dead netns Date: Wed, 16 Nov 2016 10:49:35 +0100 Message-Id: <1479289775-1715-1-git-send-email-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <201611161759.tCk5fdCO%fengguang.wu@intel.com> References: <201611161759.tCk5fdCO%fengguang.wu@intel.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Andrei reports the following kmemleak error: unreferenced object 0xffff91badb543950 (size 2096): comm "kworker/u4:0", pid 6, jiffies 4295152553 (age 28.418s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 cb 5f df ba 91 ff ff .........._..... 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmemleak_alloc+0x4a/0xa0 [] kmem_cache_alloc+0x128/0x280 [] idr_layer_alloc+0x2b/0x90 [] idr_get_empty_slot+0x34d/0x370 [] idr_alloc+0x5e/0x110 [] __peernet2id_alloc+0x6d/0x90 [] peernet2id_alloc+0x55/0xb0 [] rtnl_fill_ifinfo+0xaa6/0x10a0 [] rtmsg_ifinfo_build_skb+0x73/0xd0 [] rollback_registered_many+0x295/0x390 [] unregister_netdevice_many+0x25/0x80 [] default_device_exit_batch+0x145/0x170 [] ops_exit_list.isra.4+0x52/0x60 [] cleanup_net+0x1bf/0x2a0 [] process_one_work+0x1ff/0x660 [] worker_thread+0x4e/0x480 There is no reason to try to allocate an nsid for a netns which is dying. Fixes: 0c7aecd4bde4 ("netns: add rtnl cmd to add and get peer netns ids") Reported-by: Andrei Vagin Signed-off-by: Nicolas Dichtel --- v2: fix compilation add the 'Fixes' tag. Andrei, can you test this new version? Regards, Nicolas net/core/net_namespace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index f61c0e02a413..63f65387f4e1 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -159,6 +159,9 @@ static int alloc_netid(struct net *net, struct net *peer, int reqid) max = reqid + 1; } + if (!atomic_read(&net->count) || !atomic_read(&peer->count)) + return -EINVAL; + return idr_alloc(&net->netns_ids, peer, min, max, GFP_ATOMIC); }