From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C552C4320E for ; Wed, 25 Aug 2021 23:17:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7869C60EBC for ; Wed, 25 Aug 2021 23:17:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233497AbhHYXSZ (ORCPT ); Wed, 25 Aug 2021 19:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbhHYXSX (ORCPT ); Wed, 25 Aug 2021 19:18:23 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE533C061757 for ; Wed, 25 Aug 2021 16:17:36 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id t42so973303pfg.12 for ; Wed, 25 Aug 2021 16:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mGCUvJpcs02KtrbH5sh+HKmH+Xo5D6CWLG3Hh/77W7c=; b=KWVkPzGCnO7Bm0MiuiEa8OCmY+a+qr0DoYKzeCX/flAJLkksrXbRf1NZtWrgNlWLil K0CKpt7ePor2kbLfeHqxHCiDYKaUhXU5fF+ODr8TzgMpfnOCKEqD6lP2q+4yB61qF1T4 nl5kfpmoGFeJ8587Of7Na0gzcY9NH5wvjDV6qMpyBLqH1lLmVDpW5MsfLVuVgHE6bLP6 s5O5vH0AGKuCR5EqaaACgE3dlTj+eLgysrraKyntjTDkwGJ0EgteZxWkT750iZDN8tWM f4712X2+1eVAYN2JILJOw5PKf8V4fmfK2n4G17TFMazYWhS9LF3oYF4r8p5cHfTGqsLe B5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mGCUvJpcs02KtrbH5sh+HKmH+Xo5D6CWLG3Hh/77W7c=; b=B2MwRaCj/rCQEoeZM6cfl3Us/5roqDeEtg9B6770MOSA+0dgPIR2BWj9oKbRTPKjSw Fe8tNuzZTYM1PY7ekF0lyodePA9TfEmUtzYlWbmdr8ncSLk1R35kXIZAtLtaYBUr2v4q txRgHXoQydV0ZV6NdvOjPXclu5pbALQRNZyM3+9Te4AcbT/tYy1jVsckGL69akrIF22L mjgBjtxptoGfqb+ABVfukuLgkiIM0D+G4yTuRcbuWO8bMPDXkRRIkwE89JpbhwsjtqkR IdU269BvXfGoaHlIlOzn9EfY5cd538m9TA0pjoBgkHS/+PqEwa/bY17VAnFmoChQ3F/5 mkhw== X-Gm-Message-State: AOAM5307dMUiAdRKz2DWLa1U9kQz34257uT6nvbMBWi5dpuAAZQD3O9z uhn8Wpmupm3wmRDnTod3o08= X-Google-Smtp-Source: ABdhPJzwvTrz1uvQlm7L64UzorkvuphkINVKV6cB522KIJWFtcPKVQ3lCGo4OqF35tmwW3aBzf2M9w== X-Received: by 2002:a63:515f:: with SMTP id r31mr564738pgl.41.1629933455539; Wed, 25 Aug 2021 16:17:35 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:d4a1:c5c4:fef5:2e3e]) by smtp.gmail.com with ESMTPSA id mv1sm6625035pjb.29.2021.08.25.16.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 16:17:35 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet , Willy Tarreau , Keyu Man , Wei Wang , Martin KaFai Lau Subject: [PATCH net 1/2] ipv6: use siphash in rt6_exception_hash() Date: Wed, 25 Aug 2021 16:17:28 -0700 Message-Id: <20210825231729.401676-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210825231729.401676-1-eric.dumazet@gmail.com> References: <20210825231729.401676-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet A group of security researchers brought to our attention the weakness of hash function used in rt6_exception_hash() Lets use siphash instead of Jenkins Hash, to considerably reduce security risks. Following patch deals with IPv4. Fixes: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache") Signed-off-by: Eric Dumazet Reported-by: Keyu Man Cc: Wei Wang Cc: Martin KaFai Lau --- net/ipv6/route.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index b6ddf23d38330ded88509b8507998ce82a72799b..c5e8ecb96426bda619fe242351e40dcf6ff68bcf 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -1484,17 +1485,24 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket) static u32 rt6_exception_hash(const struct in6_addr *dst, const struct in6_addr *src) { - static u32 seed __read_mostly; - u32 val; + static siphash_key_t rt6_exception_key __read_mostly; + struct { + struct in6_addr dst; + struct in6_addr src; + } __aligned(SIPHASH_ALIGNMENT) combined = { + .dst = *dst, + }; + u64 val; - net_get_random_once(&seed, sizeof(seed)); - val = jhash2((const u32 *)dst, sizeof(*dst)/sizeof(u32), seed); + net_get_random_once(&rt6_exception_key, sizeof(rt6_exception_key)); #ifdef CONFIG_IPV6_SUBTREES if (src) - val = jhash2((const u32 *)src, sizeof(*src)/sizeof(u32), val); + combined.src = *src; #endif - return hash_32(val, FIB6_EXCEPTION_BUCKET_SIZE_SHIFT); + val = siphash(&combined, sizeof(combined), &rt6_exception_key); + + return hash_64(val, FIB6_EXCEPTION_BUCKET_SIZE_SHIFT); } /* Helper function to find the cached rt in the hash table -- 2.33.0.rc2.250.ged5fa647cd-goog