Skip to contentSkip to conversation

netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_cb

PATCH Applied [email protected] 2 participants 4 messages Sep 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 netfilter: nf_table_offload: Fix the incorrect rcu usage in nft_indr_block_cb

From: wenxu <[email protected]>

The flow_block_ing_cmd() needs to call blocking functions while iterating block_ing_cb_list, nft_indr_block_cb is in the cb_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")

---
v3: rebase to patches 1156728 and 1156729

 net/netfilter/nf_tables_offload.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_offload.c +5 -2
index 113ac40..ca9e0cb 100644
@@ -357,11 +357,12 @@ static void nft_indr_block_cb(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))
 				continue;
 
@@ -370,9 +371,11 @@ static void nft_indr_block_cb(struct net_device *dev,
 				continue;
 
 			nft_indr_block_ing_cmd(dev, basechain, cb, cb_priv, cmd);
+			mutex_unlock(&net->nft.commit_mutex);
 			return;
 		}
 	}
+	mutex_unlock(&net->nft.commit_mutex);
 }
 
 static struct flow_indr_block_ing_entry block_ing_entry = {
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 6 lines · On Tue, Sep 03, 2019 at 11:15:27AM +0800, [email protected] wrote:

From: wenxu <[email protected]>

The flow_block_ing_cmd() needs to call blocking functions while iterating block_ing_cb_list, nft_indr_block_cb is in the cb_list,
So it is the incorrect rcu case. To fix it just traverse the list under the commit mutex.

Applied.

#2 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Sep 03, 2019 at 11:15:27AM +0800, [email protected] wrote:
net/netfilter/nf_tables_offload.c +0 -0
index 113ac40..ca9e0cb 100644
@@ -357,11 +357,12 @@ static void nft_indr_block_cb(struct net_device *dev,
 	const struct nft_table *table;
 	const struct nft_chain *chain;
 

net/netfilter/nf_tables_offload.c static void nft_indr_block_cb(struct net_device *dev, · line 367

Quoted 10 lines
net/netfilter/nf_tables_offload.c +3 -2
-	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))
 				continue;

nft_indr_block_cb() does not check for the offload flag in the basechain...

author
#3 lore raw

yes, It's an another problem. I will send another patch to fix it.

Quoted 22 lines · Pablo Neira Ayuso
Quoted 8 lines · On Tue, Sep 03, 2019 at 11:15:27AM +0800, [email protected] wrote:
net/netfilter/nf_tables_offload.c +0 -0
index 113ac40..ca9e0cb 100644
@@ -357,11 +357,12 @@ static void nft_indr_block_cb(struct net_device *dev,
 	const struct nft_table *table;
 	const struct nft_chain *chain;
 

net/netfilter/nf_tables_offload.c static void nft_indr_block_cb(struct net_device *dev, · line 367

Quoted 10 lines
net/netfilter/nf_tables_offload.c +3 -2
-	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))
 				continue;

nft_indr_block_cb() does not check for the offload flag in the basechain...