Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp688807pxv; Thu, 22 Jul 2021 09:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtjQAzi81Q9Z8ot9nv0OseEqD3z43cgjBm+LdUwYLsr4UtHOhvn6mcpZz6Bh/eXbZFWzIF X-Received: by 2002:a92:d6c9:: with SMTP id z9mr492367ilp.134.1626972378408; Thu, 22 Jul 2021 09:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626972378; cv=none; d=google.com; s=arc-20160816; b=E6IuTJECDSENnuGn0LcTSjs7EGMUDSeQY1qL+vVECojxPq6mbHGzQam9Alk8v/4JFS RGSs83ZFoXTBgNL9soYJA7jYeSRK7oWb4/uw080j5WkVJe/o56c/seds/MR7KgUM9SNG OBBE5RtizSPZulO2CAZbGV4Aq/XBQRMNVO2MseEWSRgcx/goCk9Wh9OtX4rk9Kbmffcb SJ+MSBOPLrv69zkm3mKzxCGPmfog79IpCfgvtiAzaFbhTjkmQsO9aLktqm8X2R3uf8/Y djdRUEw3XJ4z7uqsEzuOpCGX7ltthAg1Vo+W0/jmoBdRBP9LJGSvNBNkREA2e7E3hERY TyeA== 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=lY1gJMsU2EQXzle1iwmFa3GbF6/y0G+TbEqZUJgxhf8=; b=T/++CSCekSNgQVhSgH/PULKNzslrVYFKjyWEAW7ZJIVh+UjE9toNMs3PI2sRHq+DAJ YwT4pv4EAVMk/dA35bjAplHptP/9w9BG0Hhf/PfzS8Y5tFVbCPilsPWEz4ZMTwi42/lD yOjsYoAyP4uQsvPCOsZ0WAmtYpmC+H5J2bYAVOmikDIdGZMkeN15tKLO1+Bs577l86iS OZVX85aMBSEVzEs7XOveowKWhRe+8+nFtyBs0mgE6NuBgaLKXsmxGDszg6gRlgjgUCkw /wGmB+2Czjl0hAuDDuACXxrdbT2HSvbjOTSsusypTuKxLh13De8izWWWRRokWWYXnLdN zi5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lmxIcfa8; 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 g17si29055734jaq.116.2021.07.22.09.46.06; Thu, 22 Jul 2021 09:46:18 -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=lmxIcfa8; 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 S233908AbhGVQDS (ORCPT + 99 others); Thu, 22 Jul 2021 12:03:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:39220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233319AbhGVQBz (ORCPT ); Thu, 22 Jul 2021 12:01:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B5838613E7; Thu, 22 Jul 2021 16:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626972149; bh=XbBtprAWeCdGxXUpJiT+AWYH8omDISnp2/WOiKinfz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lmxIcfa8JgrANEjMqyV9DZWnEdGY7UmazE0PMbJlGg+L0sRDoi8phjfna729vl7/9 LQBsTBP2HRAJSv6nJqA5POoJvNJ8SD1ItPJh4mSf990be3G/mgLHE5pzzbYwwEao/9 cS5NS3QzSgGuX5vUxfk/Uh5Jh8mjYguaDTW+Wh+E= 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.10 118/125] ipv6: tcp: drop silly ICMPv6 packet too big messages Date: Thu, 22 Jul 2021 18:31:49 +0200 Message-Id: <20210722155628.623033606@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210722155624.672583740@linuxfoundation.org> References: <20210722155624.672583740@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 @@ -1730,6 +1730,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,