Skip to content

Commit 5026010

Browse files
mhiramatSasha Levin
authored andcommitted
tracing: ring-buffer: Fix to check event length before using
[ Upstream commit 912b0ee ] Check the event length before adding it for accessing next index in rb_read_data_buffer(). Since this function is used for validating possibly broken ring buffers, the length of the event could be broken. In that case, the new event (e + len) can point a wrong address. To avoid invalid memory access at boot, check whether the length of each event is in the possible range before using it. Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Fixes: 5f3b6e8 ("ring-buffer: Validate boot range memory events") Link: https://patch.msgid.link/177123421541.142205.9414352170164678966.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bc77986 commit 5026010

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

kernel/trace/ring_buffer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1813,16 +1813,20 @@ static int rb_read_data_buffer(struct buffer_data_page *dpage, int tail, int cpu
18131813
struct ring_buffer_event *event;
18141814
u64 ts, delta;
18151815
int events = 0;
1816+
int len;
18161817
int e;
18171818

18181819
*delta_ptr = 0;
18191820
*timestamp = 0;
18201821

18211822
ts = dpage->time_stamp;
18221823

1823-
for (e = 0; e < tail; e += rb_event_length(event)) {
1824+
for (e = 0; e < tail; e += len) {
18241825

18251826
event = (struct ring_buffer_event *)(dpage->data + e);
1827+
len = rb_event_length(event);
1828+
if (len <= 0 || len > tail - e)
1829+
return -1;
18261830

18271831
switch (event->type_len) {
18281832

0 commit comments

Comments
 (0)