Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1217672iob; Thu, 28 Apr 2022 23:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEUgfZTBxin+KKuT5gWtfoSE8x7RDXxQ1MUyIFGDvhxqb/LsdCxxS/3rUg3Kunnhmq8jXY X-Received: by 2002:a17:902:e94e:b0:158:91e6:501 with SMTP id b14-20020a170902e94e00b0015891e60501mr37196228pll.29.1651214294387; Thu, 28 Apr 2022 23:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651214294; cv=none; d=google.com; s=arc-20160816; b=zJYUWUapvhg2cHEOeQxbHpWDXVKzG8a5huMMUBmB4umbTLftq/N8vbqL6B/posBf1w 5z6JS0ocLRbONMw6ndt3hg0Uoe0Fj7xbU0a7kgWoEHhp5c4y+CUcCXLdlEQ80dX5uEKD 3nXWx6Fdbn+rHn293JGRKOomIwjpUHbaa6LiVYY+uHkomU7wUiaaEaOykpbMBCcz6Usb BqyIqrcBqap9R2c3ko8jYRVLVK3SfZY3XpTerOURTuP4/s3EB9yL7wsF9FQJgE+FaHDM /0/JKVKFz3ksKHRvVquS8X3DPen1PdzLAd2RqqeYbVDYr9VBobePGX9C73smb2OXGQjm xnQQ== 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=Tzhec7IOHHZj0Huql2J+lx0hgWB8NzsJwjY2Q3n43i0=; b=Eb4Ksc/Uf43BYew6txgd+iytPwQY8MG3LWXkuD6QE0/kFaLKxIlaIhXin5VhASjcOg mUoeBdDM8S3dujHYk6qrjNaABovA7ErzB0I9I4a8c4WLsVp2PbB++Gl9nv5ZqciwkBiL cOabTS2mZNvq+kljkl4sS4rkyhX2FwDELyVNdbBeT52j8T3zl66LOoOd/HX7g/RLHcPo +YOoOuMtE57hWzLpd+//NTC3B/sRGBvUdvWITbOhjA1WZso4knBVvivf6ubC3W4NYR5E vzET154/VTW+FFOrGg0AXZ/9rJ51Y3hzELYN74l1YxdKhVYOM5cWwHhp1v+DvHCTGYTr AMnw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d10-20020a170902854a00b00154c1348e40si5642666plo.497.2022.04.28.23.37.58; Thu, 28 Apr 2022 23:38:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346451AbiD1MoM (ORCPT + 99 others); Thu, 28 Apr 2022 08:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346433AbiD1MoG (ORCPT ); Thu, 28 Apr 2022 08:44:06 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0FE896324; Thu, 28 Apr 2022 05:40:50 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 23SCeF1G007482; Thu, 28 Apr 2022 14:40:15 +0200 From: Willy Tarreau To: netdev@vger.kernel.org Cc: David Miller , Jakub Kicinski , Eric Dumazet , Moshe Kol , Yossi Gilad , Amit Klein , "Jason A . Donenfeld" , linux-kernel@vger.kernel.org Subject: [PATCH v2 net 3/7] tcp: resalt the secret every 10 seconds Date: Thu, 28 Apr 2022 14:39:57 +0200 Message-Id: <20220428124001.7428-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20220428124001.7428-1-w@1wt.eu> References: <20220428124001.7428-1-w@1wt.eu> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 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 55aa5cc258e3..2c76aab20403 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 @@ u64 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