Skip to content

Commit 61e19cd

Browse files
Sasha Levinrostedt
authored andcommitted
tracing: Fix lock imbalance in s_start() memory allocation failure path
When s_start() fails to allocate memory for set_event_iter, it returns NULL before acquiring event_mutex. However, the corresponding s_stop() function always tries to unlock the mutex, causing a lock imbalance warning: WARNING: bad unlock balance detected! 6.17.0-rc7-00175-g2b2e0c04f78c #7 Not tainted ------------------------------------- syz.0.85611/376514 is trying to release lock (event_mutex) at: [<ffffffff8dafc7a4>] traverse.part.0.constprop.0+0x2c4/0x650 fs/seq_file.c:131 but there are no more locks to release! The issue was introduced by commit b355247 ("tracing: Cache ':mod:' events for modules not loaded yet") which added the kzalloc() allocation before the mutex lock, creating a path where s_start() could return without locking the mutex while s_stop() would still try to unlock it. Fix this by unconditionally acquiring the mutex immediately after allocation, regardless of whether the allocation succeeded. Cc: [email protected] Link: https://lore.kernel.org/[email protected] Fixes: b355247 ("tracing: Cache ":mod:" events for modules not loaded yet") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 2378a19 commit 61e19cd

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/trace/trace_events.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,11 +1629,10 @@ static void *s_start(struct seq_file *m, loff_t *pos)
16291629
loff_t l;
16301630

16311631
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
1632+
mutex_lock(&event_mutex);
16321633
if (!iter)
16331634
return NULL;
16341635

1635-
mutex_lock(&event_mutex);
1636-
16371636
iter->type = SET_EVENT_FILE;
16381637
iter->file = list_entry(&tr->events, struct trace_event_file, list);
16391638

0 commit comments

Comments
 (0)