Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb
@ 2026-11-29 13:28 Jaewon Jung
  2026-11-29 13:38 ` sashiko-bot
  2026-11-29 13:42 ` Steven Rostedt
  0 siblings, 2 replies; 3+ 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 related	[flat|nested] 3+ 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:38 ` sashiko-bot
  2026-11-29 13:42 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-29 13:38 UTC (permalink / raw)
  To: Jaewon Jung; +Cc: linux-trace-kernel

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

^ permalink raw reply	[flat|nested] 3+ 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:38 ` sashiko-bot
@ 2026-11-29 13:42 ` Steven Rostedt
  1 sibling, 0 replies; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2026-11-29 13:43 UTC | newest]

Thread overview: 3+ 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:38 ` sashiko-bot
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