Skip to content

Commit da0f622

Browse files
committed
ftrace: Check against is_kernel_text() instead of kaslr_offset()
As kaslr_offset() is architecture dependent and also may not be defined by all architectures, when zeroing out unused weak functions, do not check against kaslr_offset(), but instead check if the address is within the kernel text sections. If KASLR added a shift to the zeroed out function, it would still not be located in the kernel text. This is a more robust way to test if the text is valid or not. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: "Arnd Bergmann" <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: ef378c3 ("scripts/sorttable: Zero out weak functions in mcount_loc table") Reported-by: Nathan Chancellor <[email protected]> Reported-by: Mark Brown <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Closes: https://lore.kernel.org/all/20250224180805.GA1536711@ax162/ Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6eeca74 commit da0f622

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

kernel/trace/ftrace.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7004,7 +7004,6 @@ static int ftrace_process_locs(struct module *mod,
70047004
unsigned long count;
70057005
unsigned long *p;
70067006
unsigned long addr;
7007-
unsigned long kaslr;
70087007
unsigned long flags = 0; /* Shut up gcc */
70097008
unsigned long pages;
70107009
int ret = -ENOMEM;
@@ -7056,9 +7055,6 @@ static int ftrace_process_locs(struct module *mod,
70567055
ftrace_pages->next = start_pg;
70577056
}
70587057

7059-
/* For zeroed locations that were shifted for core kernel */
7060-
kaslr = !mod ? kaslr_offset() : 0;
7061-
70627058
p = start;
70637059
pg = start_pg;
70647060
while (p < end) {
@@ -7072,7 +7068,18 @@ static int ftrace_process_locs(struct module *mod,
70727068
* object files to satisfy alignments.
70737069
* Skip any NULL pointers.
70747070
*/
7075-
if (!addr || addr == kaslr) {
7071+
if (!addr) {
7072+
skipped++;
7073+
continue;
7074+
}
7075+
7076+
/*
7077+
* If this is core kernel, make sure the address is in core
7078+
* or inittext, as weak functions get zeroed and KASLR can
7079+
* move them to something other than zero. It just will not
7080+
* move it to an area where kernel text is.
7081+
*/
7082+
if (!mod && !(is_kernel_text(addr) || is_kernel_inittext(addr))) {
70767083
skipped++;
70777084
continue;
70787085
}

0 commit comments

Comments
 (0)