mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
ftrace: Check against is_kernel_text() instead of kaslr_offset()
[ Upstream commitda0f622b34] 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 <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: "Arnd Bergmann" <arnd@arndb.de> Link: https://lore.kernel.org/20250225182054.471759017@goodmis.org Fixes:ef378c3b82("scripts/sorttable: Zero out weak functions in mcount_loc table") Reported-by: Nathan Chancellor <nathan@kernel.org> Reported-by: Mark Brown <broonie@kernel.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Closes: https://lore.kernel.org/all/20250224180805.GA1536711@ax162/ Closes: https://lore.kernel.org/all/5225b07b-a9b2-4558-9d5f-aa60b19f6317@sirena.org.uk/ Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
379e755ec2
commit
e115e9fa69
+12
-5
@@ -6528,7 +6528,6 @@ static int ftrace_process_locs(struct module *mod,
|
||||
unsigned long count;
|
||||
unsigned long *p;
|
||||
unsigned long addr;
|
||||
unsigned long kaslr;
|
||||
unsigned long flags = 0; /* Shut up gcc */
|
||||
unsigned long pages;
|
||||
int ret = -ENOMEM;
|
||||
@@ -6578,9 +6577,6 @@ static int ftrace_process_locs(struct module *mod,
|
||||
ftrace_pages->next = start_pg;
|
||||
}
|
||||
|
||||
/* For zeroed locations that were shifted for core kernel */
|
||||
kaslr = !mod ? kaslr_offset() : 0;
|
||||
|
||||
p = start;
|
||||
pg = start_pg;
|
||||
while (p < end) {
|
||||
@@ -6594,7 +6590,18 @@ static int ftrace_process_locs(struct module *mod,
|
||||
* object files to satisfy alignments.
|
||||
* Skip any NULL pointers.
|
||||
*/
|
||||
if (!addr || addr == kaslr) {
|
||||
if (!addr) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this is core kernel, make sure the address is in core
|
||||
* or inittext, as weak functions get zeroed and KASLR can
|
||||
* move them to something other than zero. It just will not
|
||||
* move it to an area where kernel text is.
|
||||
*/
|
||||
if (!mod && !(is_kernel_text(addr) || is_kernel_inittext(addr))) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user