Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp697164pxv; Thu, 22 Jul 2021 09:58:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXxYplYUklgeU/G325zxQGjoqC9kP1cLwpx2P3uxdKw4peQBP2BUJlNA8ndMhDA0aQZWtX X-Received: by 2002:aa7:cb9a:: with SMTP id r26mr732909edt.78.1626973089462; Thu, 22 Jul 2021 09:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626973089; cv=none; d=google.com; s=arc-20160816; b=v1vGaUDtHeV+p8V2M4SykvLGMlUtSZzdL2eUrxeKs8do24tP1Dp1p0TTFZkaVZVPaX pDoEoW7IngZyUD9IgTQ5FrOuFCFJPPk4lMA+F83adt9YF5pOqC1t1xPeZkx6ozt7WeBP 5tuOs83/1LN2OIpR/IsOt+NI0A4BBJDz2m/pntIavqr+QlNaWsB9ST2ahEi5wMqmdkdw LvMbAKDUHNkDsfcu74t661TWLbTMR1cSD0U6C8Did+9C8MyM8mwMexdSQgKjfx6A9ie7 HieAL58S+dPR5sisxeLRDDbnZkSUSR7+D231yEhtnBxE3rp5EDHj2Nx77ErXOZrLJlaG Jzmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2YUrfvAGoiLaPh2cr8Y88exs6q9SHmmmINh/HiodvHg=; b=YGGAaPyJc8EYa5rBmW9P+2yjOXDnn1A9LAguyEa3Ba+gF/9Qms7keYe+U+XxRPgvIv xmVIyeeFH+6vtaeoIAQ1k29FI3wESf95BzP9ciBBqShBJZsucohddA2/dT7ai+guaHSM YxcKm/0eoMofYhKaC/Ftom4a0iWWk0VPE7PypttRCw6aEZrbkbJ6yBvup/1+Fq/XW5yy c2DMeIMgLlOdvo8ycO/frltMbKhYAlmUS3HPcUKrPJ81QV+nWBd6+RTF7P420OWcQHPa c6P8bQMZJeb3A8Nne7P6HU6cDO2JQeHlJ86OF2/Bu7VT+hx30r5eup7I4Yd4iXhHc5ko 4nTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PFk+8dMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qb27si32105672ejc.33.2021.07.22.09.57.46; Thu, 22 Jul 2021 09:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PFk+8dMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234391AbhGVQNz (ORCPT + 99 others); Thu, 22 Jul 2021 12:13:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:53030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235009AbhGVQI7 (ORCPT ); Thu, 22 Jul 2021 12:08:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D7CE261D9A; Thu, 22 Jul 2021 16:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626972530; bh=63pQ7qwxvMD+8aw8OmACJzum0oF3DtFhzTItWntAbyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFk+8dMdjldp3oq8sQiZjhax0TFXaVoJI/oNVueW+OmH3EtEaIMn2iCrQWBHMT8sT sI3hsPNeZhGesEPQU1oJHaIXRodzTKLdlYehXGuiVBTYSB0Mo5JO+P/zqNxdaPrGNg C1O2kCzTpe2GAmdYtALmknmccJyjpS+MbKUV2bzw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , =?UTF-8?q?Maciej=20=C5=BBenczykowski?= , Martin KaFai Lau , "David S. Miller" Subject: [PATCH 5.13 146/156] ipv6: tcp: drop silly ICMPv6 packet too big messages Date: Thu, 22 Jul 2021 18:32:01 +0200 Message-Id: <20210722155633.064467828@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210722155628.371356843@linuxfoundation.org> References: <20210722155628.371356843@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit c7bb4b89033b764eb07db4e060548a6311d801ee upstream. While TCP stack scales reasonably well, there is still one part that can be used to DDOS it. IPv6 Packet too big messages have to lookup/insert a new route, and if abused by attackers, can easily put hosts under high stress, with many cpus contending on a spinlock while one is stuck in fib6_run_gc() ip6_protocol_deliver_rcu() icmpv6_rcv() icmpv6_notify() tcp_v6_err() tcp_v6_mtu_reduced() inet6_csk_update_pmtu() ip6_rt_update_pmtu() __ip6_rt_update_pmtu() ip6_rt_cache_alloc() ip6_dst_alloc() dst_alloc() ip6_dst_gc() fib6_run_gc() spin_lock_bh() ... Some of our servers have been hit by malicious ICMPv6 packets trying to _increase_ the MTU/MSS of TCP flows. We believe these ICMPv6 packets are a result of a bug in one ISP stack, since they were blindly sent back for _every_ (small) packet sent to them. These packets are for one TCP flow: 09:24:36.266491 IP6 Addr1 > Victim ICMP6, packet too big, mtu 1460, length 1240 09:24:36.266509 IP6 Addr1 > Victim ICMP6, packet too big, mtu 1460, length 1240 09:24:36.316688 IP6 Addr1 > Victim ICMP6, packet too big, mtu 1460, length 1240 09:24:36.316704 IP6 Addr1 > Victim ICMP6, packet too big, mtu 1460, length 1240 09:24:36.608151 IP6 Addr1 > Victim ICMP6, packet too big, mtu 1460, length 1240 TCP stack can filter some silly requests : 1) MTU below IPV6_MIN_MTU can be filtered early in tcp_v6_err() 2) tcp_v6_mtu_reduced() can drop requests trying to increase current MSS. This tests happen before the IPv6 routing stack is entered, thus removing the potential contention and route exhaustion. Note that IPv6 stack was performing these checks, but too late (ie : after the route has been added, and after the potential garbage collect war) v2: fix typo caught by Martin, thanks ! v3: exports tcp_mtu_to_mss(), caught by David, thanks ! Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reviewed-by: Maciej Żenczykowski Cc: Martin KaFai Lau Acked-by: Martin KaFai Lau Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/tcp_output.c | 1 + net/ipv6/tcp_ipv6.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1732,6 +1732,7 @@ int tcp_mtu_to_mss(struct sock *sk, int return __tcp_mtu_to_mss(sk, pmtu) - (tcp_sk(sk)->tcp_header_len - sizeof(struct tcphdr)); } +EXPORT_SYMBOL(tcp_mtu_to_mss); /* Inverse of above */ int tcp_mss_to_mtu(struct sock *sk, int mss) --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -348,11 +348,20 @@ failure: static void tcp_v6_mtu_reduced(struct sock *sk) { struct dst_entry *dst; + u32 mtu; if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) return; - dst = inet6_csk_update_pmtu(sk, READ_ONCE(tcp_sk(sk)->mtu_info)); + mtu = READ_ONCE(tcp_sk(sk)->mtu_info); + + /* Drop requests trying to increase our current mss. + * Check done in __ip6_rt_update_pmtu() is too late. + */ + if (tcp_mtu_to_mss(sk, mtu) >= tcp_sk(sk)->mss_cache) + return; + + dst = inet6_csk_update_pmtu(sk, mtu); if (!dst) return; @@ -433,6 +442,8 @@ static int tcp_v6_err(struct sk_buff *sk } if (type == ICMPV6_PKT_TOOBIG) { + u32 mtu = ntohl(info); + /* We are not interested in TCP_LISTEN and open_requests * (SYN-ACKs send out by Linux are always <576bytes so * they should go through unfragmented). @@ -443,7 +454,11 @@ static int tcp_v6_err(struct sk_buff *sk if (!ip6_sk_accept_pmtu(sk)) goto out; - WRITE_ONCE(tp->mtu_info, ntohl(info)); + if (mtu < IPV6_MIN_MTU) + goto out; + + WRITE_ONCE(tp->mtu_info, mtu); + if (!sock_owned_by_user(sk)) tcp_v6_mtu_reduced(sk); else if (!test_and_set_bit(TCP_MTU_REDUCED_DEFERRED,