netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
Subsystems (2)
PATCH v2 1/1 netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_get_and_ing_cmd
From: wenxu <[email protected]>
The 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 is the incorrect rcu case. To fix it just traverse the list under the commit mutex.
--- net/netfilter/nf_tables_offload.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_offload.c +4 -2
@@ -363,11 +363,12 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,const struct nft_table *table;const struct nft_chain *chain; -list_for_each_entry_rcu (table, &net->nft.tables, list) { +mutex_lock (&net->nft.commit_mutex); +list_for_each_entry (table, &net->nft.tables, list) {if (table->family !=NFPROTO_NETDEV )continue ; -list_for_each_entry_rcu (chain, &table->chains, list) { +list_for_each_entry (chain, &table->chains, list) {if (nft_is_base_chain (chain)) {struct nft_base_chain *basechain;
@@ -382,4 +383,5 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev, } } } +mutex_unlock (&net->nft.commit_mutex); }
Signature · 1 line
1.8.3.1
Pablo Neira Ayuso
maintainerQuoted 6 lines · On Mon, Aug 19, 2019 at 09:22:32PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
The
flow_block_ing_cmd()needs to call blocking functions while iteratingblock_ing_cb_list,nft_indr_block_get_and_ing_cmdis in thecb_list, So it is the incorrect rcu case. To fix it just traverse the list under the commit mutex.
The flow_indr_block_call() is called from a path that already holds this lock.
Quoted 9 lines · Pablo Neira Ayuso
Quoted 6 lines · On Mon, Aug 19, 2019 at 09:22:32PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
The
flow_block_ing_cmd()needs to call blocking functions while iteratingblock_ing_cb_list,nft_indr_block_get_and_ing_cmdis in thecb_list, So it is the incorrect rcu case. To fix it just traverse the list under the commit mutex.The
flow_indr_block_call()is called from a path that already holds this lock.
The flow_indr_block_call already hodls this lock. But the flow_block_ing_cmd is not called
by flow_indr_block_call. It is called by offloaded driver with unregister event for indr_dev.
Quoted 1 line
Hi pablo,
any other questions about this patch?
BR
wenxu
Quoted 38 lines · On 8/19/2019 9:22 PM, [email protected] wrote:
From: wenxu <[email protected]>
The
flow_block_ing_cmd()needs to call blocking functions while iteratingblock_ing_cb_list,nft_indr_block_get_and_ing_cmdis in thecb_list, So 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 <[email protected]>--- net/netfilter/nf_tables_offload.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)net/netfilter/nf_tables_offload.c +4
-2@@ -363,11 +363,12 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,const struct nft_table *table;const struct nft_chain *chain; -list_for_each_entry_rcu (table, &net->nft.tables, list) { +mutex_lock (&net->nft.commit_mutex); +list_for_each_entry (table, &net->nft.tables, list) {if (table->family !=NFPROTO_NETDEV )continue ; -list_for_each_entry_rcu (chain, &table->chains, list) { +list_for_each_entry (chain, &table->chains, list) {if (nft_is_base_chain (chain)) {struct nft_base_chain *basechain;@@ -382,4 +383,5 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev, } } } +mutex_unlock (&net->nft.commit_mutex); }
Pablo Neira Ayuso
maintainerQuoted 3 lines · wenxu
Hi pablo,
any other questions about this patch?
Please, rebase:
https://patchwork.ozlabs.org/patch/1156728/
https://patchwork.ozlabs.org/patch/1156729/