Skip to content

Commit 8d7861a

Browse files
covanamrostedt
authored andcommitted
rv: Fix out-of-bound memory access in rv_is_container_monitor()
When rv_is_container_monitor() is called on the last monitor in rv_monitors_list, KASAN yells: BUG: KASAN: global-out-of-bounds in rv_is_container_monitor+0x101/0x110 Read of size 8 at addr ffffffff97c7c798 by task setup/221 The buggy address belongs to the variable: rv_monitors_list+0x18/0x40 This is due to list_next_entry() is called on the last entry in the list. It wraps around to the first list_head, and the first list_head is not embedded in struct rv_monitor_def. Fix it by checking if the monitor is last in the list. Cc: [email protected] Cc: Gabriele Monaco <[email protected]> Fixes: cb85c66 ("rv: Add option for nested monitors and include sched") Link: https://lore.kernel.org/e85b5eeb7228bfc23b8d7d4ab5411472c54ae91b.1744355018.git.namcao@linutronix.de Signed-off-by: Nam Cao <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 485acd2 commit 8d7861a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/trace/rv/rv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ bool rv_is_nested_monitor(struct rv_monitor_def *mdef)
225225
*/
226226
bool rv_is_container_monitor(struct rv_monitor_def *mdef)
227227
{
228-
struct rv_monitor_def *next = list_next_entry(mdef, list);
228+
struct rv_monitor_def *next;
229+
230+
if (list_is_last(&mdef->list, &rv_monitors_list))
231+
return false;
232+
233+
next = list_next_entry(mdef, list);
229234

230235
return next->parent == mdef->monitor || !mdef->monitor->enable;
231236
}

0 commit comments

Comments
 (0)