From 189569f074869ef737ada7a81e2214b6471ae1ac Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 31 Aug 2023 13:06:04 +0200 Subject: [PATCH] 6.1-stable patches added patches: kallsyms-fix-kallsyms_selftest-failure.patch --- ...llsyms-fix-kallsyms_selftest-failure.patch | 95 +++++++++++++++++++ queue-6.1/series | 1 + 2 files changed, 96 insertions(+) create mode 100644 queue-6.1/kallsyms-fix-kallsyms_selftest-failure.patch diff --git a/queue-6.1/kallsyms-fix-kallsyms_selftest-failure.patch b/queue-6.1/kallsyms-fix-kallsyms_selftest-failure.patch new file mode 100644 index 00000000000..129a8264aac --- /dev/null +++ b/queue-6.1/kallsyms-fix-kallsyms_selftest-failure.patch @@ -0,0 +1,95 @@ +From 33f0467fe06934d5e4ea6e24ce2b9c65ce618e26 Mon Sep 17 00:00:00 2001 +From: Yonghong Song +Date: Thu, 24 Aug 2023 20:46:59 -0700 +Subject: kallsyms: Fix kallsyms_selftest failure + +From: Yonghong Song + +commit 33f0467fe06934d5e4ea6e24ce2b9c65ce618e26 upstream. + +Kernel test robot reported a kallsyms_test failure when clang lto is +enabled (thin or full) and CONFIG_KALLSYMS_SELFTEST is also enabled. +I can reproduce in my local environment with the following error message +with thin lto: + [ 1.877897] kallsyms_selftest: Test for 1750th symbol failed: (tsc_cs_mark_unstable) addr=ffffffff81038090 + [ 1.877901] kallsyms_selftest: abort + +It appears that commit 8cc32a9bbf29 ("kallsyms: strip LTO-only suffixes +from promoted global functions") caused the failure. Commit 8cc32a9bbf29 +changed cleanup_symbol_name() based on ".llvm." instead of '.' where +".llvm." is appended to a before-lto-optimization local symbol name. +We need to propagate such knowledge in kallsyms_selftest.c as well. + +Further more, compare_symbol_name() in kallsyms.c needs change as well. +In scripts/kallsyms.c, kallsyms_names and kallsyms_seqs_of_names are used +to record symbol names themselves and index to symbol names respectively. +For example: + kallsyms_names: + ... + __amd_smn_rw._entry <== seq 1000 + __amd_smn_rw._entry.5 <== seq 1001 + __amd_smn_rw.llvm. <== seq 1002 + ... + +kallsyms_seqs_of_names are sorted based on cleanup_symbol_name() through, so +the order in kallsyms_seqs_of_names actually has + + index 1000: seq 1002 <== __amd_smn_rw.llvm. (actual symbol comparison using '__amd_smn_rw') + index 1001: seq 1000 <== __amd_smn_rw._entry + index 1002: seq 1001 <== __amd_smn_rw._entry.5 + +Let us say at a particular point, at index 1000, symbol '__amd_smn_rw.llvm.' +is comparing to '__amd_smn_rw._entry' where '__amd_smn_rw._entry' is the one to +search e.g., with function kallsyms_on_each_match_symbol(). The current implementation +will find out '__amd_smn_rw._entry' is less than '__amd_smn_rw.llvm.' and +then continue to search e.g., index 999 and never found a match although the actual +index 1001 is a match. + +To fix this issue, let us do cleanup_symbol_name() first and then do comparison. +In the above case, comparing '__amd_smn_rw' vs '__amd_smn_rw._entry' and +'__amd_smn_rw._entry' being greater than '__amd_smn_rw', the next comparison will +be > index 1000 and eventually index 1001 will be hit an a match is found. + +For any symbols not having '.llvm.' substr, there is no functionality change +for compare_symbol_name(). + +Fixes: 8cc32a9bbf29 ("kallsyms: strip LTO-only suffixes from promoted global functions") +Reported-by: kernel test robot +Closes: https://lore.kernel.org/oe-lkp/202308232200.1c932a90-oliver.sang@intel.com +Signed-off-by: Yonghong Song +Reviewed-by: Song Liu +Reviewed-by: Zhen Lei +Link: https://lore.kernel.org/r/20230825034659.1037627-1-yonghong.song@linux.dev +Cc: stable@vger.kernel.org +Signed-off-by: Kees Cook +Signed-off-by: Greg Kroah-Hartman +--- + kernel/kallsyms.c | 17 +++++++---------- + 1 file changed, 7 insertions(+), 10 deletions(-) + +--- a/kernel/kallsyms.c ++++ b/kernel/kallsyms.c +@@ -188,16 +188,13 @@ static bool cleanup_symbol_name(char *s) + + static int compare_symbol_name(const char *name, char *namebuf) + { +- int ret; +- +- ret = strcmp(name, namebuf); +- if (!ret) +- return ret; +- +- if (cleanup_symbol_name(namebuf) && !strcmp(name, namebuf)) +- return 0; +- +- return ret; ++ /* The kallsyms_seqs_of_names is sorted based on names after ++ * cleanup_symbol_name() (see scripts/kallsyms.c) if clang lto is enabled. ++ * To ensure correct bisection in kallsyms_lookup_names(), do ++ * cleanup_symbol_name(namebuf) before comparing name and namebuf. ++ */ ++ cleanup_symbol_name(namebuf); ++ return strcmp(name, namebuf); + } + + static int kallsyms_lookup_names(const char *name, diff --git a/queue-6.1/series b/queue-6.1/series index 5f12eb10b84..375d7482e37 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -7,3 +7,4 @@ lockdep-fix-static-memory-detection-even-more.patch parisc-cleanup-mmap-implementation-regarding-color-alignment.patch parisc-sys_parisc-parisc_personality-is-called-from-asm-code.patch io_uring-parisc-adjust-pgoff-in-io_uring-mmap-for-parisc.patch +kallsyms-fix-kallsyms_selftest-failure.patch -- 2.47.3