netfilter: conntrack: introduce clash resolution on insertion race
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 1/1 netfilter: conntrack: introduce clash resolution on insertion race
This patch introduces nf_ct_resolve_clash() to resolve race condition on conntrack insertions.
This is particularly a problem for connection-less protocols such as UDP, with no initial handshake. Two or more packets may race to insert the entry resulting in packet drops.
Another problematic scenario are packets enqueued to userspace via NFQUEUE after the raw table, that make it easier to trigger this race.
To resolve this, the idea is to reset the conntrack entry to the one that won race. Packet and bytes counters are also merged.
The 'insert_failed' stats still accounts for this situation, after this patch, the drop counter is bumped whenever we drop packets, so we can watch for unresolved clashes.
---
v3: Florian wants more comments, rename old_ct to 'loser_ct'.
Don't call resolve_clash for dying conntracks.
include/net/netfilter/nf_conntrack_l4proto.h | 3 ++ net/netfilter/nf_conntrack_core.c | 55 ++++++++++++++++++++++++++-- net/netfilter/nf_conntrack_proto_udp.c | 2 + net/netfilter/nf_conntrack_proto_udplite.c | 2 + 4 files changed, 59 insertions(+), 3 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +3 -0
@@ -23,6 +23,9 @@ struct nf_conntrack_l4proto {/* L4 Protocol number. */ u_int8_t l4proto; +/* Resolve clashes on insertion races. */ +bool allow_clash; +/* Try to fill in the third arg: dataoff is offset past network protocol hdr. Return true if possible. */ bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
net/netfilter/nf_conntrack_core.c +52 -3
82 lines not on this page · raw message
net/netfilter/nf_conntrack_proto_udp.c +2 -0
@@ -309,6 +309,7 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = .l3proto = PF_INET, .l4proto = IPPROTO_UDP, .name = "udp", + .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, .print_tuple = udp_print_tuple,
@@ -341,6 +342,7 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = .l3proto = PF_INET6, .l4proto = IPPROTO_UDP, .name = "udp", + .allow_clash = true, .pkt_to_tuple = udp_pkt_to_tuple, .invert_tuple = udp_invert_tuple, .print_tuple = udp_print_tuple,
net/netfilter/nf_conntrack_proto_udplite.c +2 -0
@@ -274,6 +274,7 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = .l3proto = PF_INET, .l4proto = IPPROTO_UDPLITE, .name = "udplite", + .allow_clash = true, .pkt_to_tuple = udplite_pkt_to_tuple, .invert_tuple = udplite_invert_tuple, .print_tuple = udplite_print_tuple,
@@ -306,6 +307,7 @@ static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite6 __read_mostly = .l3proto = PF_INET6, .l4proto = IPPROTO_UDPLITE, .name = "udplite", + .allow_clash = true, .pkt_to_tuple = udplite_pkt_to_tuple, .invert_tuple = udplite_invert_tuple, .print_tuple = udplite_print_tuple,
Signature · 1 line
2.1.4