x86/mm/KASLR: Account for minimum padding when calculating entropy
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;"
Signed-off-by Junaid Shahid <[email protected]>
--- arch/x86/mm/kaslr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/kaslr.c +2 -1
@@ -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