From: sashiko-bot@kernel.org
To: "Jaewon Jung" <jaewon8868@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb
Date: Sun, 29 Nov 2026 13:38:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-239638@kernel.org> (raw)
In-Reply-To: <20261129132918.852689-1-jaewon8868@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] tracing: incomplete overflow check in
buffer_subbuf_size_write()
--
commit 0482e7d96c18826f9dfdfebb60a0d8b69cd9465c
Author: Jaewon Jung <jaewon8868@gmail.com>
tracing: Check for overflow in buffer_subbuf_size_kb
This commit checks whether val exceeds ULONG_MAX / 1024 before multiplying
by 1024 in buffer_subbuf_size_write().
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 926a2eb247dfe..14b846b4136bd 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -8337,6 +8337,9 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf,
> if (ret)
> return ret;
>
> + /* Reject values that would overflow when converted to bytes. */
> + if (val > ULONG_MAX / 1024)
> + return -EINVAL;
> val *= 1024; /* value passed in is in KB */
>
> pages = DIV_ROUND_UP(val, PAGE_SIZE);
[Severity: Medium]
Can a large val still bypass the order check or overflow in DIV_ROUND_UP()?
On 64-bit systems, val is an unsigned long while pages is a 32-bit int, so
DIV_ROUND_UP(val, PAGE_SIZE) truncates to 32 bits. A value such as
0x400000004 KB (on 4 KB pages) passes val > ULONG_MAX / 1024 and yields
0x100000001 pages, which truncates to pages = 1 (order = 0) and sets an
unintended sub-buffer size. In addition, val == ULONG_MAX / 1024 passes
this check, and val + PAGE_SIZE - 1 inside DIV_ROUND_UP() then overflows
unsigned long.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129132918.852689-1-jaewon8868@gmail.com?part=1
next prev parent reply other threads:[~2026-11-29 13:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 13:28 [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb Jaewon Jung
2026-11-29 13:38 ` sashiko-bot [this message]
2026-11-29 13:42 ` 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=sashiko-outbox-239638@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jaewon8868@gmail.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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