All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Jaewon Jung <jaewon8868@gmail.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] tracing: Check for overflow in buffer_subbuf_size_kb
Date: Sun, 29 Nov 2026 08:42:53 -0500	[thread overview]
Message-ID: <20261129084253.479418da@robin> (raw)
In-Reply-To: <20261129132918.852689-1-jaewon8868@gmail.com>

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);


      parent reply	other threads:[~2026-11-29 13:43 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
2026-11-29 13:42 ` Steven Rostedt [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=20261129084253.479418da@robin \
    --to=rostedt@goodmis.org \
    --cc=jaewon8868@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    /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.