From: David Miller <davem@davemloft.net>
To: ktkhai@virtuozzo.com
Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, ebiederm@xmission.com
Subject: Re: [PATCH v3 1/2] net: Fix possible race in peernet2id_alloc()
Date: Wed, 17 Jan 2018 15:43:08 -0500 (EST) [thread overview]
Message-ID: <20180117.154308.169315058756768615.davem@davemloft.net> (raw)
In-Reply-To: <151609506842.12003.15536977929261353291.stgit@localhost.localdomain>
From: Kirill Tkhai <ktkhai@virtuozzo.com>
Date: Tue, 16 Jan 2018 12:31:41 +0300
> peernet2id_alloc() is racy without rtnl_lock() as refcount_read(&peer->count)
> under net->nsid_lock does not guarantee, peer is alive:
>
> rcu_read_lock()
> peernet2id_alloc() ..
> spin_lock_bh(&net->nsid_lock) ..
> refcount_read(&peer->count) (!= 0) ..
> .. put_net()
> .. cleanup_net()
> .. for_each_net(tmp)
> .. spin_lock_bh(&tmp->nsid_lock)
> .. __peernet2id(tmp, net) == -1
> .. ..
> .. ..
> __peernet2id_alloc(alloc == true) ..
> .. ..
> rcu_read_unlock() ..
> .. synchronize_rcu()
> .. kmem_cache_free(net)
>
> After the above situation, net::netns_id contains id pointing to freed memory,
> and any other dereferencing by the id will operate with this freed memory.
>
> Currently, peernet2id_alloc() is used under rtnl_lock() everywhere except
> ovs_vport_cmd_fill_info(), and this race can't occur. But peernet2id_alloc()
> is generic interface, and better we fix it before someone really starts
> use it in wrong context.
>
> v2: Don't place refcount_read(&net->count) under net->nsid_lock
> as suggested by Eric W. Biederman <ebiederm@xmission.com>
> v3: Rebase on top of net-next
>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Applied to net-next.
prev parent reply other threads:[~2018-01-17 20:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-16 9:31 [PATCH v3 1/2] net: Fix possible race in peernet2id_alloc() Kirill Tkhai
2018-01-16 9:31 ` [PATCH v3 2/2] net: Remove spinlock from get_net_ns_by_id() Kirill Tkhai
2018-01-17 20:43 ` David Miller
2018-01-17 20:43 ` David Miller [this message]
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=20180117.154308.169315058756768615.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=eric.dumazet@gmail.com \
--cc=ktkhai@virtuozzo.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