Skip to content

Commit 67e6b11

Browse files
committed
LoongArch: Automatically disable KASLR for hibernation
Hibernation assumes the memory layout after resume be the same as that before sleep, so it expects the kernel is loaded at the same position. To achieve this goal we automatically disable KASLR if user explicitly requests hibernation via the "resume=" command line. Since "nohibernate" and "noresume" have higher priorities than "resume=", we only disable KASLR if there is no "nohibernate" and "noresume". Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent e523a5a commit 67e6b11

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

arch/loongarch/kernel/relocate.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,32 @@ static inline __init bool kaslr_disabled(void)
123123
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
124124
return true;
125125

126+
#ifdef CONFIG_HIBERNATION
127+
str = strstr(builtin_cmdline, "nohibernate");
128+
if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
129+
return false;
130+
131+
str = strstr(boot_command_line, "nohibernate");
132+
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
133+
return false;
134+
135+
str = strstr(builtin_cmdline, "noresume");
136+
if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
137+
return false;
138+
139+
str = strstr(boot_command_line, "noresume");
140+
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
141+
return false;
142+
143+
str = strstr(builtin_cmdline, "resume=");
144+
if (str == builtin_cmdline || (str > builtin_cmdline && *(str - 1) == ' '))
145+
return true;
146+
147+
str = strstr(boot_command_line, "resume=");
148+
if (str == boot_command_line || (str > boot_command_line && *(str - 1) == ' '))
149+
return true;
150+
#endif
151+
126152
return false;
127153
}
128154

0 commit comments

Comments
 (0)