From: Libo Chen <libo.chen@oracle.com>
To: Steven Rostedt <rostedt@goodmis.org>,
LKML <linux-kernel@vger.kernel.org>,
Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: [PATCH v2] tracing: Verify event formats that have "%*p.."
Date: Fri, 28 Mar 2025 16:22:27 -0700 [thread overview]
Message-ID: <ffeb5e0a-6968-42d4-bcbb-bd8fc5341a50@oracle.com> (raw)
In-Reply-To: <20250327195311.2d89ec66@gandalf.local.home>
On 3/27/25 16:53, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> The trace event verifier checks the formats of trace events to make sure
> that they do not point at memory that is not in the trace event itself or
> in data that will never be freed. If an event references data that was
> allocated when the event triggered and that same data is freed before the
> event is read, then the kernel can crash by reading freed memory.
>
> The verifier runs at boot up (or module load) and scans the print formats
> of the events and checks their arguments to make sure that dereferenced
> pointers are safe. If the format uses "%*p.." the verifier will ignore it,
> and that could be dangerous. Cover this case as well.
>
> Also add to the sample code a use case of "%*pbl".
>
> Link: https://urldefense.com/v3/__https://lore.kernel.org/all/bcba4d76-2c3f-4d11-baf0-02905db953dd@oracle.com/__;!!ACWV5N9M2RV99hQ!L9dryF2Ft0p8H1X2Q6EPsm0j03lJOixhB2V-_zkgCOBUoIS5V7B8hmOZxCpHjzNnCodkqNmxUulCC5wPbg$
>
this is no longer a blocker for me, as I mentioned in a different thread:
https://lore.kernel.org/all/4f5453e8-61b6-45d1-8c6c-8b4fb99a6448@oracle.com/
Thanks,
Libo
> Reported-by: Libo Chen <libo.chen@oracle.com>
> Reviewed-by: Libo Chen <libo.chen@oracle.com>
> Tested-by: Libo Chen <libo.chen@oracle.com>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> Changes since v1: https://urldefense.com/v3/__https://lore.kernel.org/20250327114911.2c713511@gandalf.local.home__;!!ACWV5N9M2RV99hQ!L9dryF2Ft0p8H1X2Q6EPsm0j03lJOixhB2V-_zkgCOBUoIS5V7B8hmOZxCpHjzNnCodkqNmxUumNh4GyCw$
>
> - Fixed indentation in sample header.
>
> kernel/trace/trace_events.c | 7 +++++++
> samples/trace_events/trace-events-sample.h | 8 ++++++--
> 2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 8e7603acca21..ceeedcb5940b 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -470,6 +470,7 @@ static void test_event_printk(struct trace_event_call *call)
> case '%':
> continue;
> case 'p':
> + do_pointer:
> /* Find dereferencing fields */
> switch (fmt[i + 1]) {
> case 'B': case 'R': case 'r':
> @@ -498,6 +499,12 @@ static void test_event_printk(struct trace_event_call *call)
> continue;
> if (fmt[i + j] == '*') {
> star = true;
> + /* Handle %*pbl case */
> + if (!j && fmt[i + 1] == 'p') {
> + arg++;
> + i++;
> + goto do_pointer;
> + }
> continue;
> }
> if ((fmt[i + j] == 's')) {
> diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
> index 999f78d380ae..1a05fc153353 100644
> --- a/samples/trace_events/trace-events-sample.h
> +++ b/samples/trace_events/trace-events-sample.h
> @@ -319,7 +319,8 @@ TRACE_EVENT(foo_bar,
> __assign_cpumask(cpum, cpumask_bits(mask));
> ),
>
> - TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s", __entry->foo, __entry->bar,
> + TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s [%d] %*pbl",
> + __entry->foo, __entry->bar,
>
> /*
> * Notice here the use of some helper functions. This includes:
> @@ -370,7 +371,10 @@ TRACE_EVENT(foo_bar,
>
> __get_str(str), __get_str(lstr),
> __get_bitmask(cpus), __get_cpumask(cpum),
> - __get_str(vstr))
> + __get_str(vstr),
> + __get_dynamic_array_len(cpus),
> + __get_dynamic_array_len(cpus),
> + __get_dynamic_array(cpus))
> );
>
> /*
prev parent reply other threads:[~2025-03-28 23:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 23:53 Steven Rostedt
2025-03-28 23:22 ` Libo Chen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ffeb5e0a-6968-42d4-bcbb-bd8fc5341a50@oracle.com \
--to=libo.chen@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®