Skip to content

Commit 6eeca74

Browse files
committed
ftrace: Test mcount_loc addr before calling ftrace_call_addr()
The addresses in the mcount_loc can be zeroed and then moved by KASLR making them invalid addresses. ftrace_call_addr() for ARM 64 expects a valid address to kernel text. If the addr read from the mcount_loc section is invalid, it must not call ftrace_call_addr(). Move the addr check before calling ftrace_call_addr() in ftrace_process_locs(). 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: Mark Brown <[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: "Arnd Bergmann" <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Closes: https://lore.kernel.org/all/20250225025631.GA271248@ax162/ Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 264143c commit 6eeca74

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/trace/ftrace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7063,7 +7063,9 @@ static int ftrace_process_locs(struct module *mod,
70637063
pg = start_pg;
70647064
while (p < end) {
70657065
unsigned long end_offset;
7066-
addr = ftrace_call_adjust(*p++);
7066+
7067+
addr = *p++;
7068+
70677069
/*
70687070
* Some architecture linkers will pad between
70697071
* the different mcount_loc sections of different
@@ -7075,6 +7077,8 @@ static int ftrace_process_locs(struct module *mod,
70757077
continue;
70767078
}
70777079

7080+
addr = ftrace_call_adjust(addr);
7081+
70787082
end_offset = (pg->index+1) * sizeof(pg->records[0]);
70797083
if (end_offset > PAGE_SIZE << pg->order) {
70807084
/* We should have allocated enough */

0 commit comments

Comments
 (0)