From: wenxu@ucloud.cn
To: pablo@netfilter.org, fw@strlen.de
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
Date: Mon, 19 Aug 2019 17:46:47 +0800 [thread overview]
Message-ID: <1566208007-22513-1-git-send-email-wenxu@ucloud.cn> (raw)
From: wenxu <wenxu@ucloud.cn>
The nft_indr_block_get_and_ing_cmd is called in netdevice notify
It is the incorrect rcu case, To fix it just traverse the list under
the commit mutex.
Fixes: 9a32669fecfb ("netfilter: nf_tables_offload: support indr block call")
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/netfilter/nf_tables_offload.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
index b95e27b..bcaafc8 100644
--- a/net/netfilter/nf_tables_offload.c
+++ b/net/netfilter/nf_tables_offload.c
@@ -359,15 +359,18 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,
void *cb_priv,
enum flow_block_command command)
{
- struct net *net = dev_net(dev);
+ const struct nft_chain *chain, *nr;
const struct nft_table *table;
- const struct nft_chain *chain;
+ struct nft_ctx ctx = {
+ .net = dev_net(dev),
+ };
- list_for_each_entry_rcu(table, &net->nft.tables, list) {
+ mutex_lock(&ctx.net->nft.commit_mutex);
+ list_for_each_entry(table, &ctx.net->nft.tables, list) {
if (table->family != NFPROTO_NETDEV)
continue;
- list_for_each_entry_rcu(chain, &table->chains, list) {
+ list_for_each_entry_safe(chain, nr, &table->chains, list) {
if (nft_is_base_chain(chain)) {
struct nft_base_chain *basechain;
@@ -382,4 +385,5 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,
}
}
}
+ mutex_unlock(&ctx.net->nft.commit_mutex);
}
--
1.8.3.1
next reply other threads:[~2019-08-19 9:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-19 9:46 wenxu [this message]
2019-08-19 10:21 ` [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd Florian Westphal
2019-08-19 10:48 ` wenxu
2019-08-19 10:59 ` Florian Westphal
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=1566208007-22513-1-git-send-email-wenxu@ucloud.cn \
--to=wenxu@ucloud.cn \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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;
as well as URLs for NNTP newsgroup(s).