Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1007597pxb; Wed, 1 Sep 2021 15:08:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkQVXXYTGzaPCPjxeQZBSEJ3MFsvi7Lz6b6Zx787cuXxR1B3Bb59qbgP9Bfpn9EF80TOYs X-Received: by 2002:a17:907:96a2:: with SMTP id hd34mr37209ejc.113.1630534106537; Wed, 01 Sep 2021 15:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630534106; cv=none; d=google.com; s=arc-20160816; b=zWMhrbMg5rMOmSNq5ft57dHm7GGcq24f9fWoNcqGyz2u1m2LIE0dSXCaae1TkwEph/ bSWogcxQFLwyFPyNeC1bEDGOgr0NNXMPsC6LdX8ExrigkPSmFORzY4DHHxHuXsLG4F5A SOO+0OBzAGIH+U4BdtMKYqUQOMbuj6IN9YXCbvDNAf+9lHY2GicDYoW9PtX8YtmrvDxQ u6NLqpQ2bcRdv+6poG6avoHV4aq5ieplV9abJ/FfbbZwGYN9qZVRKguw/YklGfQOa/Xw 184MJK3NcQxgzsW5s9ErsDw13CZHYNJKoQZfPPacFqAn6DdFN+31IeA93yeHKagB0TzU q3Fg== 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=qx+quGE9AnonDsHD7XaVnth6gRnR1/NnUCitNjW+Pr0=; b=rVUGLrGDGtH4w0ynhcAUj5ohyD8bZIJmguQqgkvZbghHEDkkZKAGzrSWfVcfLOyO7S I5U3yRN/XOMHR9/jNj0mQ+nz6ocBwMDPaj2HbyXJ84ZxdYQ/IL2gQTDrlLX4KDyYFk/X LDdT268Eu9sLzamNN9R1Mh3rJYZtVngeD46lybKoxam+eqpcAG7yMwWoFva6VYvzWrAZ qd7h1V4wDSnls+bsTMdHpmb92OvY/JP1jNuDV4K3/Pz9sAM0Aiy+e0V+v7bpHlt0RU88 r6KQPVtB9RwvFeuJjgEO2utty+uydPrA2eFHxJJnqcJ3aFPGWRQ7MsSCkNscrVlHlfKE YK1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IyZH8+CY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si1078977ejy.519.2021.09.01.15.08.03; Wed, 01 Sep 2021 15:08:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IyZH8+CY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1346316AbhIAMtp (ORCPT + 99 others); Wed, 1 Sep 2021 08:49:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:49844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346011AbhIAMqM (ORCPT ); Wed, 1 Sep 2021 08:46:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1244C610A4; Wed, 1 Sep 2021 12:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499975; bh=ByzqMabcrb7u0/9gS2Wcg3528tlofZxVs8tV5FBWh6M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IyZH8+CYYFVqC0UNAbblVbuYyOKJZ5x+brC9hmvpX3VDlzn/tg9mFQH3F0ECQFEsi rIRPBCINdSC+NUhQY4LBeKwFBBHgEjnvspuLqXN2PbQzLO8DM67nJeJvb+OFZBtcbM QwFFnUWnJFbpK0K0xYmg1p8ehQhdNCa/9eKb4T64= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Keyu Man , Wei Wang , Martin KaFai Lau , "David S. Miller" , Sasha Levin Subject: [PATCH 5.13 054/113] ipv6: use siphash in rt6_exception_hash() Date: Wed, 1 Sep 2021 14:28:09 +0200 Message-Id: <20210901122303.774057853@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122301.984263453@linuxfoundation.org> References: <20210901122301.984263453@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 4785305c05b25a242e5314cc821f54ade4c18810 ] 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 Acked-by: Wei Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 09e84161b731..67c74469503a 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.30.2