Skip to content

Commit 8cc32a9

Browse files
yonghong-songkees
authored andcommitted
kallsyms: strip LTO-only suffixes from promoted global functions
Commit 6eb4bd9 ("kallsyms: strip LTO suffixes from static functions") stripped all function/variable suffixes started with '.' regardless of whether those suffixes are generated at LTO mode or not. In fact, as far as I know, in LTO mode, when a static function/variable is promoted to the global scope, '.llvm.<...>' suffix is added. The existing mechanism breaks live patch for a LTO kernel even if no <symbol>.llvm.<...> symbols are involved. For example, for the following kernel symbols: $ grep bpf_verifier_vlog /proc/kallsyms ffffffff81549f60 t bpf_verifier_vlog ffffffff8268b430 d bpf_verifier_vlog._entry ffffffff8282a958 d bpf_verifier_vlog._entry_ptr ffffffff82e12a1f d bpf_verifier_vlog.__already_done 'bpf_verifier_vlog' is a static function. '_entry', '_entry_ptr' and '__already_done' are static variables used inside 'bpf_verifier_vlog', so llvm promotes them to file-level static with prefix 'bpf_verifier_vlog.'. Note that the func-level to file-level static function promotion also happens without LTO. Given a symbol name 'bpf_verifier_vlog', with LTO kernel, current mechanism will return 4 symbols to live patch subsystem which current live patching subsystem cannot handle it. With non-LTO kernel, only one symbol is returned. In [1], we have a lengthy discussion, the suggestion is to separate two cases: (1). new symbols with suffix which are generated regardless of whether LTO is enabled or not, and (2). new symbols with suffix generated only when LTO is enabled. The cleanup_symbol_name() should only remove suffixes for case (2). Case (1) should not be changed so it can work uniformly with or without LTO. This patch removed LTO-only suffix '.llvm.<...>' so live patching and tracing should work the same way for non-LTO kernel. The cleanup_symbol_name() in scripts/kallsyms.c is also changed to have the same filtering pattern so both kernel and kallsyms tool have the same expectation on the order of symbols. [1] https://lore.kernel.org/live-patching/[email protected]/T/#u Fixes: 6eb4bd9 ("kallsyms: strip LTO suffixes from static functions") Reported-by: Song Liu <[email protected]> Signed-off-by: Yonghong Song <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 5fc5224 commit 8cc32a9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

kernel/kallsyms.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,10 @@ static bool cleanup_symbol_name(char *s)
174174
* LLVM appends various suffixes for local functions and variables that
175175
* must be promoted to global scope as part of LTO. This can break
176176
* hooking of static functions with kprobes. '.' is not a valid
177-
* character in an identifier in C. Suffixes observed:
177+
* character in an identifier in C. Suffixes only in LLVM LTO observed:
178178
* - foo.llvm.[0-9a-f]+
179-
* - foo.[0-9a-f]+
180179
*/
181-
res = strchr(s, '.');
180+
res = strstr(s, ".llvm.");
182181
if (res) {
183182
*res = '\0';
184183
return true;

scripts/kallsyms.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ static void cleanup_symbol_name(char *s)
349349
* ASCII[_] = 5f
350350
* ASCII[a-z] = 61,7a
351351
*
352-
* As above, replacing '.' with '\0' does not affect the main sorting,
353-
* but it helps us with subsorting.
352+
* As above, replacing the first '.' in ".llvm." with '\0' does not
353+
* affect the main sorting, but it helps us with subsorting.
354354
*/
355-
p = strchr(s, '.');
355+
p = strstr(s, ".llvm.");
356356
if (p)
357357
*p = '\0';
358358
}

0 commit comments

Comments
 (0)