Skip to content

Commit 40ee2af

Browse files
dmantipovrostedt
authored andcommitted
ring-buffer: Fix buffer locking in ring_buffer_subbuf_order_set()
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: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Tzvetomir Stoyanov <[email protected]> Link: https://lore.kernel.org/[email protected] Reported-by: [email protected] 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 <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent a9d0aab commit 40ee2af

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

kernel/trace/ring_buffer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6795,7 +6795,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
67956795
old_size = buffer->subbuf_size;
67966796

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

68016801
/* Make sure all commits have finished */
@@ -6900,7 +6900,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
69006900
}
69016901

69026902
atomic_dec(&buffer->record_disabled);
6903-
mutex_unlock(&buffer->mutex);
69046903

69056904
return 0;
69066905

@@ -6909,7 +6908,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
69096908
buffer->subbuf_size = old_size;
69106909

69116910
atomic_dec(&buffer->record_disabled);
6912-
mutex_unlock(&buffer->mutex);
69136911

69146912
for_each_buffer_cpu(buffer, cpu) {
69156913
cpu_buffer = buffer->buffers[cpu];

0 commit comments

Comments
 (0)