Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4462821ioa; Wed, 27 Apr 2022 04:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqo0i8BnwJ33YpgFoQzfQ7uowFKkF1MC/4B+qRTMqnrDz8i4XoXxdLrEuDAhC7CTIE8c3n X-Received: by 2002:a17:903:32d2:b0:15d:478c:8b46 with SMTP id i18-20020a17090332d200b0015d478c8b46mr5142598plr.127.1651059167708; Wed, 27 Apr 2022 04:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651059167; cv=none; d=google.com; s=arc-20160816; b=iIJWM6oa026q02sTsSb7Trsn5UMle9NwM1nIgUiY56NMJRBCFUajvXQgFOr1Wud53q 9YnY4UHBEw5e6r8kU+UWHKHj8VlozEsdY155YecYJtNvUNS2EjTURopnF+4ZTxU3tARR hEZ5Pyd8rJf0w9BuVsipgtYujkK1IvsZIV4tpvUyt2kbREJdws9ewM1xuh9PZZsCWvSz O4XQLcW5+uP3Bx0qXiJ8/mpKmKLaoDY5F9XuSh9zHvfr51nBVZk35Qjs04G8LJOOBzTk Osu/gzxo0Jg4okwbGcx0wnG0F3t4XLP9AUboBcUlEsaPczvaPn8Y9i9yf0xNvwWm6Y1X vWHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=ICqVhPxATMWBvYjAndj+KdruJiU6ZSM4/xNM3aK/HOw=; b=IXS+LlRwiaZyuvot3xc3g492GICvyJt5oLViOS/TTYid+dk7xdrPOXlHYAU78mIVST aOuVCRvuAnz06jlvjmxISbii3fq6tEFGJwv+JvaqpveeqJ1c3RFSW47Z9gHywC60mAv1 VK7X16ki9PIe/iEts77hWw+vdxz0rrkF0kODzWB/cpJOFLCTBqmTbm5jk8qLwLGkY9KW JoxMZQIwGtMFDMjT5yYdz+j3LV4UVk9ozpLi3rVAZVbk8sXtV27ppC8a1RSLUbxilFpQ v/Rr1TRZHQrpAmiDQHlogkSwJ+Za1gQ2ph4QEt7DmpbN3SeCTxSDRFAneM6g2wzzJBmU qX6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id jx13-20020a17090b46cd00b001cb7af1047esi1451591pjb.100.2022.04.27.04.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:32:47 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9AA4248612B; Wed, 27 Apr 2022 03:20:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358334AbiD0G4S (ORCPT + 99 others); Wed, 27 Apr 2022 02:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351656AbiD0G4Q (ORCPT ); Wed, 27 Apr 2022 02:56:16 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EF13DCE; Tue, 26 Apr 2022 23:53:04 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 23R6qosB002127; Wed, 27 Apr 2022 08:52:50 +0200 From: Willy Tarreau To: netdev@vger.kernel.org Cc: David Miller , Jakub Kicinski , Eric Dumazet , Moshe Kol , Yossi Gilad , Amit Klein , linux-kernel@vger.kernel.org Subject: [PATCH net 3/7] tcp: resalt the secret every 10 seconds Date: Wed, 27 Apr 2022 08:52:29 +0200 Message-Id: <20220427065233.2075-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20220427065233.2075-1-w@1wt.eu> References: <20220427065233.2075-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 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 Tested-by: Willy Tarreau Signed-off-by: Eric Dumazet --- 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 2cdd43a63f64..200ab4686275 100644 --- a/net/core/secure_seq.c +++ b/net/core/secure_seq.c @@ -22,6 +22,8 @@ static siphash_aligned_key_t net_secret; static siphash_aligned_key_t ts_secret; +#define EPHEMERAL_PORT_SHUFFLE_PERIOD (10 * HZ) + static __always_inline void net_secret_init(void) { net_get_random_once(&net_secret, sizeof(net_secret)); @@ -101,10 +103,12 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, struct in6_addr saddr; struct in6_addr daddr; __be16 dport; + unsigned int timeseed; } __aligned(SIPHASH_ALIGNMENT) combined = { .saddr = *(struct in6_addr *)saddr, .daddr = *(struct in6_addr *)daddr, - .dport = dport + .dport = dport, + .timeseed = jiffies / EPHEMERAL_PORT_SHUFFLE_PERIOD, }; 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.17.5