Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp104953pxb; Mon, 13 Sep 2021 14:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe+PEJvjHXOaOtscRBNmq8RAllOjWINauHeGScgN74fL/wGGg6UqQdinWtebgKgAy7FP+i X-Received: by 2002:a05:6402:b23:: with SMTP id bo3mr11913526edb.145.1631567611948; Mon, 13 Sep 2021 14:13:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631567611; cv=none; d=google.com; s=arc-20160816; b=wyI39XMq13WfCpA9rZsIv5897vf/GVFEmgyZB0KmNB/GN5qJFZZKHq1V64PwVvP2wp qHMu6hdTSFl/oily0lkl6XWu8ySUUnKof//wIBT3MRI8ocytwFZ0dnvch0VceSFOBij1 O2Dis/LmxuKjgOytuI1+ETGUS1xaptNLi0GdAYieLIPNCymecggI26igD69LwyntF+Ed 1DTTC0fYTyAKGcQLNef9A40uMJwWA33jiI++0VQQKGIn+OCL9L/KY3suG+GPMwQSLNsN xh5/AJsgvMXckVcQR7UDCI9sgTHKiP9hHE6+eqqrYKAFrHVUOnoYzAU1EDhi3IOtIroX rg1A== 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=ntV3hfnDEFsv3Sw1vnHcNR2TXEuzaftLg9//5jxS9R8=; b=suOZU8x4Sd2vtw3nkomXzSBGI5GdMCdxiXJ6WNIPw7M6ASf/22Tp8SvvkjvpZPb2b6 j8h8d3AW8Y+IS6OD42uqFeriH4hvMsPyXHGvlVEfpKSly99d+oaI0ZdnZCoWtFOGL5AR 2+yiMU9H9ad3cqWYxkh7y8KQLEPc7RF92C0F9OarNy/XMKCvNyrYhh6VUFT4B1WHnPcE 8GgndtJdTUDLEpajjjYV14aqZuSlhT9IRyfjkjHKxsTweeQAq/M6vyP3L36SPHtFJsoS 4AqAYhc3eoExG1S0L10DSlU8HXVEnUuzOVuvRikJg7oy7tkCXqEwv+j3bQD2RALnSJVy IXYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q+1K5GJZ; 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 h14si8461839ejt.392.2021.09.13.14.13.08; Mon, 13 Sep 2021 14:13:31 -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=q+1K5GJZ; 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 S243719AbhIMNwq (ORCPT + 99 others); Mon, 13 Sep 2021 09:52:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:51840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243604AbhIMNsx (ORCPT ); Mon, 13 Sep 2021 09:48:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 86915615A3; Mon, 13 Sep 2021 13:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539980; bh=YGuuKEorXXXCOtl6ApTDFfVYenI2YK5ibSFWqQGCn/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+1K5GJZlr2BLIOjxStZ2cKxr+a2V8dUGSdLmdz6B7bzN5l1lP/JERexAit5ZWo1S KU0Mh0WMzadPWggHaZVOHHIkxuCgcaB8fhvLjbG7aPLfvUth0cdLCUEj1TxuzLLwaY CZjGjCEoy5+Z/KY08/i10v0PTmi3yYrqVVRcAdHg= 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 Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 207/236] ipv6: make exception cache less predictible Date: Mon, 13 Sep 2021 15:15:12 +0200 Message-Id: <20210913131107.420156415@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 a00df2caffed3883c341d5685f830434312e4a43 ] Even after commit 4785305c05b2 ("ipv6: use siphash in rt6_exception_hash()"), an attacker can still use brute force to learn some secrets from a victim linux host. One way to defeat these attacks is to make the max depth of the hash table bucket a random value. Before this patch, each bucket of the hash table used to store exceptions could contain 6 items under attack. After the patch, each bucket would contains a random number of items, between 6 and 10. The attacker can no longer infer secrets. This is slightly increasing memory size used by the hash table, we do not expect this to be a problem. Following patch is dealing with the same issue in 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 Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv6/route.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index bcf4fae83a9b..168a7b4d957a 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -1655,6 +1655,7 @@ static int rt6_insert_exception(struct rt6_info *nrt, struct in6_addr *src_key = NULL; struct rt6_exception *rt6_ex; struct fib6_nh *nh = res->nh; + int max_depth; int err = 0; spin_lock_bh(&rt6_exception_lock); @@ -1709,7 +1710,9 @@ static int rt6_insert_exception(struct rt6_info *nrt, bucket->depth++; net->ipv6.rt6_stats->fib_rt_cache++; - if (bucket->depth > FIB6_MAX_DEPTH) + /* Randomize max depth to avoid some side channels attacks. */ + max_depth = FIB6_MAX_DEPTH + prandom_u32_max(FIB6_MAX_DEPTH); + while (bucket->depth > max_depth) rt6_exception_remove_oldest(bucket); out: -- 2.30.2