* [PATCH] tracing: Fix lock imbalance in s_start() memory allocation failure path
@ 2025-09-29 11:32 Sasha Levin
2025-09-29 18:03 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2025-09-29 11:32 UTC (permalink / raw)
To: rostedt, mhiramat, mathieu.desnoyers
Cc: linux-kernel, linux-trace-kernel, Sasha Levin
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 b355247df104 ("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.
Fixes: b355247df104 ("tracing: Cache ":mod:" events for modules not loaded yet")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/trace/trace_events.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 9f3e9537417d5..e00da4182deb7 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1629,11 +1629,10 @@ static void *s_start(struct seq_file *m, loff_t *pos)
loff_t l;
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+ mutex_lock(&event_mutex);
if (!iter)
return NULL;
- mutex_lock(&event_mutex);
-
iter->type = SET_EVENT_FILE;
iter->file = list_entry(&tr->events, struct trace_event_file, list);
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tracing: Fix lock imbalance in s_start() memory allocation failure path
2025-09-29 11:32 [PATCH] tracing: Fix lock imbalance in s_start() memory allocation failure path Sasha Levin
@ 2025-09-29 18:03 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2025-09-29 18:03 UTC (permalink / raw)
To: Sasha Levin; +Cc: mhiramat, mathieu.desnoyers, linux-kernel, linux-trace-kernel
On Mon, 29 Sep 2025 07:32:38 -0400
Sasha Levin <sashal@kernel.org> wrote:
> iff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 9f3e9537417d5..e00da4182deb7 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -1629,11 +1629,10 @@ static void *s_start(struct seq_file *m, loff_t *pos)
> loff_t l;
>
> iter = kzalloc(sizeof(*iter), GFP_KERNEL);
> + mutex_lock(&event_mutex);
> if (!iter)
> return NULL;
>
> - mutex_lock(&event_mutex);
> -
> iter->type = SET_EVENT_FILE;
> iter->file = list_entry(&tr->events, struct trace_event_file, list);
>
Good catch, thanks!
-- Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-29 18:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-29 11:32 [PATCH] tracing: Fix lock imbalance in s_start() memory allocation failure path Sasha Levin
2025-09-29 18:03 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).