possible deadlock in lock_system_sleep (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: 32c52ec87d62 x86/insn-eval: Fix shadowed segment index in .. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=120a93a9580000 kernel config: https://syzkaller.appspot.com/x/.config?x=c4b098695335c89f dashboard link: https://syzkaller.appspot.com/bug?extid=1f0fbc2561b3e5d51b91 compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=141d098e580000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
============================================
WARNING: possible recursive locking detected
syzkaller #0 Not tainted
--------------------------------------------
syz.3.5755/5950 is trying to acquire lock:ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: lock_system_sleep+0x49/0x70 kernel/power/main.c:71
but task is already holding lock:ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __do_sys_reboot kernel/reboot.c:774 [inline] ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0x223/0x460 kernel/reboot.c:738
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(system_transition_mutex);
lock(system_transition_mutex);
*** DEADLOCK ***
May be due to missing lock nesting notation
locks held by syz.3.5755/5950: 1, last CPU#0:
#0: ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __do_sys_reboot kernel/reboot.c:774 [inline] #0: ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0x223/0x460 kernel/reboot.c:738
stack backtrace: CPU: 0 UID: 0 PID: 5950 Comm: syz.3.5755 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/07/2026 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 print_deadlock_bug+0x27a/0x290 kernel/locking/lockdep.c:3085 check_deadlock kernel/locking/lockdep.c:3137 [inline] validate_chain kernel/locking/lockdep.c:3939 [inline] __lock_acquire+0x25db/0x2de0 kernel/locking/lockdep.c:5288 lock_acquire+0x115/0x350 kernel/locking/lockdep.c:5942 __mutex_lock_common kernel/locking/mutex.c:646 [inline] __mutex_lock+0x19d/0x1550 kernel/locking/mutex.c:821 lock_system_sleep+0x49/0x70 kernel/power/main.c:71 hibernate+0x162/0x680 kernel/power/hibernate.c:784 __do_sys_reboot kernel/reboot.c:816 [inline] __se_sys_reboot+0x2ba/0x460 kernel/reboot.c:738 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fdb2419f809 Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffff22cee98 EFLAGS: 00000246 ORIG_RAX: 00000000000000a9 RAX: ffffffffffffffda RBX: 00007ffff22cefc8 RCX: 00007fdb2419f809 RDX: 00000000d000fce2 RSI: 0000000028121969 RDI: 00000000fee1dead RBP: 0000000000000001 R08: 0000000000000000 R09: 00007ffff22cefc8 R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffff22cefb8 R13: 0000000000000002 R14: 00007fdb24222cc0 R15: 0000000000000002 </TASK>
---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
From: Edward Aadm Davis <[email protected]>
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 32c52ec87d62
kernel/reboot.c +2 -2
@@ -813,8 +813,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,#ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND : - ret =hibernate (); -break ; +mutex_unlock (&system_transition_mutex); +return hibernate ();#endif default :
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 32c52ec8 x86/insn-eval: Fix shadowed segment index in .. git tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git console output: https://syzkaller.appspot.com/x/log.txt?x=17ef3831580000 kernel config: https://syzkaller.appspot.com/x/.config?x=c4b098695335c89f dashboard link: https://syzkaller.appspot.com/bug?extid=1f0fbc2561b3e5d51b91 compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 patch: https://syzkaller.appspot.com/x/patch.diff?x=148f298e580000
Note: testing is done by a robot and is best-effort only.
PATCH 1/1 kernel/reboot: Avoid potential deadlocks during suspension
In reply to syzbotInvoking reboot with LINUX_REBOOT_CMD_SW_SUSPEND causes kernel/reboot.c to acquire system_transition_mutex and invoke hibernate(). hibernate() calls lock_system_sleep(), which sets PF_NOFREEZE on current and attempts to acquire system_transition_mutex again, potentially hitting:
WARNING: possible recursive locking detected
--------------------------------------------
syz.3.5755/5950 is trying to acquire lock:ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: lock_system_sleep+0x49/0x70 kernel/power/main.c:71
but task is already holding lock:ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __do_sys_reboot kernel/reboot.c:774 [inline] ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0x223/0x460 kernel/reboot.c:738
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(system_transition_mutex);
lock(system_transition_mutex);
*** DEADLOCK ***
May be due to missing lock nesting notation
locks held by syz.3.5755/5950: 1, last CPU#0:
#0: ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __do_sys_reboot kernel/reboot.c:774 [inline] #0: ffffffff8fc04760 (system_transition_mutex){+.+.}-{4:4}, at: __se_sys_reboot+0x223/0x460 kernel/reboot.c:738
Call Trace: lock_system_sleep+0x49/0x70 kernel/power/main.c:71 hibernate+0x162/0x680 kernel/power/hibernate.c:784 __do_sys_reboot kernel/reboot.c:816 [inline]
Move the suspension operation outside the scope protected by lock system_transition_mutex.
--- kernel/reboot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/reboot.c +2 -2
@@ -813,8 +813,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,#ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND : - ret =hibernate (); -break ; +mutex_unlock (&system_transition_mutex); +return hibernate ();#endif default :
Signature · 1 line
2.43.0
Re: [PATCH] kernel/reboot: Avoid potential deadlocks during suspension
Quoted 40 lines · Edward Adam Davis
Invoking reboot with
LINUX_REBOOT_CMD_SW_SUSPENDcauseskernel/reboot.cto acquiresystem_transition_mutexand invokehibernate().hibernate()callslock_system_sleep(), which setsPF_NOFREEZEon current and attempts to acquiresystem_transition_mutexagain, potentially hitting:WARNING: possible recursive locking detected
--------------------------------------------
syz.3.5755/5950 is trying to acquire lock:ffffffff8fc04760(system_transition_mutex){+.+.}-{4:4}, at:lock_system_sleep+0x49/0x70kernel/power/main.c:71but task is already holding lock:
ffffffff8fc04760(system_transition_mutex){+.+.}-{4:4}, at:__do_sys_rebootkernel/reboot.c:774[inline]ffffffff8fc04760(system_transition_mutex){+.+.}-{4:4}, at:__se_sys_reboot+0x223/0x460kernel/reboot.c:738other info that might help us debug this:
Possible unsafe locking scenario:CPU0 ----
lock(system_transition_mutex);
lock(system_transition_mutex);*** DEADLOCK ***
May be due to missing lock nesting notation
locks held by syz.3.5755/5950: 1, last CPU#0:
#0:ffffffff8fc04760(system_transition_mutex){+.+.}-{4:4}, at:__do_sys_rebootkernel/reboot.c:774[inline]
#0:ffffffff8fc04760(system_transition_mutex){+.+.}-{4:4}, at:__se_sys_reboot+0x223/0x460 kernel/reboot.c:738 Call Trace: lock_system_sleep+0x49/0x70 kernel/power/main.c:71 hibernate+0x162/0x680 kernel/power/hibernate.c:784 __do_sys_reboot kernel/reboot.c:816 [inline]
Quoted 6 lines
Move the suspension operation outside the scope protected by lock
system_transition_mutex.Fixes 55f2503c3b69 ("PM / reboot: Eliminate race between reboot and suspend")Reported-by [email protected]
CC akpm:
Quoted 10 lines
Signed-off-by Edward Adam Davis <[email protected]>---
kernel/reboot.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)kernel/reboot.c +0
-0
kernel/reboot.c SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, · line 817
Quoted 7 lines
kernel/reboot.c +2
-2@@ -813,8 +813,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,#ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND : - ret =hibernate (); -break ; +mutex_unlock (&system_transition_mutex); +return hibernate ();
Well, this fixes the issue in hand,
kernel/reboot.c SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, · line 820
Quoted 4 lines
kernel/reboot.c +0
-0#endif default :
--- Thanks!
"I'm not a very positive person" - Linus torvalds