Skip to contentSkip to conversation

netfilter: nat: remove incorrect debug assert

PATCH In review Florian Westphal 3 participants 8 messages Feb 8, 2017 – Mar 3, 2017

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nat: remove incorrect debug assert

The comment is incorrect, this function does see fragments when IP_NODEFRAG is used. Remove the wrong assertion.

As conntrack doesn't track fragments skb->nfct will be null and no nat is performed.

---
 net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 5 -----
 1 file changed, 5 deletions(-)
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -5
index f8aad03d674b..6f5e8d01b876 100644
@@ -255,11 +255,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,
 	/* maniptype == SRC for postrouting. */
 	enum nf_nat_manip_type maniptype = HOOK2MANIP(state->hook);
 
-	/* We never see fragments: conntrack defrags on pre-routing
-	 * and local-out, and nf_nat_out protects post-routing.
-	 */
-	NF_CT_ASSERT(!ip_is_fragment(ip_hdr(skb)));
-
 	ct = nf_ct_get(skb, &ctinfo);
 	/* Can't track?  It's not due to stress, or conntrack would
 	 * have dropped it.  Hence it's the user's responsibilty to
Signature · 1 line
2.10.2
#1 lore raw
Quoted 5 lines · Florian Westphal

The comment is incorrect, this function does see fragments when IP_NODEFRAG is used. Remove the wrong assertion.

As conntrack doesn't track fragments skb->nfct will be null and no nat is performed.

With IP_NODEFRAG, ipv4_conntrack_defrag() will just accept the packet.

So the first fragment will get into nf_conntrack_in(), and I think, if enough information is there in place, it will get a ct object. Follow up fragments with offset != 0 which doesn't contain headers will definitely not get a ct object.

Shouldn't handle case this by attaching a template conntrack? Currently this IP_NODEFRAG case is going through as invalid traffic.

My impression is that we're handling this case in a sloppy way, am I missing anything?

Quoted 29 lines
---
 net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 5 -----
 1 file changed, 5 deletions(-)
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -5
index f8aad03d674b..6f5e8d01b876 100644
@@ -255,11 +255,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,
 	/* maniptype == SRC for postrouting. */
 	enum nf_nat_manip_type maniptype = HOOK2MANIP(state->hook);
 
-	/* We never see fragments: conntrack defrags on pre-routing
-	 * and local-out, and nf_nat_out protects post-routing.
-	 */
-	NF_CT_ASSERT(!ip_is_fragment(ip_hdr(skb)));
-
 	ct = nf_ct_get(skb, &ctinfo);
 	/* Can't track?  It's not due to stress, or conntrack would
 	 * have dropped it.  Hence it's the user's responsibilty to
Signature · 6 lines
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#2 lore raw
Quoted 11 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal

The comment is incorrect, this function does see fragments when IP_NODEFRAG is used. Remove the wrong assertion.

As conntrack doesn't track fragments skb->nfct will be null and no nat is performed.

With IP_NODEFRAG, ipv4_conntrack_defrag() will just accept the packet.

So the first fragment will get into nf_conntrack_in(), and I think, if enough information is there in place, it will get a ct object.

ipv4_get_l4proto():

       if (iph->frag_off & htons(IP_OFFSET))
              return -NF_ACCEPT;

so yes, you are right, first packet will be tracked in this case.

Quoted 8 lines

up fragments with offset != 0 which doesn't contain headers will definitely not get a ct object.

Shouldn't handle case this by attaching a template conntrack? Currently this IP_NODEFRAG case is going through as invalid traffic.

My impression is that we're handling this case in a sloppy way, am I missing anything?

What would you do instead?

We currently have a suboptimal handling of such cases, but I don't see how we can change it without (possibly) breaking existing setups. I also don't see how alternative handling is 'better'.

Tagging it as UNTRACKED seems wrong because its used for cases where we could track but decide against it, e.g. due to -j NOTRACK or explicit tracker whitelist (icmpv6 neigh for instance).

Documentation says (iptables-extensions):

INVALID The packet is associated with no known connection. UNTRACKED The packet is not tracked at all, which happens if you explictly untrack it by using -j CT --notrack in the raw table.

(XXX: needs a sentence wrt. icmpv6...)

So current behaviour at least appears consistent with documentation.

Quoted 8 lines
Quoted 8 lines
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -0

ick_inndex f8aad03d674b..6f5e8d01b876 100644

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -0
@@ -255,11 +255,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,
 	/* maniptype == SRC for postrouting. */
 	enum nf_nat_manip_type maniptype = HOOK2MANIP(state->hook);
 
Quoted 5 lines

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c nf_nat_ipv4_fn(void *priv, struct sk_buff *skb, · line 262

Quoted 5 lines
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -5
-	/* We never see fragments: conntrack defrags on pre-routing
-	 * and local-out, and nf_nat_out protects post-routing.
-	 */
-	NF_CT_ASSERT(!ip_is_fragment(ip_hdr(skb)));
-

We could make this a explicit test+return but that seems weird too, we would track the first fragment but would not nat.

However, changing test to if (iph->frag_off) return -NF_ACCEPT seems wrong too because we have enough info to track. OTOH, this only happens with HDRINCL+raw socket so perhaps we shouldn't care about this and just change ipv4 l3 tracker to ignore all packets w. iph->frag_off set.

#3 lore raw
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal

The comment is incorrect, this function does see fragments when IP_NODEFRAG is used. Remove the wrong assertion.

As conntrack doesn't track fragments skb->nfct will be null and no nat is performed.

With IP_NODEFRAG, ipv4_conntrack_defrag() will just accept the packet.

Quoted 8 lines
Quoted 2 lines

So the first fragment will get into nf_conntrack_in(), and I think, if enough information is there in place, it will get a ct object.

ipv4_get_l4proto():

       if (iph->frag_off & htons(IP_OFFSET))
              return -NF_ACCEPT;

so yes, you are right, first packet will be tracked in this case.

With NAT in place, this also means the first packet of a flow gets mangled, while follow up don't.

Probably change that spot above to use ip_is_fragment()?

Quoted 6 lines
Quoted 6 lines

up fragments with offset != 0 which doesn't contain headers will definitely not get a ct object.

Shouldn't handle case this by attaching a template conntrack? Currently this IP_NODEFRAG case is going through as invalid traffic.

Quoted 7 lines
Quoted 2 lines

My impression is that we're handling this case in a sloppy way, am I missing anything?

What would you do instead?

We currently have a suboptimal handling of such cases, but I don't see how we can change it without (possibly) breaking existing setups.

AFAIK, only IP_NODEFRAG locally generated packets would get affected. I wonder how this option is used (network testing?). I cannot come up with any reasonable stateful ruleset that may work with this. With a stateful ruleset in place, the first packet will go through and follow up would be INVALID. There are tons of rulesets outthere simply logging and dropping invalid ones.

Look, the first packet create an entry in SYN_SENT state, that just expires later on.

Quoted 1 line

I also don't see how alternative handling is 'better'.

We could just handle all the packets in a flow in the same way, so they all go through INVALID.

#4 lore raw
In reply to Florian Westphal
Quoted 1 line · Florian Westphal

Pablo Neira Ayuso <[email protected]> wrote:

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -0

ick_inndex f8aad03d674b..6f5e8d01b876 100644

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -0
@@ -255,11 +255,6 @@ nf_nat_ipv4_fn(void *priv, struct sk_buff *skb,
 	/* maniptype == SRC for postrouting. */
 	enum nf_nat_manip_type maniptype = HOOK2MANIP(state->hook);
 
Quoted 8 lines
Quoted 5 lines

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c nf_nat_ipv4_fn(void *priv, struct sk_buff *skb, · line 262

Quoted 5 lines
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -5
-	/* We never see fragments: conntrack defrags on pre-routing
-	 * and local-out, and nf_nat_out protects post-routing.
-	 */
-	NF_CT_ASSERT(!ip_is_fragment(ip_hdr(skb)));
-

We could make this a explicit test+return but that seems weird too, we would track the first fragment but would not nat.

Right, that test+return just for this is weird.

Quoted 4 lines

However, changing test to if (iph->frag_off) return -NF_ACCEPT seems wrong too because we have enough info to track. OTOH, this only happens with HDRINCL+raw socket so perhaps we shouldn't care about this and just change ipv4 l3 tracker to ignore all packets w. iph->frag_off set.

Florian, unless you rise your hand, I'm going to take this patch so we at least fix splats here. I still have the impression that this setsockopt() option and its interaction with netfilter is broken at many levels.

author maintainer
#5 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 4 lines

However, changing test to if (iph->frag_off) return -NF_ACCEPT seems wrong too because we have enough info to track. OTOH, this only happens with HDRINCL+raw socket so perhaps we shouldn't care about this and just change ipv4 l3 tracker to ignore all packets w. iph->frag_off set.

Florian, unless you rise your hand, I'm going to take this patch so we at least fix splats here. I still have the impression that this setsockopt() option and its interaction with netfilter is broken at many levels.

Hmmm, I think we should disable tracking of all fragmented packets, or at least disable NAT of all fragmented packets.

If we NAT 1st packet only then frag reasm won't complete anyway.

#6 lore raw
Quoted 11 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso
Quoted 4 lines

However, changing test to if (iph->frag_off) return -NF_ACCEPT seems wrong too because we have enough info to track. OTOH, this only happens with HDRINCL+raw socket so perhaps we shouldn't care about this and just change ipv4 l3 tracker to ignore all packets w. iph->frag_off set.

Florian, unless you rise your hand, I'm going to take this patch so we at least fix splats here. I still have the impression that this setsockopt() option and its interaction with netfilter is broken at many levels.

Quoted 4 lines

Hmmm, I think we should disable tracking of all fragmented packets, or at least disable NAT of all fragmented packets.

If we NAT 1st packet only then frag reasm won't complete anyway.

Right. Would you give a shoot at this? If you do, I'd appreciate. Thanks.

#7 lore raw
In reply to Florian Westphal
Quoted 6 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines

However, changing test to if (iph->frag_off) return -NF_ACCEPT seems wrong too because we have enough info to track. OTOH, this only happens with HDRINCL+raw socket so perhaps we shouldn't care about this and just change ipv4 l3 tracker to ignore all packets w. iph->frag_off set.

Quoted 7 lines
Quoted 4 lines

Florian, unless you rise your hand, I'm going to take this patch so we at least fix splats here. I still have the impression that this setsockopt() option and its interaction with netfilter is broken at many levels.

Hmmm, I think we should disable tracking of all fragmented packets, or at least disable NAT of all fragmented packets.

I think that is the safest solution, i.e. disable tracking and NAT for all fragmented packets.

Quoted 1 line

If we NAT 1st packet only then frag reasm won't complete anyway.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary