Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6139265iog; Thu, 23 Jun 2022 12:09:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u+nwha22ABNMVSSQ1MUEd/Vok7rMKLWgVjKq8HckcMexSB4VgzbX7jknhANI557KZ1zQQI X-Received: by 2002:a17:903:2306:b0:16a:2fa4:9dad with SMTP id d6-20020a170903230600b0016a2fa49dadmr18186919plh.57.1656011388060; Thu, 23 Jun 2022 12:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011388; cv=none; d=google.com; s=arc-20160816; b=Et5MM7a490SmHTRyQ+E3M+BTpQsJI2szVmeio3FN9ntkP+uJsuWZv/GGXNRkbjTu67 fj9SBfUN/oYOAH0LWV0Ti9KkcyJ7wPhmbli5gPwWUoL7l1r0kV8EqDu3jEtcEv2+a3sY Yn8zqjrAZFTgJ/b/pWsrQeZ4LkZDtbq0XqOV7IfZa86nPwvMOvkciIj6mvp+eRSl/iT1 R3sHwtzYFfr3z59gBSExiRgg60D7avVhBkDU0PiaYevPHZiAZjYBkvCW3CV2XWYcJBqE iXlUgewBYzwk7NjfMUIT6P8NPu4TLskeH8hT2YdJxwcwZcjqFtcjY7aJAMAHSurI3pi3 OslA== 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=0GSnV/yM62FNceDmmeXEOFymJ2fA07nXvSvJxzpQRb4=; b=AtyRC529EON5cQpGSBqCNF82Y6t401cYQ02VV+UkZkr/XNgl8nHeCvECUZAel5ZVS6 +1bhO2VTtYGbofSzOMWJoU1Or4L3v/WOBtGRPrWtO2SXqD9qNXHsnmmvwMTuKZrxB2TD pPdg165oKEMfC9IOQUNHIkXgwu/zqEywD4uHkKfTqUxKeymoFuleU/rI9Io8vE2kKJC9 eyUYzVYh0oFAaBHPg1OMjEgJoXyg39TiakrFxp5WiKd7oFWNIGWahBOyf6ezlzI02Blj KpmkMvvySeKQzPkeg/94MKywDks9CAXAuuznz5yhn8Jid7XC0RQfvrMscGMzIZi11cKZ wFkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MAn2V3Zl; 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 o12-20020a056a00214c00b00517c9022a86si25277749pfk.199.2022.06.23.12.09.36; Thu, 23 Jun 2022 12:09:48 -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=MAn2V3Zl; 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 S234783AbiFWRuK (ORCPT + 99 others); Thu, 23 Jun 2022 13:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235530AbiFWRsS (ORCPT ); Thu, 23 Jun 2022 13:48:18 -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 E4CDAA377F; Thu, 23 Jun 2022 10:11:31 -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 D6574B824BA; Thu, 23 Jun 2022 17:11:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29492C3411B; Thu, 23 Jun 2022 17:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004288; bh=BiKY0cWKwAsCGIT5tUZUQGIoQsLFPbq9+UZnNUOmaPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MAn2V3ZlVwFDf00Jq8eWl1PLdHXwSMAB2DPY/dLRs6omDMNU5JokenG6wCFgt58+g lJMRllGZLTOqVX9N+TnATMbqf4rFnlyKYR2U9aTmlwN3+tnmwAKKG7u31ai/PK+NiF au7gJh8xa+Neu33axuUNocwK2v115IRtRCRdhQOU= 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 5.10 04/11] tcp: add some entropy in __inet_hash_connect() Date: Thu, 23 Jun 2022 18:44:37 +0200 Message-Id: <20220623164322.426528204@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164322.296526800@linuxfoundation.org> References: <20220623164322.296526800@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 Cc: 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 @@ -833,6 +833,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 */