From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: Ziyang Xuan <william.xuanziyang@huawei.com>,
kadlec@netfilter.org, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft] netfilter: nf_tables: Fix pertential data-race in __nft_flowtable_type_get()
Date: Tue, 2 Apr 2024 13:30:21 +0200 [thread overview]
Message-ID: <ZgvsTTsCUay4GCUa@calendula> (raw)
In-Reply-To: <20240402105642.GB18301@breakpoint.cc>
On Tue, Apr 02, 2024 at 12:56:42PM +0200, Florian Westphal wrote:
> Ziyang Xuan <william.xuanziyang@huawei.com> wrote:
> > nft_unregister_flowtable_type() within nf_flow_inet_module_exit() can
> > concurrent with __nft_flowtable_type_get() within nf_tables_newflowtable().
> > And thhere is not any protection when iterate over nf_tables_flowtables
> > list in __nft_flowtable_type_get(). Therefore, there is pertential
> > data-race of nf_tables_flowtables list entry.
> >
> > Use list_for_each_entry_rcu() with rcu_read_lock() to Iterate over
> > nf_tables_flowtables list in __nft_flowtable_type_get() to resolve it.
>
> I don't think this resolves the described race.
>
> > Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
> > ---
> > net/netfilter/nf_tables_api.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> > index fd86f2720c9e..fbf38e32f11d 100644
> > --- a/net/netfilter/nf_tables_api.c
> > +++ b/net/netfilter/nf_tables_api.c
> > @@ -8297,10 +8297,14 @@ static const struct nf_flowtable_type *__nft_flowtable_type_get(u8 family)
> > {
> > const struct nf_flowtable_type *type;
> >
> > - list_for_each_entry(type, &nf_tables_flowtables, list) {
> > - if (family == type->family)
> > + rcu_read_lock()
> > + list_for_each_entry_rcu(type, &nf_tables_flowtables, list) {
> > + if (family == type->family) {
> > + rcu_read_unlock();
> > return type;
>
> This means 'type' can be non-null while module is being unloaded,
> before refcount increment.
>
> You need acquire rcu_read_lock() in the caller, nft_flowtable_type_get,
> and release it after refcount on module owner failed or succeeded.
And these need to be rcu protected:
static LIST_HEAD(nf_tables_expressions);
static LIST_HEAD(nf_tables_objects);
static LIST_HEAD(nf_tables_flowtables);
for a complete fix for:
f102d66b335a ("netfilter: nf_tables: use dedicated mutex to guard transactions")
next prev parent reply other threads:[~2024-04-02 11:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-01 13:34 [PATCH nft] netfilter: nf_tables: Fix pertential data-race in __nft_flowtable_type_get() Ziyang Xuan
2024-04-02 10:56 ` Florian Westphal
2024-04-02 11:30 ` Pablo Neira Ayuso [this message]
2024-04-02 12:58 ` Ziyang Xuan (William)
2024-04-02 12:52 ` Ziyang Xuan (William)
2024-04-02 13:55 ` Florian Westphal
2024-04-03 0:51 ` Ziyang Xuan (William)
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=ZgvsTTsCUay4GCUa@calendula \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=kadlec@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=william.xuanziyang@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.