Skip to contentSkip to conversation

x86/mm/KASLR: Account for minimum padding when calculating entropy

PATCH New Junaid Shahid 1 participant 1 message Oct 23, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm/KASLR: Account for minimum padding when calculating entropy

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;"

---
 arch/x86/mm/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/kaslr.c +2 -1
index 6e6b39710e5f..fe3eec30f736 100644
@@ -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]);
 
Signature · 1 line
2.29.0.rc2.309.g374f81d7ae-goog