From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kirill Tkhai Subject: [PATCH 2/3] net: Add BUG_ON() to get_net() Date: Thu, 21 Dec 2017 16:14:10 +0300 Message-ID: <151386204146.3724.1821581875608154672.stgit@localhost.localdomain> References: <151386201910.3724.7199367937841370542.stgit@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: eric.dumazet@gmail.com, ktkhai@virtuozzo.com, ebiederm@xmission.com To: netdev@vger.kernel.org, davem@davemloft.net Return-path: Received: from mail-eopbgr10100.outbound.protection.outlook.com ([40.107.1.100]:13920 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751622AbdLUNOR (ORCPT ); Thu, 21 Dec 2017 08:14:17 -0500 In-Reply-To: <151386201910.3724.7199367937841370542.stgit@localhost.localdomain> Sender: netdev-owner@vger.kernel.org List-ID: Since people may mistakenly obtain destroying net from net_namespace_list and from net::netns_ids without checking for its net::counter, let's protect against such situations and insert BUG_ON() to stop move on after this. Panic is better, than memory corruption and undefined behavior. Signed-off-by: Kirill Tkhai --- include/net/net_namespace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 10f99dafd5ac..ff0e47471d5b 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -195,7 +195,7 @@ void __put_net(struct net *net); static inline struct net *get_net(struct net *net) { - atomic_inc(&net->count); + BUG_ON(atomic_inc_return(&net->count) <= 1); return net; }