diff mbox

[RFC,net-next] ipv6: stop sending PTB packets for MTU < 1280

Message ID 1409005545-24910-2-git-send-email-hagen@jauu.net
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Hagen Paul Pfeifer Aug. 25, 2014, 10:25 p.m. UTC
Reduce the attack vector and stop generating ICMPv6 packet to big for
packets smaller then the minimal required IPv6 MTU.

See
http://tools.ietf.org/html/draft-gont-6man-deprecate-atomfrag-generation-00

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 net/ipv6/route.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Hannes Frederic Sowa Aug. 25, 2014, 10:47 p.m. UTC | #1
Hi Hagen,

On Di, 2014-08-26 at 00:25 +0200, Hagen Paul Pfeifer wrote:
> Reduce the attack vector and stop generating ICMPv6 packet to big for
> packets smaller then the minimal required IPv6 MTU.
> 
> See
> http://tools.ietf.org/html/draft-gont-6man-deprecate-atomfrag-generation-00

I wonder if we should wait until this gets RFC status?

I very much welcome this decision! I already raised this problem some
time ago:
http://lists.openwall.net/netdev/2013/12/31/17

I wonder if we should add a mode alike ipv4 ip_no_pmtu_disc mode for
ipv6:

ip_no_pmtu_disc - INTEGER
        Disable Path MTU Discovery. If enabled in mode 1 and a
        fragmentation-required ICMP is received, the PMTU to this
        destination will be set to min_pmtu (see below). You will need
        to raise min_pmtu to the smallest interface MTU on your system
        manually if you want to avoid locally generated fragments.

        In mode 2 incoming Path MTU Discovery messages will be
        discarded. Outgoing frames are handled the same as in mode 1,
        implicitly setting IP_PMTUDISC_DONT on every created socket.

        Mode 3 is a hardend pmtu discover mode. The kernel will only
        accept fragmentation-needed errors if the underlying protocol
        can verify them besides a plain socket lookup. Current
        protocols for which pmtu events will be honored are TCP, SCTP
        and DCCP as they verify e.g. the sequence number or the
        association. This mode should not be enabled globally but is
        only intended to secure e.g. name servers in namespaces where
        TCP path mtu must still work but path MTU information of other
        protocols should be discarded. If enabled globally this mode
        could break other protocols.

        Possible values: 0-3
        Default: FALSE

Not sure yet...

> Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
> ---
>  net/ipv6/route.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index f74b041..84ebacd 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1154,12 +1154,9 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
>  		struct net *net = dev_net(dst->dev);
>  
>  		rt6->rt6i_flags |= RTF_MODIFIED;
> -		if (mtu < IPV6_MIN_MTU) {
> -			u32 features = dst_metric(dst, RTAX_FEATURES);
> +		if (mtu < IPV6_MIN_MTU)
>  			mtu = IPV6_MIN_MTU;
> -			features |= RTAX_FEATURE_ALLFRAG;
> -			dst_metric_set(dst, RTAX_FEATURES, features);
> -		}
> +
>  		dst_metric_set(dst, RTAX_MTU, mtu);
>  		rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
>  	}

This patch is a starter, yes. We can now get rid of the dst_allfrag
function altogether.

Thanks,
Hannes


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hagen Paul Pfeifer Aug. 26, 2014, 8:06 a.m. UTC | #2
On 26 August 2014 00:47, Hannes Frederic Sowa
<hannes@stressinduktion.org> wrote:

Hey Hannes

> I wonder if we should wait until this gets RFC status?

Yes, we should wait until we get Fernando's go (based on v6ops
discussion & consensus). But the discussions seem to boils down to
this action (remove IPv6 PTB generation < 1280). If so we probably
don't want to wait two years with an open "protocol bug".

> I very much welcome this decision! I already raised this problem some
> time ago:
> http://lists.openwall.net/netdev/2013/12/31/17

Thank you for the pointer

> I wonder if we should add a mode alike ipv4 ip_no_pmtu_disc mode for
> ipv6:

Not sure, we should discuss this here (netdev). I tend to remove the
functionality completely. Any use cases where it makes sense to keep
this?

> This patch is a starter, yes. We can now get rid of the dst_allfrag
> function altogether.

Yes right, I am aware of this. Depending on the discussion we should
get rid of the allfrags code or not. Let's see. Thank you Hannes for
the comments.

Hagen
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fernando Gont Aug. 27, 2014, 8:33 p.m. UTC | #3
On 08/25/2014 07:47 PM, Hannes Frederic Sowa wrote:
> Hi Hagen,
> 
> On Di, 2014-08-26 at 00:25 +0200, Hagen Paul Pfeifer wrote:
>> Reduce the attack vector and stop generating ICMPv6 packet to big for
>> packets smaller then the minimal required IPv6 MTU.
>>
>> See
>> http://tools.ietf.org/html/draft-gont-6man-deprecate-atomfrag-generation-00
> 
> I wonder if we should wait until this gets RFC status?
> 
> I very much welcome this decision! I already raised this problem some
> time ago:
> http://lists.openwall.net/netdev/2013/12/31/17

FWIW, this issue you reported is related, but different from the one
I've described. The one I've described is based on sending ICMPv6
PTB<1280.   RFC2460 states that when you receive an ICMPv6 PTB<1280 you
should add a Fragment Header to all packets sent to that destination
(i.e., produce the so called "IPv6 atomic fragments").

These "atomic fragments" have an offset=0, and MF=0 -- i.e., they are
not really fragmented.

Hence the trivial way to mitigate this attack is to drop incoming ICMPv6
PTB1280 (or, at the very least, don't react to them by sending all
subsequent packets with a Fragment Header).

Thanks!

Best regards,
Hagen Paul Pfeifer Aug. 27, 2014, 8:57 p.m. UTC | #4
On 27 August 2014 22:33, Fernando Gont <fgont@si6networks.com> wrote:

> Hence the trivial way to mitigate this attack is to drop incoming ICMPv6
> PTB1280 (or, at the very least, don't react to them by sending all
> subsequent packets with a Fragment Header).

Any news from the v6ops people - what is your suggestion Fernando?
Should we wait for more v6ops input?

Hagen
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hannes Frederic Sowa Aug. 27, 2014, 11:07 p.m. UTC | #5
Hi Fernando,

On Mi, 2014-08-27 at 17:33 -0300, Fernando Gont wrote:
> On 08/25/2014 07:47 PM, Hannes Frederic Sowa wrote:
> > Hi Hagen,
> > 
> > On Di, 2014-08-26 at 00:25 +0200, Hagen Paul Pfeifer wrote:
> >> Reduce the attack vector and stop generating ICMPv6 packet to big for
> >> packets smaller then the minimal required IPv6 MTU.
> >>
> >> See
> >> http://tools.ietf.org/html/draft-gont-6man-deprecate-atomfrag-generation-00
> > 
> > I wonder if we should wait until this gets RFC status?
> > 
> > I very much welcome this decision! I already raised this problem some
> > time ago:
> > http://lists.openwall.net/netdev/2013/12/31/17
> 
> FWIW, this issue you reported is related, but different from the one
> I've described. The one I've described is based on sending ICMPv6
> PTB<1280.   RFC2460 states that when you receive an ICMPv6 PTB<1280 you
> should add a Fragment Header to all packets sent to that destination
> (i.e., produce the so called "IPv6 atomic fragments").
> 
> These "atomic fragments" have an offset=0, and MF=0 -- i.e., they are
> not really fragmented.

Sure, in this specific thread I was mostly concerned with DNS packet
blackholing in forwarding path. Because of DNSSEC packets also easily
getting bigger than 1280 bytes this effect could also hurt people
without dst_allfrag being true (the function which checks if atomic
fragments are in effect along a route because of a <1280 PtB
notification before). At that time, I had atomic fragments in mind, they
just weren't that much of a problem as we are not concerned about them
in forwarding path and don't check for dst_allfrag there. But we also
had other changes to harden the host side in regard to PtB acceptance,
specifically this also helps to harden against spoofed PtB with mtu <
1280, see below.

At former times Linux used path mtu information in the forwarding path,
so not only the end system would be vulnerable, but all systems along
the way if one could sneak in a PtB error to reduce path mtu. This could
get used to inject PtB notifications even into full quadruple looked up
connections by just letting the router returning the PtB error instead
of directly spoofing it. At least there is no way you could generate
PtBs with mtus smaller than 1280, so no problems in regard to atomic
fragments.

You still had to ensure to hit a live socket, though. On DNS servers
with UDP this could be easily done because on unconnected sockets we
only do a 2-tuple lookup on the socket to validate the PtB error, so it
was easily possible to hit unconnected DNS servers ports on a router.

For protection on the host side:

In case you have an IPv6 socket and you want to ensure that no PtB
information will be accepted by it you already can set IP_MTU_DISCOVER
to IP_PMTUDISC_OMIT (or to IP_PMTUDISC_INTERFACE but kernel will then
start to reject creating fragments at all and will signal error to user
space). This is already implemented in unbound and hopefully already
found its way into BIND to protect DNS.

> Hence the trivial way to mitigate this attack is to drop incoming ICMPv6
> PTB1280 (or, at the very least, don't react to them by sending all
> subsequent packets with a Fragment Header).

Yes, atomic fragments aggravate this problem.

In retrospect, I don't know about other operationg systems, at that time
I only checked Linux and FreeBSD:

FreeBSD only uses interface MTU to check if PtB should be generated in
forwarding path.
Linux used to check path mtu but I converted that to checks for
interface mtu only in fwd path, too.

FreeBSD only accepts PtB information for TCP connections where the inner
data of the ICMP error matches the full quadruple of a tcp connected
socket. FreeBSD also validates that the ICMP(v6) is in the TCP window.

FreeBSD does not deal with PtB information on UDP sockets at all!

Linux does the same for TCP sockets (also checks windowing information).
But Linux also accepts 2-tuple UDP PtB errors (unconnected sockets),
this is now configurable on a per socket basis but we don't have a way
to turn this mode on globally as this is possible for IPv4.

That said, it is not that easy to forge PtB information any more. Only
systems where unconnected UDP sockets are exposed may be easily attacked
(but this is still a big enough attack vector). On TCP connections one
would need to spray a lot of packets against those hosts to match full
quadruple and get into the TCP window.

Bye,
Hannes


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index f74b041..84ebacd 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1154,12 +1154,9 @@  static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 		struct net *net = dev_net(dst->dev);
 
 		rt6->rt6i_flags |= RTF_MODIFIED;
-		if (mtu < IPV6_MIN_MTU) {
-			u32 features = dst_metric(dst, RTAX_FEATURES);
+		if (mtu < IPV6_MIN_MTU)
 			mtu = IPV6_MIN_MTU;
-			features |= RTAX_FEATURE_ALLFRAG;
-			dst_metric_set(dst, RTAX_FEATURES, features);
-		}
+
 		dst_metric_set(dst, RTAX_MTU, mtu);
 		rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
 	}