Commit 6eeca746 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt (Google)
Browse files

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 <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/20250225182054.290128736@goodmis.org


Fixes: ef378c3b ("scripts/sorttable: Zero out weak functions in mcount_loc table")
Reported-by: default avatarNathan Chancellor <nathan@kernel.org>
Reported-by: default avatar"Arnd Bergmann" <arnd@arndb.de>
Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/all/20250225025631.GA271248@ax162/
Closes: https://lore.kernel.org/all/91523154-072b-437b-bbdc-0b70e9783fd0@app.fastmail.com/


Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 264143c4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -7063,7 +7063,9 @@ static int ftrace_process_locs(struct module *mod,
	pg = start_pg;
	while (p < end) {
		unsigned long end_offset;
		addr = ftrace_call_adjust(*p++);

		addr = *p++;

		/*
		 * Some architecture linkers will pad between
		 * the different mcount_loc sections of different
@@ -7075,6 +7077,8 @@ static int ftrace_process_locs(struct module *mod,
			continue;
		}

		addr = ftrace_call_adjust(addr);

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