netfilter: flowtable: extend ct timeout of offloaded GRE flows
Subsystems (4)
PATCH 1/1 netfilter: flowtable: extend ct timeout of offloaded GRE flows
Since commit 03428ca5cee9 ("netfilter: conntrack: rework offload nf_conn timeout extension logic"), the flowtable gc worker extends the timeout of an offloaded conntrack entry from nf_flow_table_extend_ct_timeout() once it falls below 5 minutes. That function only knows about TCP and UDP and hits WARN_ON_ONCE() for any other layer 4 protocol. However, GRE flows can be offloaded too, both via nft_flow_offload and act_ct, since commit 4e8d9584d154 ("netfilter: flowtable: Support GRE").
The timeout of an offloaded GRE entry drops below that threshold as soon as a packet of the flow still goes through conntrack. With ip6gre tunnels using the default encapsulation limit this is ordinary traffic:
the flowtable does not parse the Destination Options header in front of GRE, so every packet of the flow takes the classic forwarding path. It also happens for a packet with ttl <= 1, which the flowtable fast path passes up to the classic forwarding path. nf_conntrack_gre_packet() then refreshes ct->timeout to the GRE stream timeout (180 seconds by default), and the next gc run triggers, as reported by syzbot:
WARNING: net/netfilter/nf_flow_table_core.c:553 at nf_flow_table_extend_ct_timeout+0x1ee/0x2f0 Workqueue: events_power_efficient nf_flow_offload_work_gc Call Trace: nf_flow_offload_gc_step+0x545/0x7b0 nf_flow_table_iterate+0x13c/0x1f0 nf_flow_offload_work_gc+0x22/0x70 process_scheduled_works+0xc3d/0x1630 worker_thread+0xa47/0xfb0 kthread+0x38b/0x480
Besides the splat, which panics the machine with panic_on_warn, the default branch sets the new timeout to 1 jiffy, so the conntrack entry expires right away and the offloaded flow is torn down.
Handle GRE like UDP and extend the timeout to NF_CT_DAY. GRE conntrack has no protocol state to take into account, and NF_CT_DAY is also what flow_offload_add() already sets for every offloaded entry, GRE included. This also restores the behaviour from before commit 03428ca5cee9, when the conntrack gc worker extended offloaded entries of any protocol to NF_CT_DAY.
---
Tested on v7.3 in QEMU, with and without KASAN, lockdep and DEBUG_OBJECTS, using netns topologies where a router namespace offloads GRE flows to a flowtable:
- nft "flow add" and tc act_ct, each with IPv4 GRE and ip6gre
- ip6gre with the default encapsulation limit (plain pings), and ttl=1 GRE packets for IPv4
- 120s stress runs: 6 GRE tunnels plus TCP/UDP traffic, ttl=1 packets, flowtable deleted and re-added every ~20s
Without this patch every run hits the WARN above and the GRE conntrack entries are torn down and recreated over and over (hundreds of NEW events in the stress run); with panic_on_warn=1 the kernel panics. With it there is no WARN, GRE entries stay offloaded with a ~1 day timeout, and TCP/UDP behave as before. The nft_flowtable.sh, nft_offload.sh and nft_interface_stress.sh selftests give the same results with and without this patch.
net/netfilter/nf_flow_table_core.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_flow_table_core.c +1 -0
@@ -544,6 +544,7 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)switch (l4proto) {case IPPROTO_UDP : +case IPPROTO_GRE : new_timeout =NF_CT_DAY ;break ;case IPPROTO_TCP :
Signature · 1 line
2.43.0