[PATCH OLK-6.6] arm64: kaslr: fix nokaslr cmdline parsing

hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICBCH8 ---------------------------------------------------------------------- Currently, when the command line contains "nokaslrxxx", it was incorrectly treated as a request to disable KASLR. This fixes the parsing logic for the 'nokaslr' command line argument. Only the exact strings 'nokaslr' will disable KASLR. Other inputs such as 'xxnokaslr', 'xxnokaslrxx', or 'xxnokaslr=xx' will not disable KASLR. Fixes: aacd149b6238 ("arm64: head: avoid relocating the kernel twice for KASLR") Signed-off-by: Chen Ridong <chenridong@huawei.com> --- arch/arm64/kernel/pi/kaslr_early.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/pi/kaslr_early.c b/arch/arm64/kernel/pi/kaslr_early.c index 17bff6e399e46..e30f2887ac659 100644 --- a/arch/arm64/kernel/pi/kaslr_early.c +++ b/arch/arm64/kernel/pi/kaslr_early.c @@ -32,12 +32,35 @@ static char *__strstr(const char *s1, const char *s2) } return NULL; } + +/* + * nokaslr is valid start? + * Only the first cmd or characters before nokaslr is ' ' are valid. + */ +static bool nokaslr_valid_starts(const char *str, const char *cmdline) +{ + return str == cmdline || (str > cmdline && *(str - 1) == ' '); +} + +/* nokaslr is valid end? */ +static bool nokaslr_valid_ends(const char *str) +{ + size_t len = strlen("nokaslr"); + const char *after = str + len; + + /* End with ' ', '\0' */ + if (*after == ' ' || *after == '\0') + return true; + + return false; +} + static bool cmdline_contains_nokaslr(const u8 *cmdline) { const u8 *str; str = __strstr(cmdline, "nokaslr"); - return str == cmdline || (str > cmdline && *(str - 1) == ' '); + return nokaslr_valid_starts(str, cmdline) && nokaslr_valid_ends(str); } static bool is_kaslr_disabled_cmdline(void *fdt) -- 2.34.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/16861 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/5TF... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/16861 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/5TF...
participants (2)
-
Chen Ridong
-
patchwork bot