From: Beau Belgrave <beaub@linux.microsoft.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Qiang <liqiang01@kylinos.cn>,
mhiramat@kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/4] tracing/user_events: Validate explicit struct field sizes
Date: Wed, 22 Jul 2026 17:27:32 +0000 [thread overview]
Message-ID: <20260722172732.GA212-beaub@linux.microsoft.com> (raw)
In-Reply-To: <20260722123310.7da7166b@gandalf.local.home>
On Wed, Jul 22, 2026 at 12:33:10PM -0400, Steven Rostedt wrote:
> Beau,
>
> Can you review this?
>
Sure thing.
> Thanks,
>
> -- Steve
>
>
> On Wed, 22 Jul 2026 14:10:38 +0800
> Li Qiang <liqiang01@kylinos.cn> wrote:
>
> > User event declarations permit an explicit size for a struct field. The
> > parser accumulated that size in an unsigned offset, then assigned the
> > parsed unsigned value directly to signed field metadata. Oversized
> > declarations or cumulative offsets could wrap or become invalid signed
> > values.
> >
> > Validate an explicit size is representable as int before storing it. Keep
> > the running offset signed and reject additions exceeding INT_MAX, so
> > invalid field layouts are rejected during declaration parsing.
> >
Li Qiang, thanks for looking into this!
> > Fixes: 7f5a08c79df3 ("user_events: Add minimal support for trace_event into ftrace")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
> > ---
> > kernel/trace/trace_events_user.c | 16 ++++++++++++----
> > 1 file changed, 12 insertions(+), 4 deletions(-)
> >
> > diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> > index 8c82ecb735f4..fd5b3946921c 100644
> > --- a/kernel/trace/trace_events_user.c
> > +++ b/kernel/trace/trace_events_user.c
> > @@ -1197,10 +1197,12 @@ static int user_event_add_field(struct user_event *user, const char *type,
> > * Format: type name [size]
> > */
> > static int user_event_parse_field(char *field, struct user_event *user,
> > - u32 *offset)
> > + int *offset)
> > {
> > char *part, *type, *name;
> > - u32 depth = 0, saved_offset = *offset;
> > + u32 depth = 0;
> > + unsigned int field_size;
> > + int saved_offset = *offset;
> > int len, size = -EINVAL;
> > bool is_struct = false;
> >
> > @@ -1261,8 +1263,11 @@ static int user_event_parse_field(char *field, struct user_event *user,
> > if (!is_struct)
> > return -EINVAL;
> >
> > - if (kstrtou32(part, 10, &size))
> > + if (kstrtouint(part, 10, &field_size))
> > return -EINVAL;
> > + if (field_size > INT_MAX)
> > + return -E2BIG;
We have a hard coded limit on arrays already of 1024 (MAX_FIELD_ARRAY_SIZE).
We could have a much smaller max here if we want to. However, since this
will backport, I'm fine keeping it this larger value in-case someone
really needs this much space for a struct.
> > + size = field_size;
> > break;
> > default:
> > return -EINVAL;
> > @@ -1281,6 +1286,9 @@ static int user_event_parse_field(char *field, struct user_event *user,
> > if (size < 0)
> > return size;
> >
> > + if (size > INT_MAX - saved_offset)
> > + return -E2BIG;
> > +
> > *offset = saved_offset + size;
We should really use check_add_overflow() here and return -E2BIG if it
fails instead of a hand coded check. Please update utilizing that.
> >
> > return user_event_add_field(user, type, name, saved_offset, size,
> > @@ -1290,7 +1298,7 @@ static int user_event_parse_field(char *field, struct user_event *user,
> > static int user_event_parse_fields(struct user_event *user, char *args)
> > {
> > char *field;
> > - u32 offset = sizeof(struct trace_entry);
> > + int offset = sizeof(struct trace_entry);
> > int ret = -EINVAL;
> >
> > if (args == NULL)
Thanks,
-Beau
next prev parent reply other threads:[~2026-07-22 17:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 6:10 [PATCH 0/4] tracing: fix histogram and injection buffer overflows Li Qiang
2026-07-22 6:10 ` [PATCH 1/4] tracing/hist: Prevent overflow in histogram expression strings Li Qiang
2026-07-22 16:32 ` Steven Rostedt
2026-07-22 6:10 ` [PATCH 2/4] tracing/user_events: Validate explicit struct field sizes Li Qiang
2026-07-22 16:33 ` Steven Rostedt
2026-07-22 17:27 ` Beau Belgrave [this message]
2026-07-22 6:10 ` [PATCH 3/4] tracing/inject: Validate entry allocation size Li Qiang
2026-07-22 19:45 ` Steven Rostedt
2026-07-22 6:10 ` [PATCH 4/4] tracing/inject: Prevent overflow growing string fields Li Qiang
2026-07-22 19:51 ` Steven Rostedt
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=20260722172732.GA212-beaub@linux.microsoft.com \
--to=beaub@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=liqiang01@kylinos.cn \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.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
Powered by JetHome