Skip to content

Commit

Permalink
ring-buffer: Fix buffer locking in ring_buffer_subbuf_order_set()
Browse files Browse the repository at this point in the history
commit 40ee2af upstream.

Enlarge the critical section in ring_buffer_subbuf_order_set() to
ensure that error handling takes place with per-buffer mutex held,
thus preventing list corruption and other concurrency-related issues.

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Link: https://lore.kernel.org/20250606112242.1510605-1-dmantipov@yandex.ru
Reported-by: syzbot+05d673e83ec640f0ced9@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=05d673e83ec640f0ced9
Fixes: f9b94da ("ring-buffer: Set new size of the ring buffer sub page")
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Dmitry Antipov authored and Greg Kroah-Hartman committed Jun 19, 2025
1 parent e018053 commit 0fc9a29
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions kernel/trace/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6764,7 +6764,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
old_size = buffer->subbuf_size;

/* prevent another thread from changing buffer sizes */
mutex_lock(&buffer->mutex);
guard(mutex)(&buffer->mutex);
atomic_inc(&buffer->record_disabled);

/* Make sure all commits have finished */
Expand Down Expand Up @@ -6869,7 +6869,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
}

atomic_dec(&buffer->record_disabled);
mutex_unlock(&buffer->mutex);

return 0;

Expand All @@ -6878,7 +6877,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
buffer->subbuf_size = old_size;

atomic_dec(&buffer->record_disabled);
mutex_unlock(&buffer->mutex);

for_each_buffer_cpu(buffer, cpu) {
cpu_buffer = buffer->buffers[cpu];
Expand Down

0 comments on commit 0fc9a29

Please sign in to comment.