Skip to content

Commit

Permalink
tracing: Fix trace_adjust_address() when there is no modules in scrat…
Browse files Browse the repository at this point in the history
…ch area

The function trace_adjust_address() is used to map addresses of modules
stored in the persistent memory and are also loaded in the current boot to
return the current address for the module.

If there's only one module entry, it will simply use that, otherwise it
performs a bsearch of the entry array to find the modules to offset with.

The issue is if there are no modules in the array. The code does not
account for that and ends up referencing the first element in the array
which does not exist and causes a crash.

If nr_entries is zero, exit out early as if this was a core kernel
address.

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20250501151909.65910359@gandalf.local.home
Fixes: 35a380d ("tracing: Show last module text symbols in the stacktrace")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt committed May 1, 2025
1 parent 3c1d9cf commit 1be8e54
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6043,8 +6043,10 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
tscratch = tr->scratch;
/* if there is no tscrach, module_delta must be NULL. */
module_delta = READ_ONCE(tr->module_delta);
if (!module_delta || tscratch->entries[0].mod_addr > addr)
if (!module_delta || !tscratch->nr_entries ||
tscratch->entries[0].mod_addr > addr) {
return addr + tr->text_delta;
}

/* Note that entries must be sorted. */
nr_entries = tscratch->nr_entries;
Expand Down

0 comments on commit 1be8e54

Please sign in to comment.