* [PATCH] x86/mm/KASLR: Account for minimum padding when calculating entropy
@ 2020-10-23 0:39 Junaid Shahid
0 siblings, 0 replies; only message in thread
From: Junaid Shahid @ 2020-10-23 0:39 UTC (permalink / raw)
To: dave.hansen, luto, peterz; +Cc: linux-kernel
Subtract the minimum padding between regions from the initial
remain_entropy. Without this, the last region could potentially
overflow past vaddr_end if we happen to get a specific sequence
of random numbers (although extremely unlikely in practice).
The bug can be demonstrated by replacing the prandom_bytes_state
call with "rand = entropy;"
Signed-off-by: Junaid Shahid <junaids@google.com>
---
arch/x86/mm/kaslr.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 6e6b39710e5f..fe3eec30f736 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -109,7 +109,8 @@ void __init kernel_randomize_memory(void)
kaslr_regions[2].size_tb = DIV_ROUND_UP(vmemmap_size, 1UL << TB_SHIFT);
/* Calculate entropy available between regions */
- remain_entropy = vaddr_end - vaddr_start;
+ remain_entropy = vaddr_end - vaddr_start -
+ (ARRAY_SIZE(kaslr_regions) - 1) * PUD_SIZE;
for (i = 0; i < ARRAY_SIZE(kaslr_regions); i++)
remain_entropy -= get_padding(&kaslr_regions[i]);
--
2.29.0.rc2.309.g374f81d7ae-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-23 0:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-23 0:39 [PATCH] x86/mm/KASLR: Account for minimum padding when calculating entropy Junaid Shahid
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox