diff mbox series

[nf] netfilter: flowtable: always init block_offload struct

Message ID 20200203120618.2574-1-fw@strlen.de
State Accepted
Delegated to: Pablo Neira
Headers show
Series [nf] netfilter: flowtable: always init block_offload struct | expand

Commit Message

Florian Westphal Feb. 3, 2020, 12:06 p.m. UTC
nftables test case
tests/shell/testcases/flowtable/0001flowtable_0

results in a crash. After the refactor, if we leave early via
nf_flowtable_hw_offload(), then "struct flow_block_offload" is left
in an uninitialized state, but later users assume its initialised.

Fixes: a7965d58ddab02 ("netfilter: flowtable: add nf_flow_table_offload_cmd()")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 I can't test this with HW offload, but at least it gets rid of
 the crash for me.

 net/netfilter/nf_flow_table_offload.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Pablo Neira Ayuso Feb. 7, 2020, 11:20 a.m. UTC | #1
On Mon, Feb 03, 2020 at 01:06:18PM +0100, Florian Westphal wrote:
> nftables test case
> tests/shell/testcases/flowtable/0001flowtable_0
> 
> results in a crash. After the refactor, if we leave early via
> nf_flowtable_hw_offload(), then "struct flow_block_offload" is left
> in an uninitialized state, but later users assume its initialised.

Thanks Florian.

I'll apply this variant of your patch, and sorry for this breakage.
diff mbox series

Patch

diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index c8b70ffeef0c..f909938e8dc4 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -846,12 +846,6 @@  static int nf_flow_table_offload_cmd(struct flow_block_offload *bo,
 {
 	int err;
 
-	if (!nf_flowtable_hw_offload(flowtable))
-		return 0;
-
-	if (!dev->netdev_ops->ndo_setup_tc)
-		return -EOPNOTSUPP;
-
 	memset(bo, 0, sizeof(*bo));
 	bo->net		= dev_net(dev);
 	bo->block	= &flowtable->flow_block;
@@ -860,6 +854,12 @@  static int nf_flow_table_offload_cmd(struct flow_block_offload *bo,
 	bo->extack	= extack;
 	INIT_LIST_HEAD(&bo->cb_list);
 
+	if (!nf_flowtable_hw_offload(flowtable))
+		return 0;
+
+	if (!dev->netdev_ops->ndo_setup_tc)
+		return -EOPNOTSUPP;
+
 	err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, bo);
 	if (err < 0)
 		return err;