x86/kaslr: support separate multiple memmaps parameter parsing
Subsystems (2)
PATCH 1/1 x86/kaslr: support separate multiple memmaps parameter parsing
When the kernel is loading,
the load address of the kernel needs to be calculated firstly.
If the kernel address space layout randomization(kaslr) is enabled, the memory range reserved by the memmap parameter will be excluded to avoid loading the kernel address into the memmap reserved area.
Currently, this is what the manual says:
`memmap = nn [KMG] @ss [KMG]
[KNL] Force usage of a specific region of memory.
Region of memory to be used is from ss to ss + nn.
If @ss [KMG] is omitted, it is equivalent to mem = nn [KMG], which limits max address to nn [KMG].
Multiple different regions can be specified, comma delimited. Example: memmap=100M@2G, 100M#3G, 1G!1024G `
Can we relax the use of memmap?
In our production environment we see many people who use it like this:
Separate multiple memmaps parameters to reserve memory, memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx
If this format is used, and the reserved memory segment is greater than 4,
there is no way to parse the 5th and subsequent memmaps and the kaslr cannot be disabled by memmap_too_large so the kernel loading address may fall within the memmap range
(reserved memory area from memmap after fourth segment),
which will have bad consequences for use of reserved memory.
--- arch/x86/boot/compressed/kaslr.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/x86/boot/compressed/kaslr.c +1 -4
@@ -203,9 +203,6 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str) {static int i; -if (i >=MAX_MEMMAP_REGIONS ) -return ; -while (str && (i <MAX_MEMMAP_REGIONS )) {int rc;unsigned long long start, size;
@@ -233,7 +230,7 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str) }/* More than 4 memmaps, fail kaslr */ -if ((i >=MAX_MEMMAP_REGIONS ) && str) +if ((i >=MAX_MEMMAP_REGIONS ) && !memmap_too_large) memmap_too_large = true; }
Signature · 1 line
2.7.4
Quoted 50 lines · Pan Zhang
When the kernel is loading,
the load address of the kernel needs to be calculated firstly.If the kernel address space layout randomization(
kaslr) is enabled, the memory range reserved by the memmap parameter will be excluded to avoid loading the kernel address into the memmap reserved area.Currently, this is what the manual says:
`memmap = nn [KMG] @ss [KMG]
[KNL] Force usage of a specific region of memory.
Region of memory to be used is from ss to ss + nn.
If @ss [KMG] is omitted, it is equivalent to mem = nn [KMG], which limits max address to nn [KMG].Multiple different regions can be specified, comma delimited. Example: memmap=100M@2G, 100M#3G, 1G!1024G `Can we relax the use of memmap?
In our production environment we see many people who use it like this:
Separate multiple memmaps parameters to reserve memory, memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxx memmap=xx\$xxxIf this format is used, and the reserved memory segment is greater than 4,
there is no way to parse the 5th and subsequent memmaps and the kaslr cannot be disabled bymemmap_too_largeso the kernel loading address may fall within the memmap range
(reserved memory area from memmap after fourth segment),
which will have bad consequences for use of reserved memory.Signed-off-by Pan Zhang <[email protected]>--- arch/x86/boot/compressed/kaslr.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)arch/x86/boot/compressed/kaslr.c +0
-3@@ -203,9 +203,6 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str) {static int i; -if (i >=MAX_MEMMAP_REGIONS ) -return ; -while (str && (i <MAX_MEMMAP_REGIONS )) {int rc;unsigned long long start, size;
arch/x86/boot/compressed/kaslr.c static void mem_avoid_memmap(enum parse_mode mode, char *str) · line 233
Quoted 5 lines
arch/x86/boot/compressed/kaslr.c +1
-1@@ -233,7 +230,7 @@ static void mem_avoid_memmap(enum parse_mode mode, char *str) }/* More than 4 memmaps, fail kaslr */ -if ((i >=MAX_MEMMAP_REGIONS ) && str) +if ((i >=MAX_MEMMAP_REGIONS ) && !memmap_too_large)
I think this should stay the way it was, otherwise KASLR will be disabled even if exactly MAX_MEMMAP_REGIONS were specified. Removing the early return as you did above should be enough to cause the flag to be set if a 5th memmap is specified in a separate parameter, right?
Quoted 6 lines
arch/x86/boot/compressed/kaslr.c +0
-0memmap_too_large = true; }Signature · 1 line
2.7.4