Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp867382pxb; Tue, 1 Feb 2022 12:04:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKtEK+kJvRo8gG2/8eehXAypgqeJ78v7LaVQm6uvWcF3/zwZ2Y6p4bwl8Au3qitLMBQf1D X-Received: by 2002:a17:906:48d0:: with SMTP id d16mr22316781ejt.734.1643745874073; Tue, 01 Feb 2022 12:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745874; cv=none; d=google.com; s=arc-20160816; b=A7LZ7wwbn0rM6iyZ9pHE/BWXxkCOdirYqSAT8HsmAM/VkbH+sSj6HSLffd/lf+edkF FZHbnZJu1cnuL5hKER/JxjFxRm+zCrrJioMfsjU5WqAYvLS7Bu+pSfGyz8I3eY1flzag Vi4EA6SSCgcqkCV89dGUUae+i813uMpBTKRwfzHakVNjonBakdmpM2tIhR3sURIgxjZc OQgOuCCSn3yGMtXJsaHFIuwPqpjnn862JYMbj6iWvjerkQ0USJr1XdxEp7nuja8lRBxF R/8E+Ugm9rjIIgzhGRTYJKIx6AeQ7ylsfIuK0OIYOWTNfxW0JRHixNni+/S1nEBlGfpR Enfw== 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=JjbJ3sOpe0up6qsbC++QG+eForVu595i6XGn11uc6P4=; b=kPEjvhkIj30GLnnn2bL8EqwIq3+z/1iJQjO1lvluGfX0fodbc0+mM3lTGMKOK9YzhF xv8zjW8doadBnD3j08JzS6xwHZ5gWhjbY/OGWTwdidO0V3qMsyHBUgj8cjt/yM2+ibfl e2pRXzcE+Ih+KYnesAbMQIoZsppMLJcqAcARo/o4Di9iSErrJR1PCnDhYEZpkfhtnPrL mFEop/HuMMYmM4223mR13mYCO6sj96buYc/iGRLusADyt+AL9ALXoA4j739O/lR91xew HDdZkoDsu74javxXsYRHHjrq/CA1AUQJwzGVW8TYWimsODPcfA3zVfq7RGDY0CdP+OpQ i+pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XmINA14d; 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 qk8si8141658ejc.166.2022.02.01.12.04.08; Tue, 01 Feb 2022 12:04:34 -0800 (PST) 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=XmINA14d; 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 S1359232AbiAaLOo (ORCPT + 99 others); Mon, 31 Jan 2022 06:14:44 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:53918 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359584AbiAaLGG (ORCPT ); Mon, 31 Jan 2022 06:06:06 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AC82FB82A70; Mon, 31 Jan 2022 11:06:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0C14C340E8; Mon, 31 Jan 2022 11:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627163; bh=YCch70a1xuaiG3umi4jdkuzRFuQOW2nax+is+noWyYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XmINA14dD37ib8KiUUEo7RKt5viWzzqZyFAkwCIckNbgXcSMb4vz4UbcuHwlUWAOL xCFxqSHcgqgA38Hbf2Uvdb1wFlu1CMPk2Eo5q7b5M+1ENvBD8BzIP9UM6yWoQ5x5TP Ch/CV1eVREcgangkGpZH1lJbVp5VUY/c+5MCEU80= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Ray Che , David Ahern , Geoff Alexander , Willy Tarreau , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 094/100] ipv4: tcp: send zero IPID in SYNACK messages Date: Mon, 31 Jan 2022 11:56:55 +0100 Message-Id: <20220131105223.613060330@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@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 [ Upstream commit 970a5a3ea86da637471d3cd04d513a0755aba4bf ] In commit 431280eebed9 ("ipv4: tcp: send zero IPID for RST and ACK sent in SYN-RECV and TIME-WAIT state") we took care of some ctl packets sent by TCP. It turns out we need to use a similar strategy for SYNACK packets. By default, they carry IP_DF and IPID==0, but there are ways to ask them to use the hashed IP ident generator and thus be used to build off-path attacks. (Ref: Off-Path TCP Exploits of the Mixed IPID Assignment) One of this way is to force (before listener is started) echo 1 >/proc/sys/net/ipv4/ip_no_pmtu_disc Another way is using forged ICMP ICMP_FRAG_NEEDED with a very small MTU (like 68) to force a false return from ip_dont_fragment() In this patch, ip_build_and_send_pkt() uses the following heuristics. 1) Most SYNACK packets are smaller than IPV4_MIN_MTU and therefore can use IP_DF regardless of the listener or route pmtu setting. 2) In case the SYNACK packet is bigger than IPV4_MIN_MTU, we use prandom_u32() generator instead of the IPv4 hashed ident one. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reported-by: Ray Che Reviewed-by: David Ahern Cc: Geoff Alexander Cc: Willy Tarreau Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/ip_output.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 4f76e8183f403..5e48b3d3a00db 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -162,12 +162,19 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk, iph->daddr = (opt && opt->opt.srr ? opt->opt.faddr : daddr); iph->saddr = saddr; iph->protocol = sk->sk_protocol; - if (ip_dont_fragment(sk, &rt->dst)) { + /* Do not bother generating IPID for small packets (eg SYNACK) */ + if (skb->len <= IPV4_MIN_MTU || ip_dont_fragment(sk, &rt->dst)) { iph->frag_off = htons(IP_DF); iph->id = 0; } else { iph->frag_off = 0; - __ip_select_ident(net, iph, 1); + /* TCP packets here are SYNACK with fat IPv4/TCP options. + * Avoid using the hashed IP ident generator. + */ + if (sk->sk_protocol == IPPROTO_TCP) + iph->id = (__force __be16)prandom_u32(); + else + __ip_select_ident(net, iph, 1); } if (opt && opt->opt.optlen) { -- 2.34.1