Skip to content

Commit 8af79d3

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nfnetlink_queue: remove old clash resolution logic
For historical reasons there are two clash resolution spots in netfilter, one in nfnetlink_queue and one in conntrack core. nfnetlink_queue one was added first: If a colliding entry is found, NAT NAT transformation is reversed by calling nat engine again with altered tuple. See commit 368982c ("netfilter: nfnetlink_queue: resolve clash for unconfirmed conntracks") for details. One problem is that nf_reroute() won't take an action if the queueing doesn't occur in the OUTPUT hook, i.e. when queueing in forward or postrouting, packet will be sent via the wrong path. Another problem is that the scenario addressed (2nd UDP packet sent with identical addresses while first packet is still being processed) can also occur without any nfqueue involvement due to threaded resolvers doing A and AAAA requests back-to-back. This lead us to add clash resolution logic to the conntrack core, see commit 6a757c0 ("netfilter: conntrack: allow insertion of clashing entries"). Instead of fixing the nfqueue based logic, lets remove it and let conntrack core handle this instead. Retain the ->update hook for sake of nfqueue based conntrack helpers. We could axe this hook completely but we'd have to split confirm and helper logic again, see commit ee04805 ("netfilter: conntrack: make conntrack userspace helpers work again"). This SHOULD NOT be backported to kernels earlier than v5.6; they lack adequate clash resolution handling. Patch was originally written by Pablo Neira Ayuso. Reported-by: Antonio Ojea <aojea@google.com> Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1766 Signed-off-by: Florian Westphal <fw@strlen.de> Tested-by: Antonio Ojea <aojea@google.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 69e687c commit 8af79d3

File tree

3 files changed

+0
-90
lines changed

3 files changed

+0
-90
lines changed

include/linux/netfilter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,11 @@ int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,
376376
struct nf_conn;
377377
enum nf_nat_manip_type;
378378
struct nlattr;
379-
enum ip_conntrack_dir;
380379

381380
struct nf_nat_hook {
382381
int (*parse_nat_setup)(struct nf_conn *ct, enum nf_nat_manip_type manip,
383382
const struct nlattr *attr);
384383
void (*decode_session)(struct sk_buff *skb, struct flowi *fl);
385-
unsigned int (*manip_pkt)(struct sk_buff *skb, struct nf_conn *ct,
386-
enum nf_nat_manip_type mtype,
387-
enum ip_conntrack_dir dir);
388384
void (*remove_nat_bysrc)(struct nf_conn *ct);
389385
};
390386

net/netfilter/nf_conntrack_core.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,80 +2197,6 @@ static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb)
21972197
nf_conntrack_get(skb_nfct(nskb));
21982198
}
21992199

2200-
static int __nf_conntrack_update(struct net *net, struct sk_buff *skb,
2201-
struct nf_conn *ct,
2202-
enum ip_conntrack_info ctinfo)
2203-
{
2204-
const struct nf_nat_hook *nat_hook;
2205-
struct nf_conntrack_tuple_hash *h;
2206-
struct nf_conntrack_tuple tuple;
2207-
unsigned int status;
2208-
int dataoff;
2209-
u16 l3num;
2210-
u8 l4num;
2211-
2212-
l3num = nf_ct_l3num(ct);
2213-
2214-
dataoff = get_l4proto(skb, skb_network_offset(skb), l3num, &l4num);
2215-
if (dataoff <= 0)
2216-
return NF_DROP;
2217-
2218-
if (!nf_ct_get_tuple(skb, skb_network_offset(skb), dataoff, l3num,
2219-
l4num, net, &tuple))
2220-
return NF_DROP;
2221-
2222-
if (ct->status & IPS_SRC_NAT) {
2223-
memcpy(tuple.src.u3.all,
2224-
ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.all,
2225-
sizeof(tuple.src.u3.all));
2226-
tuple.src.u.all =
2227-
ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.all;
2228-
}
2229-
2230-
if (ct->status & IPS_DST_NAT) {
2231-
memcpy(tuple.dst.u3.all,
2232-
ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.all,
2233-
sizeof(tuple.dst.u3.all));
2234-
tuple.dst.u.all =
2235-
ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.all;
2236-
}
2237-
2238-
h = nf_conntrack_find_get(net, nf_ct_zone(ct), &tuple);
2239-
if (!h)
2240-
return NF_ACCEPT;
2241-
2242-
/* Store status bits of the conntrack that is clashing to re-do NAT
2243-
* mangling according to what it has been done already to this packet.
2244-
*/
2245-
status = ct->status;
2246-
2247-
nf_ct_put(ct);
2248-
ct = nf_ct_tuplehash_to_ctrack(h);
2249-
nf_ct_set(skb, ct, ctinfo);
2250-
2251-
nat_hook = rcu_dereference(nf_nat_hook);
2252-
if (!nat_hook)
2253-
return NF_ACCEPT;
2254-
2255-
if (status & IPS_SRC_NAT) {
2256-
unsigned int verdict = nat_hook->manip_pkt(skb, ct,
2257-
NF_NAT_MANIP_SRC,
2258-
IP_CT_DIR_ORIGINAL);
2259-
if (verdict != NF_ACCEPT)
2260-
return verdict;
2261-
}
2262-
2263-
if (status & IPS_DST_NAT) {
2264-
unsigned int verdict = nat_hook->manip_pkt(skb, ct,
2265-
NF_NAT_MANIP_DST,
2266-
IP_CT_DIR_ORIGINAL);
2267-
if (verdict != NF_ACCEPT)
2268-
return verdict;
2269-
}
2270-
2271-
return NF_ACCEPT;
2272-
}
2273-
22742200
/* This packet is coming from userspace via nf_queue, complete the packet
22752201
* processing after the helper invocation in nf_confirm().
22762202
*/
@@ -2334,17 +2260,6 @@ static int nf_conntrack_update(struct net *net, struct sk_buff *skb)
23342260
if (!ct)
23352261
return NF_ACCEPT;
23362262

2337-
if (!nf_ct_is_confirmed(ct)) {
2338-
int ret = __nf_conntrack_update(net, skb, ct, ctinfo);
2339-
2340-
if (ret != NF_ACCEPT)
2341-
return ret;
2342-
2343-
ct = nf_ct_get(skb, &ctinfo);
2344-
if (!ct)
2345-
return NF_ACCEPT;
2346-
}
2347-
23482263
return nf_confirm_cthelper(skb, ct, ctinfo);
23492264
}
23502265

net/netfilter/nf_nat_core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,6 @@ static const struct nf_nat_hook nat_hook = {
13241324
#ifdef CONFIG_XFRM
13251325
.decode_session = __nf_nat_decode_session,
13261326
#endif
1327-
.manip_pkt = nf_nat_manip_pkt,
13281327
.remove_nat_bysrc = nf_nat_cleanup_conntrack,
13291328
};
13301329

0 commit comments

Comments
 (0)