Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp915246pxb; Wed, 1 Sep 2021 12:35:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNTq+sd5iCPeaLn09ZGty2XiuSKRwybyzTrHZsmKT7QF1ssQFN0rahrYj9ZxE/L+6AM2zZ X-Received: by 2002:a92:d1c6:: with SMTP id u6mr756956ilg.263.1630524907023; Wed, 01 Sep 2021 12:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630524907; cv=none; d=google.com; s=arc-20160816; b=G7ax8UOpf7WcFaSu3hagoOx/w0cz5/trT4LfrZyGqOuKDnLbvOQmcqGs6t80UpTihl M/Ttvv59/3Po/LMirNwhMlKNH8oNkcaMhmDBOcbHVXf/kD1Yqz5OCQ+wpGI5eP8UoP8w 0Wzb9ruZGeTukBXqhK2HqjC4NWJuzh630d+F7+qO5wgZn+qYHI7pxEEd6i7jJcULkwf/ qGd+40w9QPAUYq0wGfWRC/XIqn4dbmItdl+isvFZuSw5wpfvGI+3bfFAcdscCwgcdJRl JTPKnWEKsTkJJQhgjYw/Dz8UEO3dZuVzGa/o8xEXZDMRxIzqxZQeoi7/abc3vkN6yoGA LNxQ== 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=LSKsIYO1Rw9HuDmiJvOIHjZpE+S9MvNM6EaevdqfLho=; b=CKDmpHmYma0bk+p0Gt+B5pkPmIa8kBtp0SkGfJvYm0I4EGpka8W3nHctbJCeW6SuKi YgL+wcpO2o4SyP9M5hO8A0n7WwN0EwHskeYDMglNbW3fkMi3yd3c3e+A8ER54B+Jdeni KNkvi42IKFSEZoKoNhI83zkEbFbI/QEIZEOG9oK8lQvsnwWk4GTzZd+gySJ4PdwBMO7P 4XV/QqG9o3T85PF/Bgp9RkM3ej9xzv5OgcHuSl+Q251AF+HrDX5IkuvLjBThyzfrnpeF oWao/Z8cjOErsbJBbk8Sgi9TgUiLFkGB5e4L7LvBKC9LvMncMNz6kr+EtHJZqS/5yygC 8Puw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=khbJXpM5; 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 k35si307677jac.46.2021.09.01.12.34.55; Wed, 01 Sep 2021 12:35:07 -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=khbJXpM5; 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 S1345083AbhIAMkn (ORCPT + 99 others); Wed, 1 Sep 2021 08:40:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:40776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245698AbhIAMhy (ORCPT ); Wed, 1 Sep 2021 08:37:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8050761153; Wed, 1 Sep 2021 12:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499665; bh=F0MW1db5OjgHtF2kTSOyksu1a1+W3Mq7CZ0qKIUJMMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=khbJXpM5PK7w2h8L/3kqEuFyNSkBipdSysd2kDZuyZL2cAyQpFkOdZWqQ81eCPIa1 pUzgMo27D9VB0SjAEf97KxzoEOm88K8dYHMUb6WCCa7Ui90u6TmaFIhomdGCVcdbMO pHvm9+kUhs7aFwHB+qLBOzHKwIOM3wE14jNdnw/4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Keyu Man , Willy Tarreau , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 039/103] ipv4: use siphash instead of Jenkins in fnhe_hashfun() Date: Wed, 1 Sep 2021 14:27:49 +0200 Message-Id: <20210901122301.873854687@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122300.503008474@linuxfoundation.org> References: <20210901122300.503008474@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 6457378fe796815c973f631a1904e147d6ee33b1 ] A group of security researchers brought to our attention the weakness of hash function used in fnhe_hashfun(). Lets use siphash instead of Jenkins Hash, to considerably reduce security risks. Also remove the inline keyword, this really is distracting. Fixes: d546c621542d ("ipv4: harden fnhe_hashfun()") Signed-off-by: Eric Dumazet Reported-by: Keyu Man Cc: Willy Tarreau Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/route.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index e15c1d8b7c8d..3d9946fd41f3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -624,14 +624,14 @@ static struct fib_nh_exception *fnhe_oldest(struct fnhe_hash_bucket *hash) return oldest; } -static inline u32 fnhe_hashfun(__be32 daddr) +static u32 fnhe_hashfun(__be32 daddr) { - static u32 fnhe_hashrnd __read_mostly; - u32 hval; + static siphash_key_t fnhe_hash_key __read_mostly; + u64 hval; - net_get_random_once(&fnhe_hashrnd, sizeof(fnhe_hashrnd)); - hval = jhash_1word((__force u32)daddr, fnhe_hashrnd); - return hash_32(hval, FNHE_HASH_SHIFT); + net_get_random_once(&fnhe_hash_key, sizeof(fnhe_hash_key)); + hval = siphash_1u32((__force u32)daddr, &fnhe_hash_key); + return hash_64(hval, FNHE_HASH_SHIFT); } static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnhe) -- 2.30.2