From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: netdev@vger.kernel.org, davem@davemloft.net
Cc: eric.dumazet@gmail.com, ktkhai@virtuozzo.com, ebiederm@xmission.com
Subject: [PATCH 2/3] net: Add BUG_ON() to get_net()
Date: Thu, 21 Dec 2017 16:14:10 +0300 [thread overview]
Message-ID: <151386204146.3724.1821581875608154672.stgit@localhost.localdomain> (raw)
In-Reply-To: <151386201910.3724.7199367937841370542.stgit@localhost.localdomain>
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 <ktkhai@virtuozzo.com>
---
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;
}
next prev parent reply other threads:[~2017-12-21 13:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-21 13:13 [PATCH 1/3] net: Fix possible race in peernet2id_alloc() Kirill Tkhai
2017-12-21 13:14 ` Kirill Tkhai [this message]
2017-12-21 13:14 ` [PATCH 3/3] net: Remove spinlock from get_net_ns_by_id() Kirill Tkhai
2017-12-21 17:39 ` [PATCH 1/3] net: Fix possible race in peernet2id_alloc() Eric W. Biederman
2017-12-22 10:30 ` Kirill Tkhai
2017-12-28 12:55 ` Kirill Tkhai
2017-12-28 17:17 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=151386204146.3724.1821581875608154672.stgit@localhost.localdomain \
--to=ktkhai@virtuozzo.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox