]> git.hungrycats.org Git - linux/commitdiff
tracing: Fix retry exhaustion in simple ring buffer reader swap
authorIvan Immanuel Shaji <ivanimmanuel1234@gmail.com>
Tue, 25 Aug 2026 16:52:49 +0000 (12:52 -0400)
committerSteven Rostedt <rostedt@goodmis.org>
Fri, 28 Aug 2026 01:31:41 +0000 (21:31 -0400)
simple_ring_buffer_swap_reader_page() starts with retry set to 8 and
post-decrements it only after a failed link replacement. On the final
attempt, a successful replacement leaves retry at zero, while a failed
replacement leaves it at -1.

The current !retry test reverses both outcomes. It returns an error after
a successful final replacement, leaving the link update complete but the
reader bookkeeping unfinished. After a failed final replacement, it
falls through and updates the head and reader pointers as though the
replacement succeeded, which can corrupt the ring.

Treat only a negative counter as exhaustion and return the documented
-EBUSY error.

Cc: stable@vger.kernel.org
Fixes: 34e5b958bdad ("tracing: Introduce simple_ring_buffer")
Link: https://patch.msgid.link/20260825-kernel-patch-1-v2-1-bb3461807a32@gmail.com
Assisted-by: LLM sparse
Reviewed-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Ivan Immanuel Shaji <ivanimmanuel1234@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/simple_ring_buffer.c

index f4642f5adda3343967a44e87f120a21451cc4bb6..49913bb0057a7e6127f2390a8e7d4314c10e984b 100644 (file)
@@ -160,8 +160,8 @@ int simple_ring_buffer_swap_reader_page(struct simple_rb_per_cpu *cpu_buffer)
                overrun = cpu_buffer->meta->overrun;
        } while (!simple_bpage_unset_head_link(last, reader, SIMPLE_RB_LINK_NORMAL) && retry--);
 
-       if (!retry)
-               return -EINVAL;
+       if (retry < 0)
+               return -EBUSY;
 
        cpu_buffer->head_page = simple_bpage_from_link(reader->link.next);
        cpu_buffer->head_page->link.prev = &reader->link;