netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
@ 2019-08-19  9:46 wenxu
  2019-08-19 10:21 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: wenxu @ 2019-08-19  9:46 UTC (permalink / raw)
  To: pablo, fw; +Cc: netfilter-devel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
  2019-08-19  9:46 [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd wenxu
@ 2019-08-19 10:21 ` Florian Westphal
  2019-08-19 10:48   ` wenxu
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2019-08-19 10:21 UTC (permalink / raw)
  To: wenxu; +Cc: pablo, fw, netfilter-devel

wenxu@ucloud.cn <wenxu@ucloud.cn> wrote:
> 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.

What is an 'incorrect rcu case'?

Please clarify, e.g. by including rcu warning/splat backtrace here.

> +	struct nft_ctx ctx = {
> +		.net	= dev_net(dev),
> +	};

Why is this ctx needed?

> +	mutex_lock(&ctx.net->nft.commit_mutex);

net->nft.commit_mutex?

> -		list_for_each_entry_rcu(chain, &table->chains, list) {
> +		list_for_each_entry_safe(chain, nr, &table->chains, list) {

Why is _safe needed rather than list_for_each_entry()?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
  2019-08-19 10:21 ` Florian Westphal
@ 2019-08-19 10:48   ` wenxu
  2019-08-19 10:59     ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: wenxu @ 2019-08-19 10:48 UTC (permalink / raw)
  To: Florian Westphal; +Cc: pablo, netfilter-devel


On 8/19/2019 6:21 PM, Florian Westphal wrote:
> wenxu@ucloud.cn <wenxu@ucloud.cn> wrote:
>> 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.
> What is an 'incorrect rcu case'?
>
> Please clarify, e.g. by including rcu warning/splat backtrace here.

according to http://patchwork.ozlabs.org/patch/1148283/

flow_block_ing_cmd() needs to call blocking functions while iterating block_ing_cb_list,

nft_indr_block_get_and_ing_cmd is in the cb_list, So it should also not in rcu for blocking

cases.

>
>> +	struct nft_ctx ctx = {
>> +		.net	= dev_net(dev),
>> +	};
> Why is this ctx needed?
>
>> +	mutex_lock(&ctx.net->nft.commit_mutex);
> net->nft.commit_mutex?

When traverse the list, the list is protected under commit_mutex like nf_tables_netdev_event

do in the netdevice notify callback

>
>> -		list_for_each_entry_rcu(chain, &table->chains, list) {
>> +		list_for_each_entry_safe(chain, nr, &table->chains, list) {
> Why is _safe needed rather than list_for_each_entry()?
yes list_for_each_entry() is better
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
  2019-08-19 10:48   ` wenxu
@ 2019-08-19 10:59     ` Florian Westphal
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2019-08-19 10:59 UTC (permalink / raw)
  To: wenxu; +Cc: Florian Westphal, pablo, netfilter-devel

wenxu <wenxu@ucloud.cn> wrote:
> >> 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.
> > What is an 'incorrect rcu case'?
> >
> > Please clarify, e.g. by including rcu warning/splat backtrace here.

[..]

> flow_block_ing_cmd() needs to call blocking functions while iterating block_ing_cb_list,
> nft_indr_block_get_and_ing_cmd is in the cb_list, So it should also not in rcu for blocking
> cases.

Please submit a v2 that includes this explanation in the commit message.

> >> +	struct nft_ctx ctx = {
> >> +		.net	= dev_net(dev),
> >> +	};
> > Why is this ctx needed?
> >
> >> +	mutex_lock(&ctx.net->nft.commit_mutex);
> > net->nft.commit_mutex?
> 
> When traverse the list, the list is protected under commit_mutex like nf_tables_netdev_event
> do in the netdevice notify callback

Yes, I see that, but why do you need nft_ctx ctx?  Its confusing.

Just use

mutex_lock(&net->nft.commit_mutex);

without adding this 'ctx'.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-19 10:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19  9:46 [PATCH nf-next] netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd wenxu
2019-08-19 10:21 ` Florian Westphal
2019-08-19 10:48   ` wenxu
2019-08-19 10:59     ` Florian Westphal

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).