Skip to contentSkip to conversation

arm64: mm: Ensure tail of unaligned initrd is reserved

PATCH In review Bjorn Andersson 2 participants 2 messages Apr 18, 2019 – Apr 23, 2019

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

PATCH 1/1 arm64: mm: Ensure tail of unaligned initrd is reserved

In the event that the start address of the initrd is not aligned, but has an aligned size, the base + size will not cover the entire initrd image and there is a chance that the kernel will corrupt the tail of the image.

By aligning the end of the initrd to a page boundary and then subtracting the adjusted start address the memblock reservation will cover all pages that contains the initrd.

Fixes c756c592e442 ("arm64: Utilize phys_initrd_start/phys_initrd_size")
---
 arch/arm64/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/init.c +1 -1
index 6bc135042f5e..7cae155e81a5 100644
@@ -363,7 +363,7 @@ void __init arm64_memblock_init(void)
 		 * Otherwise, this is a no-op
 		 */
 		u64 base = phys_initrd_start & PAGE_MASK;
-		u64 size = PAGE_ALIGN(phys_initrd_size);
+		u64 size = PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base;
 
 		/*
 		 * We can only add back the initrd memory if we don't end up
Signature · 1 line
2.18.0
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Bjorn Andersson

In the event that the start address of the initrd is not aligned, but has an aligned size, the base + size will not cover the entire initrd image and there is a chance that the kernel will corrupt the tail of the image.

By aligning the end of the initrd to a page boundary and then subtracting the adjusted start address the memblock reservation will cover all pages that contains the initrd.

Fixes c756c592e442 ("arm64: Utilize phys_initrd_start/phys_initrd_size")
---
 arch/arm64/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/init.c +0 -0
index 6bc135042f5e..7cae155e81a5 100644

arch/arm64/mm/init.c void __init arm64_memblock_init(void) · line 366

Quoted 5 lines
arch/arm64/mm/init.c +1 -1
@@ -363,7 +363,7 @@ void __init arm64_memblock_init(void)
 		 * Otherwise, this is a no-op
 		 */
 		u64 base = phys_initrd_start & PAGE_MASK;
-		u64 size = PAGE_ALIGN(phys_initrd_size);
+		u64 size = PAGE_ALIGN(phys_initrd_start + phys_initrd_size) - base;

Catalin can pick this up as a fix for 5.1.

Will