Commit bed717be authored by Benjamin Herrenschmidt's avatar Benjamin Herrenschmidt Committed by Zheng Zengkai
Browse files

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

stable inclusion
from stable-5.10.60
commit afcb84e6cf8cf8ab1fb8b4bfa44c6caad64ae581
bugzilla: 177018 https://gitee.com/openeuler/kernel/issues/I4EAUG

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=afcb84e6cf8cf8ab1fb8b4bfa44c6caad64ae581



--------------------------------

[ Upstream commit 4152433c ]

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: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Fixes: 2ddbfc81 ("efi: stub: add implementation of efi_random_alloc()")
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarChen Jun <chenjun102@huawei.com>
Acked-by: default avatarWeilong Chen <chenweilong@huawei.com>
Signed-off-by: default avatarChen Jun <chenjun102@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d21db47b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment