All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yifan Zhang" <yfzhang23@stu.pku.edu.cn>,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] tracing/user_events: reject overflowing field offsets
Date: Mon, 02 Nov 2026 12:10:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-193372@kernel.org> (raw)
In-Reply-To: <179362071771.29269.8333068920166316746@stu.pku.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tracing/user_events: u32 struct size wrap in user_event_parse_field()
--

commit 3b2945a002d22d5a8a1ae3cae8f4c9ec6c460511
Author: Yifan Zhang <yfzhang23@stu.pku.edu.cn>

tracing/user_events: reject overflowing field offsets

This patch adds an overflow check in user_event_parse_field() to reject field
offsets that overflow a u32 or exceed INT_MAX when registering a user event.

> diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> index 85938b45b7618..88d384c9e101f 100644
> --- a/kernel/trace/trace_events_user.c
> +++ b/kernel/trace/trace_events_user.c
> @@ -1207,6 +1207,7 @@ static int user_event_parse_field(char *field, struct user_event *user,
>  {
>  	char *part, *type, *name;
>  	u32 depth = 0, saved_offset = *offset;
> +	u32 new_offset;
>  	int len, size = -EINVAL;
>  	bool is_struct = false;
>  
> @@ -1287,7 +1288,11 @@ static int user_event_parse_field(char *field, struct user_event *user,
>  	if (size < 0)
>  		return size;
>  
> -	*offset = saved_offset + size;
> +	if (check_add_overflow(saved_offset, (u32)size, &new_offset) ||
> +	    new_offset > INT_MAX)
> +		return -E2BIG;

[Severity: High]
What happens when a user supplies a struct field size between INT_MAX + 1 and
U32_MAX?

Earlier in user_event_parse_field(), the struct size is parsed into the signed
int variable size via kstrtou32():

	case FIELD_DEPTH_SIZE:
		if (!is_struct)
			return -EINVAL;

		if (kstrtou32(part, 10, &size))
			return -EINVAL;
		break;

When part is in [2147483648, 4294967295], kstrtou32() succeeds and writes a
value into size that is negative when interpreted as a signed int. The
preceding check:

	if (size < 0)
		return size;

then returns that user-controlled negative integer directly instead of
reaching the new overflow check.

When reached through user_events_ioctl() -> user_events_ioctl_reg() ->
user_event_parse_cmd() -> user_event_parse() -> user_event_parse_fields() ->
user_event_parse_field(), or through create_dyn_event() ->
user_event_create(), could this return arbitrary negative values (including
kernel-internal restart codes like -ERESTARTSYS, values outside [-MAX_ERRNO,
-1], or -ECANCELED) to the caller? Also, since both saved_offset and size are
bounded to INT_MAX after the size < 0 check, can check_add_overflow() ever
trigger here?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179362071771.29269.15129360535376085397@stu.pku.edu.cn?part=2

      parent reply	other threads:[~2026-11-02 12:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 11:58 [PATCH 0/2] tracing/user_events: harden dynamic field validation Yifan Zhang
2026-11-02 11:58 ` [PATCH 1/2] tracing/user_events: validate dynamic cpumask size Yifan Zhang
2026-11-02 11:58   ` Yifan Zhang
2026-11-02 11:58 ` [PATCH 2/2] tracing/user_events: reject overflowing field offsets Yifan Zhang
2026-11-02 11:58   ` Yifan Zhang
2026-11-02 12:10   ` sashiko-bot [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=sashiko-outbox-193372@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yfzhang23@stu.pku.edu.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.