Skip to contentSkip to conversation

netfilter: nft_flow_offload: do not make un-established tcp flow_offload session.

PATCH Superseded Taehee Yoo 2 participants 5 messages Apr 26, 2019 – Apr 27, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

PATCH 2/4 netfilter: nft_flow_offload: do not make un-established tcp flow_offload session.

nft_flow_offload_eval() makes flow_offload session but it doesn't check tcp state.
So, it can make un-ESTABLISHED tcp flow offload session such as SYN-RECV. But, this is not a normal case.

Fixes a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
---
 net/netfilter/nft_flow_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_flow_offload.c +3 -0
index ff50bc1b144f..8538ddf9c6bf 100644
@@ -84,6 +84,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 
 	switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
 	case IPPROTO_TCP:
+		if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
+			goto out;
+		break;
 	case IPPROTO_UDP:
 		break;
 	default:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 16 lines · Taehee Yoo

nft_flow_offload_eval() makes flow_offload session but it doesn't check tcp state.
So, it can make un-ESTABLISHED tcp flow offload session such as SYN-RECV. But, this is not a normal case.

Fixes a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
---
 net/netfilter/nft_flow_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_flow_offload.c +0 -0
index ff50bc1b144f..8538ddf9c6bf 100644

net/netfilter/nft_flow_offload.c static void nft_flow_offload_eval(const struct nft_expr *expr, · line 88

Quoted 5 lines
net/netfilter/nft_flow_offload.c +2 -0
@@ -84,6 +84,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 
 	switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
 	case IPPROTO_TCP:
+		if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
+			goto out;

You can restrict this via policy:

ct status assured flow add @x

I've been considering to remove this defensive check

(quoted diff) +0 -0

b/net/netfilter/nft_flow_offload.c
index 6e6b9adf7d38..bb8ea4cefc34 100644

net/netfilter/nft_flow_offload.c +0 -4
@@ -94,10 +94,6 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
        if (help)
                goto out;
 
-       if (ctinfo == IP_CT_NEW ||
-           ctinfo == IP_CT_RELATED)
-               goto out;
-
        if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
                goto out;
 

Given that we can restrict this via policy, ie.

ct state established flow add @x

And this would fix the flowtable infrastructure UDP traffic that only goes in one direction.

We can document in the manpage a few examples for this.

author
#2 lore raw
Quoted 1 line · Pablo Neira Ayuso

Hi Pablo!
Thank you for the review!

Quoted 18 lines · Taehee Yoo
Quoted 17 lines

nft_flow_offload_eval() makes flow_offload session but it doesn't check tcp state.
So, it can make un-ESTABLISHED tcp flow offload session such as SYN-RECV. But, this is not a normal case.

Fixes a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
---
 net/netfilter/nft_flow_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_flow_offload.c +0 -0
index ff50bc1b144f..8538ddf9c6bf 100644
@@ -84,6 +84,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 
Quoted 9 lines

net/netfilter/nft_flow_offload.c static void nft_flow_offload_eval(const struct nft_expr *expr, · line 88

Quoted 4 lines
net/netfilter/nft_flow_offload.c +2 -0
      switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
      case IPPROTO_TCP:
+             if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
+                     goto out;

You can restrict this via policy:

ct status assured flow add @x

I think If we allow to make non-ESTABLISHED flow offload, teardown code should be changed because teardown changes TCP status to ESTABLISHED.
How do you think about it?

Quoted 20 lines

I've been considering to remove this defensive check

net/netfilter/nft_flow_offload.c +0 -4
index 6e6b9adf7d38..bb8ea4cefc34 100644
@@ -94,10 +94,6 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
        if (help)
                goto out;
 
-       if (ctinfo == IP_CT_NEW ||
-           ctinfo == IP_CT_RELATED)
-               goto out;
-
        if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
                goto out;
 

Given that we can restrict this via policy, ie.

Quoted 6 lines

ct state established flow add @x

And this would fix the flowtable infrastructure UDP traffic that only goes in one direction.

We can document in the manpage a few examples for this.

I agree that flowtable infrastructure provides UDP one direction flow offloading.

Thanks!

#3 lore raw
Quoted 31 lines · Taehee Yoo
Quoted 1 line · Pablo Neira Ayuso

Hi Pablo!
Thank you for the review!

Quoted 25 lines · Taehee Yoo
Quoted 16 lines

nft_flow_offload_eval() makes flow_offload session but it doesn't check tcp state.
So, it can make un-ESTABLISHED tcp flow offload session such as SYN-RECV. But, this is not a normal case.

Fixes a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
---
 net/netfilter/nft_flow_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_flow_offload.c +0 -0
index ff50bc1b144f..8538ddf9c6bf 100644

net/netfilter/nft_flow_offload.c static void nft_flow_offload_eval(const struct nft_expr *expr, · line 88

Quoted 5 lines
net/netfilter/nft_flow_offload.c +2 -0
@@ -84,6 +84,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 
      switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
      case IPPROTO_TCP:
+             if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
+                     goto out;

You can restrict this via policy:

Quoted 6 lines
Quoted 2 lines

ct status assured flow add @x

I think If we allow to make non-ESTABLISHED flow offload, teardown code should be changed because teardown changes TCP status to ESTABLISHED. How do you think about it?

Hm, right, the teardown fixup routine cannot then bogusly assumes the TCP established state if we create a TCP entry from the first packet, ie. the SYN_SENT state...

[...]

Quoted 7 lines
Quoted 4 lines

And this would fix the flowtable infrastructure UDP traffic that only goes in one direction.

We can document in the manpage a few examples for this.

I agree that flowtable infrastructure provides UDP one direction flow offloading.

OK, probably I can collapse your patch to mine. Let me think over the weekend.

author
#4 lore raw
Quoted 36 lines · Pablo Neira Ayuso
Quoted 34 lines · Taehee Yoo
Quoted 1 line · Pablo Neira Ayuso

Hi Pablo!
Thank you for the review!

Quoted 27 lines · Taehee Yoo
Quoted 16 lines

nft_flow_offload_eval() makes flow_offload session but it doesn't check tcp state.
So, it can make un-ESTABLISHED tcp flow offload session such as SYN-RECV. But, this is not a normal case.

Fixes a3c90f7a2323 ("netfilter: nf_tables: flow offload expression")
---
 net/netfilter/nft_flow_offload.c | 3 +++
 1 file changed, 3 insertions(+)
net/netfilter/nft_flow_offload.c +0 -0
index ff50bc1b144f..8538ddf9c6bf 100644

net/netfilter/nft_flow_offload.c static void nft_flow_offload_eval(const struct nft_expr *expr, · line 88

Quoted 5 lines
net/netfilter/nft_flow_offload.c +2 -0
@@ -84,6 +84,9 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 
      switch (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum) {
      case IPPROTO_TCP:
+             if (ct->proto.tcp.state != TCP_CONNTRACK_ESTABLISHED)
+                     goto out;

You can restrict this via policy:

ct status assured flow add @x

Quoted 8 lines
Quoted 3 lines

I think If we allow to make non-ESTABLISHED flow offload, teardown code should be changed because teardown changes TCP status to ESTABLISHED. How do you think about it?

Hm, right, the teardown fixup routine cannot then bogusly assumes the TCP established state if we create a TCP entry from the first packet, ie. the SYN_SENT state...

Thank you for sharing opinion.

Quoted 11 lines

[...]

Quoted 7 lines
Quoted 4 lines

And this would fix the flowtable infrastructure UDP traffic that only goes in one direction.

We can document in the manpage a few examples for this.

I agree that flowtable infrastructure provides UDP one direction flow offloading.

OK, probably I can collapse your patch to mine. Let me think over the weekend.

Okay, I will wait for your response!