Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp859064pxb; Tue, 1 Feb 2022 11:55:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9nWEyv5DBOJg2NTnPpNqFYsRc7VVct8xXWy16lgatml+wNYmaSoUMjZ1n+yjhCoE+yvnV X-Received: by 2002:a17:90b:1bc3:: with SMTP id oa3mr4157022pjb.172.1643745326753; Tue, 01 Feb 2022 11:55:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745326; cv=none; d=google.com; s=arc-20160816; b=BRAhLqZGyxPgosoDH7BKrry/gD90AcLtkqPUBuRkXJOE1U3c0boX48nguhPanXzn/V kO56PAtf7by0LfIAULPR3LCDVm6BJD7juho/5vSbEzHRPVjR+w6iWzdpm40bqtnkD7Ni QzpJsLTqMO/RBWdqu0fa/GS+cG7cjESN2PxsVoJd7KaN91MvbOpZiIE5IfsDymEGBgN2 +frbKgMksek3hzzYKDIj17F6mRescbsblOOXxXLzq/Fze2e9Fa+AKU48YVscLALAgIzL wzV43ElTwqy2v66WZHEAn8s/qDEEUeuLHB6BebeRx+zZM874KcnVjyK2irvdIbCo6l3W hHEw== 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=/yD3IM8R573fpcui1zrfaTTcA58++gurRy0Xzy7NqMo=; b=J1LUtanYq+MpYjwN4lBKL3Nx0+5h3HIZ58/Wliansd7PcxPK5m2hMRDK3cekEapGv6 KzqXe4QVLS6tdkOnSxIFvUTCP14bdtCfCojZDzg46I3nvyoUGUtCYc+J6ObGJnPpK5eb R5E/6XUrvUCVa+fRokiVbTJIvZgVmj1cRoT/z9MSail/5/dkK3vjLPtdZ8v+/jwhVPt5 3eWK3mEwpu3ihcglg9yQpF7SschCl40l6B2Uega2g1qobLiLpp5YJsEJWvQU3VBp5/qo urSYXpV6mOZ6unQNvK5AqfsVFVYO6waviyGU7lTpA38Bva3/wlU0Mh//WMLSak11ZVE3 2H0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vQGZpIQq; 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 l13si19273687pls.571.2022.02.01.11.55.15; Tue, 01 Feb 2022 11:55:26 -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=vQGZpIQq; 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 S1359321AbiAaLFK (ORCPT + 99 others); Mon, 31 Jan 2022 06:05:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359074AbiAaLCx (ORCPT ); Mon, 31 Jan 2022 06:02:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54106C061373; Mon, 31 Jan 2022 03:01:08 -0800 (PST) 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 6448360B9C; Mon, 31 Jan 2022 11:01:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F975C340E8; Mon, 31 Jan 2022 11:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643626867; bh=tXZ+7dvf12dco54niTjCNvirBlrte9jCHP9j93/5Tro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQGZpIQqP2pU4V8gGZ+cYied4tLTfwJZxqEJf5DaeAr6vfGtGvLSMQu1sy/V52WZN vydq/jx1o1D5F93wP3QAKIp/CeoN1nP3UBF1AEIhlj8IG9F6l/4m2zWY5wAek5lN6D G0Dx9t+ghnGPxr8H+akIF44vcq+FFG0RUdYkGteM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , David Ahern , Ray Che , Willy Tarreau , Jakub Kicinski Subject: [PATCH 5.4 38/64] ipv4: avoid using shared IP generator for connected sockets Date: Mon, 31 Jan 2022 11:56:23 +0100 Message-Id: <20220131105216.962973200@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105215.644174521@linuxfoundation.org> References: <20220131105215.644174521@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 23f57406b82de51809d5812afd96f210f8b627f3 upstream. ip_select_ident_segs() has been very conservative about using the connected socket private generator only for packets with IP_DF set, claiming it was needed for some VJ compression implementations. As mentioned in this referenced document, this can be abused. (Ref: Off-Path TCP Exploits of the Mixed IPID Assignment) Before switching to pure random IPID generation and possibly hurt some workloads, lets use the private inet socket generator. Not only this will remove one vulnerability, this will also improve performance of TCP flows using pmtudisc==IP_PMTUDISC_DONT Fixes: 73f156a6e8c1 ("inetpeer: get rid of ip_id_count") Signed-off-by: Eric Dumazet Reviewed-by: David Ahern Reported-by: Ray Che Cc: Willy Tarreau Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/net/ip.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) --- a/include/net/ip.h +++ b/include/net/ip.h @@ -509,19 +509,18 @@ static inline void ip_select_ident_segs( { struct iphdr *iph = ip_hdr(skb); + /* We had many attacks based on IPID, use the private + * generator as much as we can. + */ + if (sk && inet_sk(sk)->inet_daddr) { + iph->id = htons(inet_sk(sk)->inet_id); + inet_sk(sk)->inet_id += segs; + return; + } if ((iph->frag_off & htons(IP_DF)) && !skb->ignore_df) { - /* This is only to work around buggy Windows95/2000 - * VJ compression implementations. If the ID field - * does not change, they drop every other packet in - * a TCP stream using header compression. - */ - if (sk && inet_sk(sk)->inet_daddr) { - iph->id = htons(inet_sk(sk)->inet_id); - inet_sk(sk)->inet_id += segs; - } else { - iph->id = 0; - } + iph->id = 0; } else { + /* Unfortunately we need the big hammer to get a suitable IPID */ __ip_select_ident(net, iph, segs); } }