Skip to content

Commit 1be8e54

Browse files
committed
tracing: Fix trace_adjust_address() when there is no modules in scratch 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 <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/[email protected] Fixes: 35a380d ("tracing: Show last module text symbols in the stacktrace") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3c1d9cf commit 1be8e54

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/trace/trace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6043,8 +6043,10 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
60436043
tscratch = tr->scratch;
60446044
/* if there is no tscrach, module_delta must be NULL. */
60456045
module_delta = READ_ONCE(tr->module_delta);
6046-
if (!module_delta || tscratch->entries[0].mod_addr > addr)
6046+
if (!module_delta || !tscratch->nr_entries ||
6047+
tscratch->entries[0].mod_addr > addr) {
60476048
return addr + tr->text_delta;
6049+
}
60486050

60496051
/* Note that entries must be sorted. */
60506052
nr_entries = tscratch->nr_entries;

0 commit comments

Comments
 (0)