Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6053574iog; Thu, 23 Jun 2022 10:20:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v5YVvjCO54fvERZ8vkstZvUU1t4E9CpDpEEcmz0bz9pHWIDVzA8PoRNv5RrPhwGS1sS7cb X-Received: by 2002:a05:6402:11cd:b0:435:64b5:9a52 with SMTP id j13-20020a05640211cd00b0043564b59a52mr12084269edw.157.1656004821064; Thu, 23 Jun 2022 10:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656004821; cv=none; d=google.com; s=arc-20160816; b=WpVeEmzMfIyN8MOdwK2lqvmBgEhfviIJcq+8fDr56kv0QhFbmJ5LsI39RVQIrUTzty WqmXwSSv0qsWt8zgfbEod8ak4BFpGKmBnO6qbIR0kyjfk1+KskoFfsbRUp2wGHmYmlsv 3cjUjRO6oiDB8CilqH3tzrI9W0rCnAh6NX+FXJE0rMTRUJrKqKaUHw596o9WDyxAd2LY Axpv94mbB4539atH927JytWlNfG78bSaL9Do60g44skIcFakpl8yTX/nKbIBAsOdL7Zt hd5DOWI7l/9oqpDlBgyPBShq9j0PmVDp5puiX9WV/NkoMh1vZb9ooUrFFP6AMvWI2K4g 9O9g== 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=55nC9EqeMcFZ2NnsPv34O4lP3YCY00aThxZfpEr5e94=; b=fpO2EDtZu8KlOPYHTTISF0PwVyENLJ3ts3Z2mP1FDnn/ibfXsssGO8WVxLtMePWCJD edh6AU9Ep97PrnLDS0TmUvQFJOA0qfNiDnNijiNeoO+FH6UKeWUW2nXHfcQRXkUYCfvz PlU+tjxXQJWFgJO0tlSA4UcCmblWiqXigY0vRpk2ZDguGkfPFGp2/4T45I/k1lW/e9j9 KfB6kNdgjVKRV6g7vM8kr6pzQGGG7PY/MqgUSSBTYqW+jzK5AGkIkbJhWK7ZX/hHLmY5 NzFXdSTwI0Ttzpa9v2Zqm3Mkj5ZniaIVR+3cOHRMu96S0GaIRAlVLYCg4YHXnFehYQU6 vmPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XGMPVyb9; 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 x2-20020a05640226c200b0042dbcd63aabsi118536edd.587.2022.06.23.10.19.54; Thu, 23 Jun 2022 10:20: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=XGMPVyb9; 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 S229592AbiFWRQR (ORCPT + 99 others); Thu, 23 Jun 2022 13:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233312AbiFWRMp (ORCPT ); Thu, 23 Jun 2022 13:12:45 -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 E0FD24EF45; Thu, 23 Jun 2022 09:58:41 -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 52BA1B8248A; Thu, 23 Jun 2022 16:58:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9803CC3411B; Thu, 23 Jun 2022 16:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003519; bh=KWIHTYBkB1oKZiqQ7+4sfDcn1nQyj2gDERCoeoco9X4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGMPVyb9nLvMndy39Su2YX95nqXBMG+Ai2KYjxKl2IJUo0cvfCD9iyo2+kssGjUPs dtN/iPf+fdcO8f0lAyvCkdNvtcWDZm2jY/uO/KeiHSbP/0++kOPnAeFmLPG/1KXL9x IGzZRFtwTtMYE1LHcwQka+VfeQuFpTTG4OBsSEvA= 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.9 258/264] tcp: add some entropy in __inet_hash_connect() Date: Thu, 23 Jun 2022 18:44:11 +0200 Message-Id: <20220623164351.365986967@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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 @@ -642,6 +642,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 */