Skip to contentSkip to conversation

netfilter: flowtable: Make sure dst_cache is valid before using it

PATCH In review Roi Dayan 2 participants 5 messages Apr 11, 2021 – Apr 13, 2021

Subsystems (3)
lore
Share & tools
lore

Roi Dayan

author
#0 lore raw

PATCH 1/1 netfilter: flowtable: Make sure dst_cache is valid before using it

It could be dst_cache was not set so check it's not null before using it.

Fixes 8b9229d15877 ("netfilter: flowtable: dst_check() from garbage collector path")
---
 net/netfilter/nf_flow_table_core.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_flow_table_core.c +2 -0
index 76573bae6664..e426077aaed1 100644
@@ -410,6 +410,8 @@ static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple)
 	if (tuple->xmit_type == FLOW_OFFLOAD_XMIT_NEIGH ||
 	    tuple->xmit_type == FLOW_OFFLOAD_XMIT_XFRM) {
 		dst = tuple->dst_cache;
+		if (!dst)
+			return false;
 		if (!dst_check(dst, tuple->dst_cookie))
 			return true;
 	}
Signature · 1 line
2.26.2
#1 lore raw

Hi Roi,

Quoted 2 lines · Roi Dayan

It could be dst_cache was not set so check it's not null before using it.

Could you give a try to this fix?

net/sched/act_ct.c leaves the xmit_type as FLOW_OFFLOAD_XMIT_UNSPEC since it does not cache a route.

Thanks.

Quoted 22 lines
Fixes 8b9229d15877 ("netfilter: flowtable: dst_check() from garbage collector path")
---
 net/netfilter/nf_flow_table_core.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_flow_table_core.c +2 -0
index 76573bae6664..e426077aaed1 100644
@@ -410,6 +410,8 @@ static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple)
 	if (tuple->xmit_type == FLOW_OFFLOAD_XMIT_NEIGH ||
 	    tuple->xmit_type == FLOW_OFFLOAD_XMIT_XFRM) {
 		dst = tuple->dst_cache;
+		if (!dst)
+			return false;
 		if (!dst_check(dst, tuple->dst_cookie))
 			return true;
 	}
Signature · 1 line
2.26.2
include/net/netfilter/nf_flow_table.h +2 -1
index 583b327d8fc0..9b42c6523b4d 100644
@@ -90,7 +90,8 @@ enum flow_offload_tuple_dir {
 #define FLOW_OFFLOAD_DIR_MAX	IP_CT_DIR_MAX
 
 enum flow_offload_xmit_type {
-	FLOW_OFFLOAD_XMIT_NEIGH		= 0,
+	FLOW_OFFLOAD_XMIT_UNSPEC	= 0,
+	FLOW_OFFLOAD_XMIT_NEIGH,
 	FLOW_OFFLOAD_XMIT_XFRM,
 	FLOW_OFFLOAD_XMIT_DIRECT,
 };
net/netfilter/nf_flow_table_core.c +3 -0
index 76573bae6664..ea23a36dc14e 100644
@@ -130,6 +130,9 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		flow_tuple->dst_cache = dst;
 		flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple);
 		break;
+	case FLOW_OFFLOAD_XMIT_UNSPEC:
+		WARN_ON_ONCE(1);
+		break;
 	}
 	flow_tuple->xmit_type = route->tuple[dir].xmit_type;
 
author
#2 lore raw
Quoted 6 lines · Pablo Neira Ayuso

Hi Roi,

Quoted 2 lines · Roi Dayan

It could be dst_cache was not set so check it's not null before using it.

Quoted 7 lines

Could you give a try to this fix?

net/sched/act_ct.c leaves the xmit_type as FLOW_OFFLOAD_XMIT_UNSPEC since it does not cache a route.

Thanks.

what do you mean? FLOW_OFFLOAD_XMIT_UNSPEC doesn't exists so default 0 is set.

do you suggest adding that enum option as 0?

this is the current xmit_type enum

enum flow_offload_xmit_type {
FLOW_OFFLOAD_XMIT_NEIGH = 0,
FLOW_OFFLOAD_XMIT_XFRM,
FLOW_OFFLOAD_XMIT_DIRECT,
};

Quoted 22 lines
Quoted 22 lines
Fixes 8b9229d15877 ("netfilter: flowtable: dst_check() from garbage collector path")
---
  net/netfilter/nf_flow_table_core.c | 2 ++
  1 file changed, 2 insertions(+)
net/netfilter/nf_flow_table_core.c +2 -0
index 76573bae6664..e426077aaed1 100644
@@ -410,6 +410,8 @@ static bool flow_offload_stale_dst(struct flow_offload_tuple *tuple)
  	if (tuple->xmit_type == FLOW_OFFLOAD_XMIT_NEIGH ||
  	    tuple->xmit_type == FLOW_OFFLOAD_XMIT_XFRM) {
  		dst = tuple->dst_cache;
+		if (!dst)
+			return false;
  		if (!dst_check(dst, tuple->dst_cookie))
  			return true;
  	}
Signature · 1 line
2.26.2
#3 lore raw
Quoted 14 lines · Roi Dayan
Quoted 11 lines · Pablo Neira Ayuso

Hi Roi,

Quoted 2 lines · Roi Dayan

It could be dst_cache was not set so check it's not null before using it.

Could you give a try to this fix?

net/sched/act_ct.c leaves the xmit_type as FLOW_OFFLOAD_XMIT_UNSPEC since it does not cache a route.

Quoted 7 lines
Quoted 2 lines

Thanks.

what do you mean? FLOW_OFFLOAD_XMIT_UNSPEC doesn't exists so default 0 is set.

do you suggest adding that enum option as 0?

Yes. This could be FLOW_OFFLOAD_XMIT_TC instead if you prefer.

enum flow_offload_xmit_type {
FLOW_OFFLOAD_XMIT_TC = 0,
FLOW_OFFLOAD_XMIT_NEIGH,
FLOW_OFFLOAD_XMIT_XFRM,
FLOW_OFFLOAD_XMIT_DIRECT,
};

so there is no need to check for no route in the FLOW_OFFLOAD_XMIT_NEIGH case (it's assumed this type always has a route).

author
#4 lore raw
Quoted 32 lines · Pablo Neira Ayuso
Quoted 14 lines · Roi Dayan
Quoted 11 lines · Pablo Neira Ayuso

Hi Roi,

Quoted 2 lines · Roi Dayan

It could be dst_cache was not set so check it's not null before using it.

Could you give a try to this fix?

net/sched/act_ct.c leaves the xmit_type as FLOW_OFFLOAD_XMIT_UNSPEC since it does not cache a route.

Quoted 7 lines
Quoted 2 lines

Thanks.

what do you mean? FLOW_OFFLOAD_XMIT_UNSPEC doesn't exists so default 0 is set.

do you suggest adding that enum option as 0?

Yes. This could be FLOW_OFFLOAD_XMIT_TC instead if you prefer.

enum flow_offload_xmit_type {
FLOW_OFFLOAD_XMIT_TC = 0,
FLOW_OFFLOAD_XMIT_NEIGH,
FLOW_OFFLOAD_XMIT_XFRM,
FLOW_OFFLOAD_XMIT_DIRECT,
};

Quoted 4 lines

so there is no need to check for no route in the FLOW_OFFLOAD_XMIT_NEIGH case (it's assumed this type always has a route).

thanks Pablo. were not sure I wanted to touch the enum. I prefer unspec actually as you suggested initially. it works fine by adding the enum.

i'll submit v2 with this suggestion.