[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tencent_E5E3A2A44C1761976566C7D3658377C96A05@qq.com>
Date: Sat, 1 Feb 2025 13:50:55 +0800
From: Edward Adam Davis <eadavis@...com>
To: syzbot+c041985778e4069e1ce3@...kaller.appspotmail.com
Cc: rostedt@...dmis.org,
mhiramat@...nel.org,
mathieu.desnoyers@...icios.com,
linux-kernel@...r.kernel.org,
syzkaller-bugs@...glegroups.com
Subject: [PATCH] tracing: keep the event lock balanced
syzbot reported a bad unlock balance in seq_read_iter(). [1]
The reproducer uses "/proc/thread-self/fail-nth" to make s_start() fail when
applying for memory, thus exiting s_start() before acquiring event_mutex.
This destroys the lock holding and reclaiming process in the start() and
stop() processes in seq_read_iter().
Hold the event mutex before allocating memory in s_start() to avoid this
problem.
[1]
WARNING: bad unlock balance detected!
6.13.0-syzkaller-09760-g69e858e0b8b2 #0 Not tainted
-------------------------------------
syz-executor359/5828 is trying to release lock (event_mutex) at:
[<ffffffff8239231f>] seq_read_iter+0x5ff/0x12b0 fs/seq_file.c:251
but there are no more locks to release!
other info that might help us debug this:
1 lock held by syz-executor359/5828:
#0: ffff88802fd120a0 (&p->lock){+.+.}-{4:4}, at: seq_read_iter+0xd8/0x12b0 fs/seq_file.c:182
stack backtrace:
CPU: 0 UID: 0 PID: 5828 Comm: syz-executor359 Not tainted 6.13.0-syzkaller-09760-g69e858e0b8b2 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 12/27/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120
print_unlock_imbalance_bug kernel/locking/lockdep.c:5289 [inline]
print_unlock_imbalance_bug+0x1aa/0x1f0 kernel/locking/lockdep.c:5263
__lock_release kernel/locking/lockdep.c:5528 [inline]
lock_release+0x525/0x6f0 kernel/locking/lockdep.c:5872
__mutex_unlock_slowpath+0xa3/0x6a0 kernel/locking/mutex.c:891
seq_read_iter+0x5ff/0x12b0 fs/seq_file.c:251
seq_read+0x39f/0x4e0 fs/seq_file.c:162
vfs_read+0x1df/0xbf0 fs/read_write.c:563
ksys_read+0x12b/0x250 fs/read_write.c:708
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fixes: b355247df104 ("tracing: Cache ":mod:" events for modules not loaded yet")
Reported-by: syzbot+c041985778e4069e1ce3@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c041985778e4069e1ce3
Tested-by: syzbot+c041985778e4069e1ce3@...kaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@...com>
---
kernel/trace/trace_events.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 4cb275316e51..991dd17887ea 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1600,12 +1600,12 @@ static void *s_start(struct seq_file *m, loff_t *pos)
struct set_event_iter *iter;
loff_t l;
+ mutex_lock(&event_mutex);
+
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
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.43.0
Powered by blists - more mailing lists