netfilter: flowtable: Saturate 16-bit flow_tuple->mtu
Subsystems (3)
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.
--- net/netfilter/nf_flow_table_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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 );break ; }
Signature · 1 line
2.55.0
Pablo Neira Ayuso
maintainerHi,
Quoted 27 lines · Alice Mikityanska
From: Alice Mikityanska <[email protected]>
ip6_dst_mtu_maybe_forwardclamps its return value toIP6_MAX_MTU, which is 40 bytes bigger thanU16_MAX. While it can be a valid IPv6 MTU (IPv6payload_lendoesn't include the header), this value is assigned to the 16-bitflow_tuple->mtuinflow_offload_fill_route.To avoid the overflow, use
U16_MAXfor all MTUs bigger than 65535. Sinceflow_tuple->mtuis 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_forwardreturns 0, andnf_flow_offload_ipv6_hookreturnsNF_ACCEPT.Reported-by Sashiko <[email protected]>Fixes 4f3780c004ef ("netfilter: nf_flow_table: cache mtu in struct flow_offload_tuple")Assisted-by Codex:gpt-5.6-solSigned-off-by Alice Mikityanska <[email protected]>--- net/netfilter/nf_flow_table_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/netfilter/nf_flow_table_core.c +0
-0
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
-0break ; }Signature · 1 line
2.55.0
Quoted 25 lines · Pablo Neira Ayuso
Hi,
Quoted 22 lines · Alice Mikityanska
From: Alice Mikityanska <[email protected]>
ip6_dst_mtu_maybe_forwardclamps its return value toIP6_MAX_MTU, which is 40 bytes bigger thanU16_MAX. While it can be a valid IPv6 MTU (IPv6payload_lendoesn't include the header), this value is assigned to the 16-bitflow_tuple->mtuinflow_offload_fill_route.To avoid the overflow, use
U16_MAXfor all MTUs bigger than 65535. Sinceflow_tuple->mtuis 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_forwardreturns 0, andnf_flow_offload_ipv6_hookreturnsNF_ACCEPT.Reported-by Sashiko <[email protected]>Fixes 4f3780c004ef ("netfilter: nf_flow_table: cache mtu in struct flow_offload_tuple")Assisted-by Codex:gpt-5.6-solSigned-off-by Alice Mikityanska <[email protected]>--- 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@@ -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
-0break ; }Signature · 1 line
2.55.0