Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6162927iog; Thu, 23 Jun 2022 12:40:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vPxC9U+KbLMh/5GbTi2kkJJqreoNgSmR9aR2iksvZisD5cGrmEkog3Xht1N3jRSWH27u9a X-Received: by 2002:a63:7a51:0:b0:40c:f874:1b46 with SMTP id j17-20020a637a51000000b0040cf8741b46mr8911902pgn.90.1656013221855; Thu, 23 Jun 2022 12:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656013221; cv=none; d=google.com; s=arc-20160816; b=WrBieFbJd2YRajHcEMrXML4Jzv9iFoCuYfLMUrL/wHS5Cs/pjRYEblGJGWnwYYJcnz 3Zg7TmF8BBViwIuOh2NXIyjsNCin7bNBxEGVZlAy1IsCHsBpLCprHnPS+ckF/76tUBf8 3O+OH3aUnRkn3OI+jRHp+Ig/LZhpPacreCyzqfQvGT08LSHFNx1Z7PE8SJNwczQLkHop csCM2zIMbFoXBpFp6NJolVEjblox60U1udTRiSAa9E5EiliGH9YiA/aTcw+S970Unqgc LJEZ9KFl+HlT2PJWIo2wh+ShN7H5AjBdXKjBv628TlDKkjN+Rrh7sOzuXlOc51tQ9ex2 8wcA== 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=4F1m37z9oxxD9cE5+TTk5VmslV5yzGvh31S4u/ucWd4=; b=LmIAlxKcht6gd1CAu8FSdjNGqyzoi6hx1bsb5VdNvbLLjTQHBxABU8ShbZ9eDvr+ap KdLlNQ7ur23KgMhUJ+wTb6hk+OXvmWwKvDA02O/5cRkRtiToEkMTWde5gRxd5DLsNFg4 sgA/R3nwO4LXajhhmhWx45mgOG6SOI+OFNDSQwBm28WCA4NDhCHjo1JZnz/hFCZJz7JE nozjU05nfIg5NTj0IBb41dlr1NSY0+UsMKYDuxGjdJyQnCiYHdms4kmntvQJ7bwCSKG8 KCOdndSEkLT5O6SUURX3UX7Hw6wJ3DlrMwZWOYpqzElhTIlUJBiUiymNj2V3D7BVMAJ9 6tnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kcm0V9I9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q23-20020a63e957000000b00408c597b748si28485659pgj.629.2022.06.23.12.40.09; Thu, 23 Jun 2022 12:40:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kcm0V9I9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236796AbiFWSUt (ORCPT + 99 others); Thu, 23 Jun 2022 14:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236920AbiFWSR3 (ORCPT ); Thu, 23 Jun 2022 14:17:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0628E64790; Thu, 23 Jun 2022 10:23:49 -0700 (PDT) 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 60E77B82497; Thu, 23 Jun 2022 17:23:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A02FDC3411B; Thu, 23 Jun 2022 17:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656005026; bh=xGVcvZTE22n9sCkVWm6eMU6ThsQ4xL58R6NWvHGXPZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcm0V9I9G6ydPtbgai5QIMSG8ryHFO/pQjMH4odKFGftWfZRDLWLrCg6tunl0U3dL fgt7oqkyqS7sPhP+x6tHrIr9dld3X+k5l0QwGbfGhGVE4/RMOTXlyi6EU3fnnzocvz rFQj/l18NVVgmqYNUPeegczjw1bzxUG2xuKw6XJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , David Dworken , Willem de Bruijn , "David S. Miller" , Ben Hutchings Subject: [PATCH 4.19 228/234] tcp: add some entropy in __inet_hash_connect() Date: Thu, 23 Jun 2022 18:44:55 +0200 Message-Id: <20220623164349.501588935@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit c579bd1b4021c42ae247108f1e6f73dd3f08600c upstream. Even when implementing RFC 6056 3.3.4 (Algorithm 4: Double-Hash Port Selection Algorithm), a patient attacker could still be able to collect enough state from an otherwise idle host. Idea of this patch is to inject some noise, in the cases __inet_hash_connect() found a candidate in the first attempt. This noise should not significantly reduce the collision avoidance, and should be zero if connection table is already well used. Note that this is not implementing RFC 6056 3.3.5 because we think Algorithm 5 could hurt typical workloads. Signed-off-by: Eric Dumazet Cc: David Dworken Cc: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/ipv4/inet_hashtables.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -821,6 +821,11 @@ next_port: return -EADDRNOTAVAIL; ok: + /* If our first attempt found a candidate, skip next candidate + * in 1/16 of cases to add some noise. + */ + if (!i && !(prandom_u32() % 16)) + i = 2; WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2); /* Head lock still held and bh's disabled */