Re: [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb

From: Steven Rostedt

Date: Sun Nov 29 2026 - 08:43:15 EST


On Sun, 29 Nov 2026 22:28:56 +0900
Jaewon Jung <jaewon8868@xxxxxxxxx> 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@xxxxxxxxx>
> ---
> 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);