Skip to contentSkip to conversation

netfilter: nf_tables: check the bind callback failed and unbind callback if hook register failed

PATCH In review [email protected] 2 participants 6 messages Nov 15, 2019

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

PATCH 1/1 netfilter: nf_tables: check the bind callback failed and unbind callback if hook register failed

From: wenxu <[email protected]>

Undo the callback binding before unregistering the existing hooks. It also should check err of the bind setup call

Fixes c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

---
This patch is based on:
http://patchwork.ozlabs.org/patch/1195539/

 net/netfilter/nf_tables_api.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +11 -3
index 0f8080e..149de13 100644
@@ -6001,12 +6001,20 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 			}
 		}
 
-		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
-					    FLOW_BLOCK_BIND);
-		err = nf_register_net_hook(net, &hook->ops);
+		err = flowtable->data.type->setup(&flowtable->data,
+						  hook->ops.dev,
+						  FLOW_BLOCK_BIND);
 		if (err < 0)
 			goto err_unregister_net_hooks;
 
+		err = nf_register_net_hook(net, &hook->ops);
+		if (err < 0) {
+			flowtable->data.type->setup(&flowtable->data,
+						    hook->ops.dev,
+						    FLOW_BLOCK_UNBIND);
+			goto err_unregister_net_hooks;
+		}
+
 		i++;
 	}
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 10 lines · On Fri, Nov 15, 2019 at 07:21:26PM +0800, [email protected] wrote:

From: wenxu <[email protected]>

Undo the callback binding before unregistering the existing hooks. It also should check err of the bind setup call

Fixes c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

---
This patch is based on:
http://patchwork.ozlabs.org/patch/1195539/

This is actually like this one:

https://patchwork.ozlabs.org/patch/1194046/

right?

Quoted 8 lines
 net/netfilter/nf_tables_api.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +0 -0
index 0f8080e..149de13 100644

net/netfilter/nf_tables_api.c static int nft_register_flowtable_net_hooks(struct net *net, · line 6006

Quoted 9 lines
net/netfilter/nf_tables_api.c +3 -3
@@ -6001,12 +6001,20 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 			}
 		}
 
-		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
-					    FLOW_BLOCK_BIND);
-		err = nf_register_net_hook(net, &hook->ops);
+		err = flowtable->data.type->setup(&flowtable->data,
+						  hook->ops.dev,
+						  FLOW_BLOCK_BIND);

I'd rather not check for the return value. ->setup returns 0 unless you use anything else than FLOW_BLOCK_BIND or _UNBIND. Probably better turn nf_flow_table_block_setup void and add WARN_ON_ONCE() there.

#2 lore raw
Quoted 12 lines · Pablo Neira Ayuso
Quoted 10 lines · On Fri, Nov 15, 2019 at 07:21:26PM +0800, [email protected] wrote:

From: wenxu <[email protected]>

Undo the callback binding before unregistering the existing hooks. It also should check err of the bind setup call

Fixes c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

---
This patch is based on:
http://patchwork.ozlabs.org/patch/1195539/

Quoted 5 lines

This is actually like this one:

https://patchwork.ozlabs.org/patch/1194046/

right?

I'm attaching the one I made based on yours that I posted yesterday.

From f070db9a7fb9ecb6d2fdbd4702eb5e29b2bd5f64 Mon Sep 17 00:00:00 2001
From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 15 Nov 2019 00:22:55 +0100
Subject: [PATCH] netfilter: nf_tables: unbind callbacks if flowtable hook
registration fails

Undo the callback binding before unregistering the existing hooks.

Fixes c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")
---
 net/netfilter/nf_tables_api.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +5 -1
index 4f0d880a8496..bd453c28a5d1 100644
@@ -6009,8 +6009,12 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
 					    FLOW_BLOCK_BIND);
 		err = nf_register_net_hook(net, &hook->ops);
-		if (err < 0)
+		if (err < 0) {
+			flowtable->data.type->setup(&flowtable->data,
+						    hook->ops.dev,
+						    FLOW_BLOCK_UNBIND);
 			goto err_unregister_net_hooks;
+		}
 
 		i++;
 	}
Signature · 1 line
2.11.0
author
#3 lore raw
Quoted 12 lines · Pablo Neira Ayuso
Quoted 11 lines · Pablo Neira Ayuso
Quoted 10 lines · On Fri, Nov 15, 2019 at 07:21:26PM +0800, [email protected] wrote:

From: wenxu <[email protected]>

Undo the callback binding before unregistering the existing hooks. It also should check err of the bind setup call

Fixes c29f74e0df7a ("netfilter: nf_flow_table: hardware offload support")

---
This patch is based on:
http://patchwork.ozlabs.org/patch/1195539/

Quoted 6 lines
Quoted 5 lines

This is actually like this one:

https://patchwork.ozlabs.org/patch/1194046/

right?

I'm attaching the one I made based on yours that I posted yesterday.

yes it is include this one.

author
#4 lore raw
In reply to Pablo Neira Ayuso
Quoted 12 lines · Pablo Neira Ayuso
Quoted 12 lines
 net/netfilter/nf_tables_api.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +0 -0
index 0f8080e..149de13 100644
@@ -6001,12 +6001,20 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 			}
 		}
 
Quoted 9 lines

net/netfilter/nf_tables_api.c static int nft_register_flowtable_net_hooks(struct net *net, · line 6006

Quoted 6 lines
net/netfilter/nf_tables_api.c +3 -3
-		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
-					    FLOW_BLOCK_BIND);
-		err = nf_register_net_hook(net, &hook->ops);
+		err = flowtable->data.type->setup(&flowtable->data,
+						  hook->ops.dev,
+						  FLOW_BLOCK_BIND);

I'd rather not check for the return value. ->setup returns 0 unless you use anything else than FLOW_BLOCK_BIND or _UNBIND. Probably better turn nf_flow_table_block_setup void and add WARN_ON_ONCE() there.

If BIND failed. It means hw-offload failed. But the flowtable is set as hw-offload.

Maybe it is not too make sense?

#5 lore raw
Quoted 24 lines · wenxu
Quoted 12 lines · Pablo Neira Ayuso
Quoted 12 lines
 net/netfilter/nf_tables_api.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +0 -0
index 0f8080e..149de13 100644
@@ -6001,12 +6001,20 @@ static int nft_register_flowtable_net_hooks(struct net *net,
 			}
 		}
 
Quoted 9 lines

net/netfilter/nf_tables_api.c static int nft_register_flowtable_net_hooks(struct net *net, · line 6006

Quoted 6 lines
net/netfilter/nf_tables_api.c +3 -3
-		flowtable->data.type->setup(&flowtable->data, hook->ops.dev,
-					    FLOW_BLOCK_BIND);
-		err = nf_register_net_hook(net, &hook->ops);
+		err = flowtable->data.type->setup(&flowtable->data,
+						  hook->ops.dev,
+						  FLOW_BLOCK_BIND);

I'd rather not check for the return value. ->setup returns 0 unless you use anything else than FLOW_BLOCK_BIND or _UNBIND. Probably better turn nf_flow_table_block_setup void and add WARN_ON_ONCE() there.

Quoted 3 lines

If BIND failed. It means hw-offload failed. But the flowtable is set as hw-offload.

Maybe it is not too make sense?

Oh right. Your patch:

https://patchwork.ozlabs.org/patch/1195554/

is actually better. I'll take this and I'll drop mine.

Thanks.