* [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb
@ 2026-11-29 13:28 Jaewon Jung
2026-11-29 13:42 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Jaewon Jung @ 2026-11-29 13:28 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers
Cc: linux-kernel, linux-trace-kernel
The KB-to-bytes conversion in buffer_subbuf_size_write() can overflow and
wrap a huge request to a small value, which then passes the page-order
limit and sets an unintended sub-buffer size. Check for it before the
multiplication.
Fixes: 2f84b39f4847 ("tracing: Update subbuffer with kilobytes not page order")
Signed-off-by: Jaewon Jung <jaewon8868@gmail.com>
---
kernel/trace/trace.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 65b9d67647e5..45cffadd52f6 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);
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb
2026-11-29 13:28 [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb Jaewon Jung
@ 2026-11-29 13:42 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2026-11-29 13:42 UTC (permalink / raw)
To: Jaewon Jung
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel, linux-trace-kernel
On Sun, 29 Nov 2026 22:28:56 +0900
Jaewon Jung <jaewon8868@gmail.com> wrote:
> The KB-to-bytes conversion in buffer_subbuf_size_write() can overflow and
> wrap a huge request to a small value, which then passes the page-order
> limit and sets an unintended sub-buffer size. Check for it before the
> multiplication.
>
If someone wants to put in stupid values, let them get stupid results ;-)
> Fixes: 2f84b39f4847 ("tracing: Update subbuffer with kilobytes not page order")
It doesn't break anything if an overflow happens so this patch doesn't fix anything.
> Signed-off-by: Jaewon Jung <jaewon8868@gmail.com>
> ---
> kernel/trace/trace.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 65b9d67647e5..45cffadd52f6 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;
It would be much better to just calculate the max and test against that:
/* Max size allowed is 128 pages in kilobytes */
if (val > ((128 * PAGE_SIZE) / 1024))
return -EINVAL;
-- Steve
> val *= 1024; /* value passed in is in KB */
>
> pages = DIV_ROUND_UP(val, PAGE_SIZE);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 13:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 13:28 [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb Jaewon Jung
2026-11-29 13:42 ` Steven Rostedt
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®