linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com,
	catalin.marinas@arm.com, will@kernel.org,
	Jonathan.Cameron@huawei.com, nivedita@alum.mit.edu,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH v2 2/8] efi/libstub/random: increase random alloc granularity
Date: Mon, 13 Apr 2020 17:55:15 +0200	[thread overview]
Message-ID: <20200413155521.24698-3-ardb@kernel.org> (raw)
In-Reply-To: <20200413155521.24698-1-ardb@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 <ardb@kernel.org>
---
 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


  parent reply	other threads:[~2020-04-13 15:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 15:55 [PATCH v2 0/8] efi/libstub: simplify arm64 kernel image loading Ard Biesheuvel
2020-04-13 15:55 ` [PATCH v2 1/8] efi/libstub/random: align allocate size to EFI_ALLOC_ALIGN Ard Biesheuvel
2020-04-13 15:55 ` Ard Biesheuvel [this message]
2020-04-13 15:55 ` [PATCH v2 3/8] efi/libstub/arm64: replace 'preferred' offset with alignment check Ard Biesheuvel
2020-04-14 23:21   ` Atish Patra
2020-04-15  7:42     ` Ard Biesheuvel
2020-04-13 15:55 ` [PATCH v2 4/8] efi/libstub/arm64: simplify randomized loading of kernel image Ard Biesheuvel
2020-04-13 15:55 ` [PATCH v2 5/8] efi/libstub/arm64: align PE/COFF sections to segment alignment Ard Biesheuvel
2020-04-22  9:39   ` Ard Biesheuvel
2020-04-28 15:11     ` Will Deacon
2020-04-13 15:55 ` [PATCH v2 6/8] efi/libstub: add API function to allocate aligned memory Ard Biesheuvel
2020-04-14 23:46   ` Atish Patra
2020-04-13 15:55 ` [PATCH v2 7/8] efi/libstub/arm64: switch to ordinary page allocator for kernel image Ard Biesheuvel
2020-04-14 23:29   ` Atish Patra
2020-04-13 15:55 ` [PATCH v2 8/8] efi/libstub: move efi_relocate_kernel() into separate source file Ard Biesheuvel
2020-04-13 21:53 ` [PATCH v2 0/8] efi/libstub: simplify arm64 kernel image loading Atish Patra
2020-04-14  7:22   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200413155521.24698-3-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=nivedita@alum.mit.edu \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).