Skip to contentSkip to conversation

selftests: netfilter: check icmp pkttoobig errors are set as related

PATCH Applied Florian Westphal 2 participants 4 messages Mar 25, 2019 – Apr 13, 2019

Subsystems (3)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/2 selftests: netfilter: check icmp pkttoobig errors are set as related

When an icmp error such as pkttoobig is received, conntrack checks if the "inner" header (header of packet that did not fit link mtu) is matches an existing connection, and, if so, sets that packet as being related to the conntrack entry it found.

It was recently reported that this "related" setting also works if the inner header is from another, different connection (i.e., artificial/forged icmp error).

Add a test, followup patch will add additional "inner dst matches outer dst in reverse direction" check before setting related state.

---
 tools/testing/selftests/netfilter/Makefile    |   2 +-
 .../netfilter/conntrack_icmp_related.sh       | 283 ++++++++++++++++++
 2 files changed, 284 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/netfilter/conntrack_icmp_related.sh
tools/testing/selftests/netfilter/Makefile +1 -1
index c9ff2b47bd1c..a37cb1192c6a 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for netfilter selftests
 
-TEST_PROGS := nft_trans_stress.sh nft_nat.sh
+TEST_PROGS := nft_trans_stress.sh nft_nat.sh conntrack_icmp_related.sh
 
 include ../lib.mk
tools/testing/selftests/netfilter/conntrack_icmp_related.sh new file +283 -0

283 lines not on this page · raw message

Signature · 1 line
2.19.2
author maintainer
#1 lore raw

PATCH 2/2 netfilter: conntrack: don't set related state for different outer address

Luca Moro says:
------
The issue lies in the filtering of ICMP and ICMPv6 errors that include an inner IP datagram.
For these packets, icmp_error_message() extract the ICMP error and inner layer to search of a known state.
If a state is found the packet is tagged as related (IP_CT_RELATED).

The problem is that there is no correlation check between the inner and outer layer of the packet.
So one can encapsulate an error with an inner layer matching a known state, while its outer layer is directed to a filtered host.
In this case the whole packet will be tagged as related.
This has various implications from a rule bypass (if a rule to related trafic is allow), to a known state oracle.

Unfortunately, we could not find a real statement in a RFC on how this case should be filtered.
The closest we found is RFC5927 (Section 4.3) but it is not very clear.

A possible fix would be to check that the inner IP source is the same than the outer destination.

We believed this kind of attack was not documented yet, so we started to write a blog post about it.
You can find it attached to this mail (sorry for the extract quality). It contains more technical details, PoC and discussion about the identified behavior.
We discovered later that
https://www.gont.com.ar/papers/filtering-of-icmp-error-messages.pdf
described a similar attack concept in 2004 but without the stateful filtering in mind.
-----

This implements above suggested fix:
In icmp(v6) error handler, take outer destination address, then pass that into the common function that does the "related" association.

After obtaining the nf_conn of the matching inner-headers connection, check that the destination address of the opposite direction tuple is the same as the outer address and only set RELATED if thats the case.

---
 include/net/netfilter/nf_conntrack_l4proto.h |  6 ++
 net/netfilter/nf_conntrack_proto_icmp.c      | 93 +++++++++++++++-----
 net/netfilter/nf_conntrack_proto_icmpv6.c    | 52 ++---------
 3 files changed, 84 insertions(+), 67 deletions(-)
include/net/netfilter/nf_conntrack_l4proto.h +6 -0
index 778087591983..a49edfdf47e8 100644
@@ -75,6 +75,12 @@ bool nf_conntrack_invert_icmp_tuple(struct nf_conntrack_tuple *tuple,
 bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple,
 				      const struct nf_conntrack_tuple *orig);
 
+int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,
+			    unsigned int dataoff,
+			    const struct nf_hook_state *state,
+			    u8 l4proto,
+			    union nf_inet_addr *outer_daddr);
+
 int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
 			      struct sk_buff *skb,
 			      unsigned int dataoff,
net/netfilter/nf_conntrack_proto_icmp.c +72 -21

139 lines not on this page · raw message

net/netfilter/nf_conntrack_proto_icmpv6.c +6 -46

70 lines not on this page · raw message

Signature · 1 line
2.19.2
maintainer Applied
#2 lore raw

Re: [PATCH nf 2/2] netfilter: conntrack: don't set related state for different outer address

Applied, thanks.

maintainer Applied
#3 lore raw
In reply to Florian Westphal
Quoted 11 lines · Florian Westphal

When an icmp error such as pkttoobig is received, conntrack checks if the "inner" header (header of packet that did not fit link mtu) is matches an existing connection, and, if so, sets that packet as being related to the conntrack entry it found.

It was recently reported that this "related" setting also works if the inner header is from another, different connection (i.e., artificial/forged icmp error).

Add a test, followup patch will add additional "inner dst matches outer dst in reverse direction" check before setting related state.

Applied, thanks.