[PATCH 3/4] tracing: Only return an adjusted address if it matches the kernel address
From: Steven Rostedt
Date: Tue Mar 04 2025 - 18:15:35 EST
From: Steven Rostedt <rostedt@xxxxxxxxxxx>
The trace_adjust_address() will take a given address and examine the
persistent ring buffer to see if the address matches a module that is
listed there. If it does not, it will just adjust the value to the core
kernel delta. But if the address was for something that was not part of
the core kernel text or data it should not be adjusted.
Check the result of the adjustment and only return the adjustment if it
lands in the current kernel text or data. If not, return the original
address.
Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
---
kernel/trace/trace.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c37dd3b6acb3..2ad2686f39f3 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6005,6 +6005,7 @@ static DEFINE_MUTEX(scratch_mutex);
unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
{
struct trace_scratch *tscratch;
+ unsigned long raddr;
int i;
/* If we don't have last boot delta, return the address */
@@ -6020,7 +6021,9 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
return addr + tr->module_delta[i - 1];
}
- return addr + tr->text_delta;
+ raddr = addr + tr->text_delta;
+ return is_kernel_core_data(raddr) || is_kernel_rodata(raddr) ||
+ __is_kernel(raddr) ? raddr : addr;
}
static int save_mod(struct module *mod, void *data)
--
2.47.2