From: sashiko-bot@kernel.org
To: "David Carlier" <devnexen@gmail.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] ring-buffer: Check resize_disabled before publishing the new subbuf order
Date: Sat, 12 Sep 2026 10:56:59 +0000 [thread overview]
Message-ID: <20260912105659.6FC5B1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260912103938.1127021-1-devnexen@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing cpus_read_lock() allows concurrent CPU hotplug events to crash ring_buffer_subbuf_order_set() via uninitialized list dereference or NULL pointer dereference.
--
commit d554518f86e022de0069fc76033b9d71e9046148
Author: David Carlier <devnexen@gmail.com>
ring-buffer: Check resize_disabled before publishing the new subbuf order
This commit checks if resizing is disabled on any CPU before applying
the new sub-buffer order. This aims to prevent a race condition with
mmap fast paths mapping already-mapped CPUs with the new order.
Cc: stable@vger.kernel.org
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 9c03a555a6ba2..d7e5e4620d096 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -7474,6 +7474,14 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
>
> old_capacity = rb_subbuf_capacity(buffer);
>
> + /* The mmap fast path reads subbuf_order without buffer->mutex. */
> + for_each_buffer_cpu(buffer, cpu) {
> + if (!cpumask_test_cpu(cpu, buffer->cpumask))
> + continue;
> + if (atomic_read(&buffer->buffers[cpu]->resize_disabled))
> + return -EBUSY;
> + }
> +
[Severity: High]
Can this new loop race with concurrent CPU hotplug events and trigger a NULL
pointer dereference?
Unlike ring_buffer_resize(), ring_buffer_subbuf_order_set() doesn't appear
to take cpus_read_lock(). Meanwhile, trace_rb_cpu_prepare() can update
buffer->cpumask without holding buffer->mutex.
On weakly ordered architectures, could the lack of an smp_rmb() here cause
the reader to observe a newly added CPU in buffer->cpumask but load a NULL
buffer->buffers[cpu]?
Additionally, without cpus_read_lock(), if a CPU is added to the cpumask
between the allocation loop and the final page update loop later in this
function, new_pages will be an empty list head:
ring_buffer_subbuf_order_set() {
...
/* One page was allocated for the reader page */
cpu_buffer->reader_page = list_entry(cpu_buffer->new_pages.next,
struct buffer_page, list);
list_del_init(&cpu_buffer->reader_page->list);
...
}
Could this calculate a fake pointer overlapping the cpu_buffer struct and
corrupt memory when modified?
> atomic_inc(&buffer->record_disabled);
>
> /* Make sure all commits have finished */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260912103938.1127021-1-devnexen@gmail.com?part=1
next prev parent reply other threads:[~2026-09-12 10:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 10:39 [PATCH] ring-buffer: Check resize_disabled before publishing the new subbuf order David Carlier
2026-09-12 10:56 ` sashiko-bot [this message]
2026-09-12 11:59 ` David CARLIER
2026-09-13 20:38 ` Vincent Donnefort
2026-09-13 20:41 ` Vincent Donnefort
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=20260912105659.6FC5B1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=devnexen@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 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.