Skip to contentSkip to conversation

netfilter: flowtable: Saturate 16-bit flow_tuple->mtu

PATCH In review Alice Mikityanska 2 participants 3 messages Sep 10 – Sep 16

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

PATCH 1/1 netfilter: flowtable: Saturate 16-bit flow_tuple->mtu

From: Alice Mikityanska <[email protected]>

ip6_dst_mtu_maybe_forward clamps its return value to IP6_MAX_MTU, which is 40 bytes bigger than U16_MAX. While it can be a valid IPv6 MTU (IPv6 payload_len doesn't include the header), this value is assigned to the 16-bit flow_tuple->mtu in flow_offload_fill_route.

To avoid the overflow, use U16_MAX for all MTUs bigger than 65535. Since flow_tuple->mtu is just a threshold for the software flowtable fast path, packets exceeding it won't be dropped, but rather punted to the normal forwarding path: nf_flow_offload_ipv6_forward returns 0, and nf_flow_offload_ipv6_hook returns NF_ACCEPT.

Fixes 4f3780c004ef ("netfilter: nf_flow_table: cache mtu in struct flow_offload_tuple")
Assisted-by Codex:gpt-5.6-sol
---
 net/netfilter/nf_flow_table_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_core.c +2 -1
index 03241d4bfd5e..8f15540ae206 100644
@@ -107,7 +107,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true);
 		break;
 	case NFPROTO_IPV6:
-		flow_tuple->mtu = ip6_dst_mtu_maybe_forward(dst, true);
+		flow_tuple->mtu = min(ip6_dst_mtu_maybe_forward(dst, true),
+				      U16_MAX);
 		break;
 	}
 
Signature · 1 line
2.55.0
#1 lore raw

Hi,

Quoted 27 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

ip6_dst_mtu_maybe_forward clamps its return value to IP6_MAX_MTU, which is 40 bytes bigger than U16_MAX. While it can be a valid IPv6 MTU (IPv6 payload_len doesn't include the header), this value is assigned to the 16-bit flow_tuple->mtu in flow_offload_fill_route.

To avoid the overflow, use U16_MAX for all MTUs bigger than 65535. Since flow_tuple->mtu is just a threshold for the software flowtable fast path, packets exceeding it won't be dropped, but rather punted to the normal forwarding path: nf_flow_offload_ipv6_forward returns 0, and nf_flow_offload_ipv6_hook returns NF_ACCEPT.

Fixes 4f3780c004ef ("netfilter: nf_flow_table: cache mtu in struct flow_offload_tuple")
Assisted-by Codex:gpt-5.6-sol
---
 net/netfilter/nf_flow_table_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_core.c +0 -0
index 03241d4bfd5e..8f15540ae206 100644

net/netfilter/nf_flow_table_core.c static int flow_offload_fill_route(struct flow_offload *flow, · line 111

Quoted 6 lines
net/netfilter/nf_flow_table_core.c +2 -1
@@ -107,7 +107,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true);
 		break;
 	case NFPROTO_IPV6:
-		flow_tuple->mtu = ip6_dst_mtu_maybe_forward(dst, true);
+		flow_tuple->mtu = min(ip6_dst_mtu_maybe_forward(dst, true),
+				      U16_MAX);

This reminds me we should not catch the mtu.

Quoted 6 lines
net/netfilter/nf_flow_table_core.c +0 -0
 		break;
 	}
 
Signature · 1 line
2.55.0
#2 lore raw
Quoted 25 lines · Pablo Neira Ayuso

Hi,

Quoted 22 lines · Alice Mikityanska

From: Alice Mikityanska <[email protected]>

ip6_dst_mtu_maybe_forward clamps its return value to IP6_MAX_MTU, which is 40 bytes bigger than U16_MAX. While it can be a valid IPv6 MTU (IPv6 payload_len doesn't include the header), this value is assigned to the 16-bit flow_tuple->mtu in flow_offload_fill_route.

To avoid the overflow, use U16_MAX for all MTUs bigger than 65535. Since flow_tuple->mtu is just a threshold for the software flowtable fast path, packets exceeding it won't be dropped, but rather punted to the normal forwarding path: nf_flow_offload_ipv6_forward returns 0, and nf_flow_offload_ipv6_hook returns NF_ACCEPT.

Fixes 4f3780c004ef ("netfilter: nf_flow_table: cache mtu in struct flow_offload_tuple")
Assisted-by Codex:gpt-5.6-sol
---
 net/netfilter/nf_flow_table_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

net/netfilter/nf_flow_table_core.c static int flow_offload_fill_route(struct flow_offload *flow, · line 111

Quoted 11 lines
net/netfilter/nf_flow_table_core.c +2 -1
index 03241d4bfd5e..8f15540ae206 100644
@@ -107,7 +107,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true);
 		break;
 	case NFPROTO_IPV6:
-		flow_tuple->mtu = ip6_dst_mtu_maybe_forward(dst, true);
+		flow_tuple->mtu = min(ip6_dst_mtu_maybe_forward(dst, true),
+				      U16_MAX);

This reminds me we should not catch the mtu.

Sorry, I may not have enough context here... Do you mean "cache the mtu"? Should I go with a different approach about fixing this bug, or should I drop the optimization instead of fixing it?

Thanks,
Alice

Quoted 6 lines
Quoted 6 lines
net/netfilter/nf_flow_table_core.c +0 -0
 		break;
 	}
 
Signature · 1 line
2.55.0