Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3299481iob; Mon, 16 May 2022 18:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDRgdsc3DJmruChyXIzhxLfI+5KAdoI6Bp7XIN/4NEQvXalZlOlDkET3Wkzctz3L6A85qK X-Received: by 2002:a17:907:215b:b0:6f4:d91c:ef53 with SMTP id rk27-20020a170907215b00b006f4d91cef53mr17131787ejb.175.1652751361879; Mon, 16 May 2022 18:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652751361; cv=none; d=google.com; s=arc-20160816; b=vwxwyi1Lma6mxSZQEmtlSUEwypXffFgxTN8aodkZJxkkOGJyQiuBtmPIyuN9oXJFsJ HssLaNZ9wD/gNDNluEQ1/UqrjRGz6aSoqAtA54NRfk+TPMk5/MhXnMApLhED15lCN/Cz 14qa39/lAkFNFceaPW0uk4w7pr6c2yZ8WMRXq78aKCyLVx6MR0PfzpvRk1eVZgee5hwo kFBnQJIBqNeVUQ3GHm23K/80y0MIMjV+Y721BY7NNdy66+bILJCOtNKGS9D7NNIyQxNu vuF6fnugTU768ZF2fZLXkAOthdTpsA+JGeCLTd+qO9Uyh/TfU8nI2Hs2HGFvYubN3qbr PIhw== 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=MLSNNdygAju+8+tAhJsLvEmBQNNhEvIp2q94DQec86c=; b=YJG2pTBkuksDGyu8vKUgYqKiQiYomLRYevflRZkTYyCVSvV0yFMwZCT3N0A1bxxS6F mv453OLZPBe2//MdcHSjXj75wKHCPKqWLCD3Zw7/YufC6KppdK/5tVMC/aXnJUab1obT KjJaGW0MKsRveGH92Zp7Wtnj6yrnzHT84VkpnQvl4GCWIgz/zIKmTp7xsYibzpAAWlPM LYEWeBmDPW+7GbzqHiC1+rmOe0BzTuQO/GKLTaJPvmtUkyGx54NB8oyJQEy9AAx+5QAu CbaEXuSdR6goLKtKnId44mHnPjnSdqMNOIPD19vv3UDGBsqCbx2NWcq6FhjjaaPY2vxl kqPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=unlJzQfC; 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 b6-20020aa7dc06000000b0042407dd9dc1si10851991edu.209.2022.05.16.18.35.36; Mon, 16 May 2022 18:36:01 -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=unlJzQfC; 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 S1347966AbiEPUWg (ORCPT + 99 others); Mon, 16 May 2022 16:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348903AbiEPT7C (ORCPT ); Mon, 16 May 2022 15:59:02 -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 75A1E2DA83; Mon, 16 May 2022 12:52:34 -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 3003CB81611; Mon, 16 May 2022 19:52:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9924CC385AA; Mon, 16 May 2022 19:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730752; bh=65xLmvZZ0eCVUyWvXja51xAuV9FPMBzUqc6VOL2ftHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unlJzQfCVBu6bnQYq8Tra8fcw91guz8q+Tffjuz/9e6KZVlWirLHGG9u6ZEq4AG8x JkWGFbtwogDZ9Ma6VKK6Fj7l0nehq7VSRBoyG+KIRqh1Z5W4zG4rc19t9N3VfK1Odc 5b8OP4GqFR0ETwu5Hj0OjD79gWCiFaNvjgKK5aFM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Moshe Kol , Yossi Gilad , Amit Klein , "Jason A. Donenfeld" , Willy Tarreau , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 057/102] tcp: resalt the secret every 10 seconds Date: Mon, 16 May 2022 21:36:31 +0200 Message-Id: <20220516193625.634240927@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@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.4 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 [ Upstream commit 4dfa9b438ee34caca4e6a4e5e961641807367f6f ] In order to limit the ability for an observer to recognize the source ports sequence used to contact a set of destinations, we should periodically shuffle the secret. 10 seconds looks effective enough without causing particular issues. Cc: Moshe Kol Cc: Yossi Gilad Cc: Amit Klein Cc: Jason A. Donenfeld Tested-by: Willy Tarreau Signed-off-by: Eric Dumazet Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/core/secure_seq.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c index 444cce0184c3..7131cd1fb2ad 100644 --- a/net/core/secure_seq.c +++ b/net/core/secure_seq.c @@ -22,6 +22,8 @@ static siphash_key_t net_secret __read_mostly; static siphash_key_t ts_secret __read_mostly; +#define EPHEMERAL_PORT_SHUFFLE_PERIOD (10 * HZ) + static __always_inline void net_secret_init(void) { net_get_random_once(&net_secret, sizeof(net_secret)); @@ -100,11 +102,13 @@ u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, const struct { struct in6_addr saddr; struct in6_addr daddr; + unsigned int timeseed; __be16 dport; } __aligned(SIPHASH_ALIGNMENT) combined = { .saddr = *(struct in6_addr *)saddr, .daddr = *(struct in6_addr *)daddr, - .dport = dport + .timeseed = jiffies / EPHEMERAL_PORT_SHUFFLE_PERIOD, + .dport = dport, }; net_secret_init(); return siphash(&combined, offsetofend(typeof(combined), dport), @@ -145,8 +149,10 @@ EXPORT_SYMBOL_GPL(secure_tcp_seq); u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport) { net_secret_init(); - return siphash_3u32((__force u32)saddr, (__force u32)daddr, - (__force u16)dport, &net_secret); + return siphash_4u32((__force u32)saddr, (__force u32)daddr, + (__force u16)dport, + jiffies / EPHEMERAL_PORT_SHUFFLE_PERIOD, + &net_secret); } EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral); #endif -- 2.35.1