lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [day] [month] [year] [list]
Date:   Tue, 10 Aug 2021 08:30:59 -0000
From:   "tip-bot2 for Benjamin Herrenschmidt" <>
Cc:     Benjamin Herrenschmidt <>,
        Ard Biesheuvel <>,,
Subject: [tip: efi/urgent] arm64: efi: kaslr: Fix occasional random alloc (and
 boot) failure

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     4152433c397697acc4b02c4a10d17d5859c2730d
Author:        Benjamin Herrenschmidt <>
AuthorDate:    Tue, 20 Jul 2021 21:14:05 +10:00
Committer:     Ard Biesheuvel <>
CommitterDate: Tue, 20 Jul 2021 16:49:48 +02:00

arm64: efi: kaslr: Fix occasional random alloc (and boot) failure

The EFI stub random allocator used for kaslr on arm64 has a subtle
bug. In function get_entry_num_slots() which counts the number of
possible allocation "slots" for the image in a given chunk of free
EFI memory, "last_slot" can become negative if the chunk is smaller
than the requested allocation size.

The test "if (first_slot > last_slot)" doesn't catch it because
both first_slot and last_slot are unsigned.

I chose not to make them signed to avoid problems if this is ever
used on architectures where there are meaningful addresses with the
top bit set. Instead, fix it with an additional test against the
allocation size.

This can cause a boot failure in addition to a loss of randomisation
due to another bug in the arm64 stub fixed separately.

Signed-off-by: Benjamin Herrenschmidt <>
Fixes: 2ddbfc81eac8 ("efi: stub: add implementation of efi_random_alloc()")
Signed-off-by: Ard Biesheuvel <>
 drivers/firmware/efi/libstub/randomalloc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index a408df4..724155b 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -30,6 +30,8 @@ static unsigned long get_entry_num_slots(efi_memory_desc_t *md,
 	region_end = min(md->phys_addr + md->num_pages * EFI_PAGE_SIZE - 1,
+	if (region_end < size)
+		return 0;
 	first_slot = round_up(md->phys_addr, align);
 	last_slot = round_down(region_end - size + 1, align);

Powered by blists - more mailing lists