ring-buffer: Use kaslr address instead of text delta

Instead of saving off the text and data pointers and using them to compare
with the current boot's text and data pointers, just save off the KASLR
offset. Then that can be used to figure out how to read the previous boots
buffer.

The last_boot_info will now show this offset, but only if it is for a
previous boot:

  ~# cat instances/boot_mapped/last_boot_info
  39000000	[kernel]

  ~# echo function > instances/boot_mapped/current_tracer
  ~# cat instances/boot_mapped/last_boot_info
  # Current

If the KASLR offset saved is for the current boot, the last_boot_info will
show the value of "current".

Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: https://lore.kernel.org/20250305164608.274956504@goodmis.org
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
Steven Rostedt
2025-03-28 08:39:26 -04:00
committed by Steven Rostedt (Google)
parent c73f0b6964
commit bcba8d4dbe
4 changed files with 39 additions and 34 deletions
+21 -9
View File
@@ -50,7 +50,7 @@
#include <linux/irq_work.h>
#include <linux/workqueue.h>
#include <asm/setup.h> /* COMMAND_LINE_SIZE */
#include <asm/setup.h> /* COMMAND_LINE_SIZE and kaslr_offset() */
#include "trace.h"
#include "trace_output.h"
@@ -4193,7 +4193,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
* safe to use if the array has delta offsets
* Force printing via the fields.
*/
if ((tr->text_delta || tr->data_delta) &&
if ((tr->text_delta) &&
event->type > __TRACE_LAST_TYPE)
return print_event_fields(iter, event);
@@ -5990,7 +5990,7 @@ ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
static void update_last_data(struct trace_array *tr)
{
if (!tr->text_delta && !tr->data_delta)
if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
return;
/*
@@ -6003,7 +6003,8 @@ static void update_last_data(struct trace_array *tr)
/* Using current data now */
tr->text_delta = 0;
tr->data_delta = 0;
tr->flags &= ~TRACE_ARRAY_FL_LAST_BOOT;
}
/**
@@ -6821,8 +6822,17 @@ tracing_last_boot_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t
seq_buf_init(&seq, buf, 64);
seq_buf_printf(&seq, "text delta:\t%ld\n", tr->text_delta);
seq_buf_printf(&seq, "data delta:\t%ld\n", tr->data_delta);
/*
* Do not leak KASLR address. This only shows the KASLR address of
* the last boot. When the ring buffer is started, the LAST_BOOT
* flag gets cleared, and this should only report "current".
* Otherwise it shows the KASLR address from the previous boot which
* should not be the same as the current boot.
*/
if (tr->flags & TRACE_ARRAY_FL_LAST_BOOT)
seq_buf_printf(&seq, "%lx\t[kernel]\n", tr->kaslr_addr);
else
seq_buf_puts(&seq, "# Current\n");
return simple_read_from_buffer(ubuf, cnt, ppos, buf, seq_buf_used(&seq));
}
@@ -9210,8 +9220,10 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size
tr->range_addr_start,
tr->range_addr_size);
ring_buffer_last_boot_delta(buf->buffer,
&tr->text_delta, &tr->data_delta);
#ifdef CONFIG_RANDOMIZE_BASE
if (ring_buffer_last_boot_delta(buf->buffer, &tr->kaslr_addr))
tr->text_delta = kaslr_offset() - tr->kaslr_addr;
#endif
/*
* This is basically the same as a mapped buffer,
* with the same restrictions.
@@ -10459,7 +10471,7 @@ __init static void enable_instances(void)
* to it.
*/
if (start) {
tr->flags |= TRACE_ARRAY_FL_BOOT;
tr->flags |= TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT;
tr->ref++;
}