Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp599315ybz; Fri, 24 Apr 2020 06:09:47 -0700 (PDT) X-Google-Smtp-Source: APiQypIzbJDgKLQZZWlFkBmapqO9kUs+JaRyFHliKkJM1Bz7+MYELhirtIxFockvBHtdnavrA3Ja X-Received: by 2002:a17:906:6a92:: with SMTP id p18mr7121948ejr.351.1587733787451; Fri, 24 Apr 2020 06:09:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587733787; cv=none; d=google.com; s=arc-20160816; b=AsmDdGYxqfB14CAXJ7lZSDd3v5P69uEwtbIiHdxKxsInMrCZdNSab8v9nFATdxjiFd oEpCUF8FuLCjbIh8yCop3MSb0Y7IYuuJJ09O62H/DS1Ep0wbsA5KMz5V8I4atoftqtPi 4yxk8+fomlhpyQY7TcdExT9F2IZH/zP4CUlwdSjmz+HY52eLs02HYv6BRJ4NGP2tUiR9 nY9tc/yb+DjowBONVQ6cCAzojk+1Nb2fSsL7dCZUiH484ey4k61VNuYE2KubcVnoyA1y DJa/gmTZ2ilCDczZu3TR7z1gEw47txzHpymAnt9khJbgjBomopC0tPROu9P9GV8jXBMH ERaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=INOVsWyC5xrrZQCMtnsq2/N1s8YG38w+5BmpnAK8ZFY=; b=zp7Z3j4UU7BAnwZm8I5JsOZUSntPSdJ1t2zMM1Ov6/v3go+dIO6PXHhLWsx2t7WSdF 35DqCmBdYKr6QzcYOOs532Kj7Ct6Lh73eaArBT1vqTj/eKcFBCjhq2WtB36kAy5r3lPZ bUhG6QHF9wZhgar6hzIOeDbp3m9D/Zs77pQGp3Z425uOzEHH+MyoUL1xKBWXGKTUFQC4 O65Cw9h2yAyg7tJFDgOj/TlE1sudQl2VxVjmE+VuDMEYF+pRrs6s6xqvFDvWKIgQ4CdR 0uciU2NbDvJVt+D/HIBCusIhWJMY0zFcyywCavZD377KLRudhvSKM2VUqxswcBCBh+Z2 NDrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ej66MkSH; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg8si3049279edb.548.2020.04.24.06.09.17; Fri, 24 Apr 2020 06:09:47 -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=@kernel.org header.s=default header.b=Ej66MkSH; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728188AbgDXNG7 (ORCPT + 99 others); Fri, 24 Apr 2020 09:06:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:57592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728124AbgDXNG4 (ORCPT ); Fri, 24 Apr 2020 09:06:56 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E50ED20728; Fri, 24 Apr 2020 13:06:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587733615; bh=u/xP6CoK1MUmVKKpWlYTdz2lShxhmNKAh4XSY+FwLjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ej66MkSHbWOonlumdQ9GGnTn+UsiBagZBTkYO+Jv5zmh/HazYXl0bZV4rkQqIoVYE 2Zq5Wa+A8Lo66KcR8sJF+lDLkNmALZBcBSP9Tk6oBNaJ3p3v/y6lVTUmKy4RuZyuUQ IGI9ILrieHZ3fH6Y+0ISv4vHQ282P9wI5Wf3O8D8= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Atish Patra , Palmer Dabbelt , Zou Wei Subject: [PATCH 20/33] efi/libstub/random: Increase random alloc granularity Date: Fri, 24 Apr 2020 15:05:18 +0200 Message-Id: <20200424130531.30518-21-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200424130531.30518-1-ardb@kernel.org> References: <20200424130531.30518-1-ardb@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The implementation of efi_random_alloc() arbitrarily truncates the provided random seed to 16 bits, which limits the granularity of the randomly chosen allocation offset in memory. This is currently only an issue if the size of physical memory exceeds 128 GB, but going forward, we will reduce the allocation alignment to 64 KB, and this means we need to increase the granularity to ensure that the random memory allocations are distributed evenly. We will need to switch to 64-bit arithmetic for the multiplication, but this does not result in 64-bit integer intrinsic calls on ARM or on i386. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/randomalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c index 6200dfa650f5..a408df474d83 100644 --- a/drivers/firmware/efi/libstub/randomalloc.c +++ b/drivers/firmware/efi/libstub/randomalloc.c @@ -87,7 +87,7 @@ efi_status_t efi_random_alloc(unsigned long size, } /* find a random number between 0 and total_slots */ - target_slot = (total_slots * (u16)random_seed) >> 16; + target_slot = (total_slots * (u64)(random_seed & U32_MAX)) >> 32; /* * target_slot is now a value in the range [0, total_slots), and so -- 2.17.1