Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp868716pxb; Tue, 1 Feb 2022 12:05:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7tqs86hV5xy+rJExdQMYR/r7GsZ5t7L2ayz9+nJtuxtlYM3A52ZmYg6/TjcHwqBuGPSuz X-Received: by 2002:a17:902:e885:: with SMTP id w5mr27442115plg.155.1643745954756; Tue, 01 Feb 2022 12:05:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745954; cv=none; d=google.com; s=arc-20160816; b=jWu9WuKSS+a1xWKQ/XsKubDXMb2RxkpZ9bTsW0QeKPQq8jAV8xhIQ8QeCmxCBFDWPw cnQb4k14niw2N0F3uu6ZQYo8GM6Sunlf1pSYc9vZ0+NrBfdGz2EPDK3c0UVH5AQZkWmc Y3kiwr1cYqSCMDoiNKXUvvRjV3NkBUIeGcZyzes73vZyhV2+AzWhQCdUDyQjRW/ZG/I3 wW/hwV/YOkZ9fMYP0cncN7zDreAAkmNxMflK1D/aLMLOrZHmv2dnnESgtjqHFMiw7VHq ZK/6GhX7v+FofMyS6Q0O3ql347QHpuH61Spwb0kJMZoAJC36i0ZbxFAfSIAnQteApqKs Ik5w== 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=V+eeUYYeWSQSh6pQXRzQFblQ2HKu1AeAPsYJc88wBc0=; b=DaKkdLxkoxp/M9ItR1Qg9/F25JVk/K/gN6tAvyXkCBIv7fo7HmtVwELKYFdiGR1R6F ywOs74FJsKujqgkWnjZMurtC0eXQMvtSwhbu3A4Oygi9izakPMhb7Y6bWQNQgzVfBSCL ykhwQ7JVZQ+UBfqboaKRjCrjIN+/LVkmdBVPalkl+VOfU6c0ESWaaWQsr5rVBTxRhGg+ QHI7nT96A7EdHM6GAztLGR+FXJ/2TZooXJfKWhSbJR1LiuOXF/uNFPPLoB8e0X+QuVgn D66U5n1LpMQfMP0qKczNNKUKrZxsM4QPyoce/ZB+a2D4IdivSWps68O+kqgBJy2IiAXJ mLOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wZbq9Kaw; 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 e7si19544280plh.419.2022.02.01.12.05.42; Tue, 01 Feb 2022 12:05:54 -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=wZbq9Kaw; 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 S1378137AbiAaLXn (ORCPT + 99 others); Mon, 31 Jan 2022 06:23:43 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:47934 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349498AbiAaLO1 (ORCPT ); Mon, 31 Jan 2022 06:14:27 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 74F30611DA; Mon, 31 Jan 2022 11:14:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FF91C340E8; Mon, 31 Jan 2022 11:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627666; bh=0/4qqa1wTaF3Qode9fXp/Z88QTW8pXk94tsFhuIOyyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wZbq9Kawp31s7mSgNIYnlBNTRFrXDsyKwSFBqYYiz2LrsaEruw8dvMHfRWx18OUy5 Ru1mWWjlyrDiBf24Cmt3dC/P8YPR3nWrKltT+gqN0dskMMIREI4mrNrT2RdWr2Vfh8 fPcUn6FMC/Dgcn9moItkHH1Gi45pJQbPvtlllSgs= 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.15 158/171] ipv4: tcp: send zero IPID in SYNACK messages Date: Mon, 31 Jan 2022 11:57:03 +0100 Message-Id: <20220131105235.361632029@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105229.959216821@linuxfoundation.org> References: <20220131105229.959216821@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 ff38b46bd4b0f..a4d2eb691cbc1 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