keys: serialise instantiation against keyctl_chown_key
Subsystems (3)
PATCH 1/1 keys: serialise instantiation against keyctl_chown_key
keyctl_chown_key() replaces key->user under key->sem, but the instantiation path reads key->user without it: __key_instantiate_and_link() and key_reject_and_link() bump key->user->nikeys under key_construction_mutex only, and key_payload_reserve(), called from the type's instantiate op, reads key->user once for spin_lock_irqsave() and again for spin_unlock_irqrestore().
A chown of an under-construction key that lands between those two reads locks the old owner's quota spinlock and unlocks the new owner's. The paravirt unlock slow path reports the unheld unlock and the old lock is never released, so the next quota operation on that uid spins with interrupts disabled:
pvqspinlock: lock 0xffff88800f94dc38 has corrupted value 0x0!
WARNING: CPU: 2 PID: 215 at kernel/locking/qspinlock_paravirt.h:504 __pv_queued_spin_unlock_slowpath+0x1dc/0x2e0 Call Trace: _raw_spin_unlock_irqrestore+0xe/0x30 key_payload_reserve+0x230/0x300 generic_key_instantiate+0x47/0x230 __key_instantiate_and_link+0xbd/0x310 key_instantiate_and_link+0x3f0/0x490 keyctl_instantiate_key_common+0x246/0x410
The same unsynchronised read lets the instantiator touch the old key_user after the chown has dropped the last reference to it.
Hold key->sem for write across the instantiate op and the owner-record updates so that instantiation and chown serialise on the lock that already protects key->user. key->sem nests inside key_construction_mutex and the destination keyring's semaphore here; nothing takes the construction mutex under a key's semaphore. The acquisition is annotated as nested because a keyring instantiated into a keyring shares the destination's lock class; the key under construction cannot be a destination itself, so no cycle exists.
Reproducer: a request_key() helper that chowns the target key between two uids from one thread while instantiating it from another, as root. Triggers within tens of milliseconds on 6.12.104 and on mainline.
---
An AI tool helped with the analysis and the patch. I reviewed and tested it myself: the unpatched kernel hangs within 40 ms, the patched one ran the same workload for 60 s with lockdep on and no report.
security/keys/key.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
security/keys/key.c +11 -2
@@ -439,7 +439,13 @@mutex_lock (&key_construction_mutex); -/* can't instantiate twice */ +/* can't instantiate twice; key->sem keeps key->user stable against +* keyctl_chown_key() for the instantiate op and the quota update. +* Nested: the caller may hold the destination keyring's sem and the +* key under construction may be a keyring too, but it cannot be +* anyone's destination yet, so there is no cycle. +*/ +down_write_nested (&key->sem,1 );if (key->state ==KEY_IS_UNINSTANTIATED ) {/* instantiate the key */ ret = key->type->instantiate (key, prep);
@@ -469,6 +475,7 @@key_set_expiry (key, prep->expiry); } } +up_write (&key->sem);mutex_unlock (&key_construction_mutex);
@@ -600,7 +607,8 @@mutex_lock (&key_construction_mutex); -/* can't instantiate twice */ +/* can't instantiate twice; see __key_instantiate_and_link() */ +down_write_nested (&key->sem,1 );if (key->state ==KEY_IS_UNINSTANTIATED ) {/* mark the key as being negatively instantiated */ atomic_inc (&key->user->nikeys);
@@ -621,6 +629,7 @@if (authkey)key_invalidate (authkey); } +up_write (&key->sem);mutex_unlock (&key_construction_mutex);
Signature · 1 line
2.56.0
Jarkko Sakkinen
maintainerQuoted 54 lines · Sinan Turunc
keyctl_chown_key()replaceskey->userunderkey->sem, but the instantiation path readskey->userwithout it:__key_instantiate_and_link()andkey_reject_and_link()bumpkey->user->nikeysunderkey_construction_mutexonly, andkey_payload_reserve(), called from the type's instantiate op, readskey->useronce forspin_lock_irqsave()and again forspin_unlock_irqrestore().A chown of an under-construction key that lands between those two reads locks the old owner's quota spinlock and unlocks the new owner's. The paravirt unlock slow path reports the unheld unlock and the old lock is never released, so the next quota operation on that uid spins with interrupts disabled:
pvqspinlock: lock
0xffff88800f94dc38has corrupted value0x0!WARNING: CPU: 2 PID: 215 at kernel/locking/qspinlock_paravirt.h:504 __pv_queued_spin_unlock_slowpath+0x1dc/0x2e0 Call Trace: _raw_spin_unlock_irqrestore+0xe/0x30 key_payload_reserve+0x230/0x300 generic_key_instantiate+0x47/0x230 __key_instantiate_and_link+0xbd/0x310 key_instantiate_and_link+0x3f0/0x490 keyctl_instantiate_key_common+0x246/0x410The same unsynchronised read lets the instantiator touch the old
key_userafter the chown has dropped the last reference to it.Hold
key->semfor write across the instantiate op and the owner-record updates so that instantiation and chown serialise on the lock that already protectskey->user.key->semnests insidekey_construction_mutexand the destination keyring's semaphore here; nothing takes the construction mutex under a key's semaphore. The acquisition is annotated as nested because a keyring instantiated into a keyring shares the destination's lock class; the key under construction cannot be a destination itself, so no cycle exists.Reproducer: a
request_key()helper that chowns the target key between two uids from one thread while instantiating it from another, as root. Triggers within tens of milliseconds on 6.12.104 and on mainline.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Sinan Turunc <[email protected]>---
An AI tool helped with the analysis and the patch. I reviewed and tested it myself: the unpatched kernel hangs within 40 ms, the patched one ran the same workload for 60 s with lockdep on and no report.security/keys/key.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
security/keys/key.c line 447
Quoted 10 lines
security/keys/key.c +6
-1@@ -439,7 +439,13 @@mutex_lock (&key_construction_mutex); -/* can't instantiate twice */ +/* can't instantiate twice; key->sem keeps key->user stable against +* keyctl_chown_key() for the instantiate op and the quota update. +* Nested: the caller may hold the destination keyring's sem and the +* key under construction may be a keyring too, but it cannot be +* anyone's destination yet, so there is no cycle. +*/
:-(
Quoted 33 lines
security/keys/key.c +5
-1+down_write_nested (&key->sem,1 );if (key->state ==KEY_IS_UNINSTANTIATED ) {/* instantiate the key */ ret = key->type->instantiate (key, prep);@@ -469,6 +475,7 @@key_set_expiry (key, prep->expiry); } } +up_write (&key->sem);mutex_unlock (&key_construction_mutex);@@ -600,7 +607,8 @@mutex_lock (&key_construction_mutex); -/* can't instantiate twice */ +/* can't instantiate twice; see __key_instantiate_and_link() */ +down_write_nested (&key->sem,1 );if (key->state ==KEY_IS_UNINSTANTIATED ) {/* mark the key as being negatively instantiated */ atomic_inc (&key->user->nikeys);@@ -621,6 +629,7 @@if (authkey)key_invalidate (authkey); } +up_write (&key->sem);mutex_unlock (&key_construction_mutex);Signature · 1 line
2.56.0
Please review the LLM generated patch yourself at first and write a commit message thta you can understand yourself.
Plus, remove spurious inline comment changes. I'm only then going to review this.
Br, Jarkko
Jarkko Sakkinen
maintainerQuoted 5 lines · Jarkko Sakkinen
Please review the LLM generated patch yourself at first and write a commit message thta you can understand yourself.
Plus, remove spurious inline comment changes. I'm only then going to review this.
I.e., I have serious concerns that you might not know what you're doing. Well-formed commit is the way to get evidence on that.
br, Jarkko
Jarkko Sakkinen
maintainerQuoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
Please review the LLM generated patch yourself at first and write a commit message thta you can understand yourself.
Plus, remove spurious inline comment changes. I'm only then going to review this.
I.e., I have serious concerns that you might not know what you're doing. Well-formed commit is the way to get evidence on that.
E.g., if I pick and write proper explanation instead of slop, should I call it my own?
To have a review process, there must be two who think. Otherwise, it is just me figuring out all of this; and LLM. You have no role.
This is also why it is important to write proper commits.
Br, Jarkko
Jarkko Sakkinen
maintainerQuoted 11 lines · Jarkko Sakkinen
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
Please review the LLM generated patch yourself at first and write a commit message thta you can understand yourself.
Plus, remove spurious inline comment changes. I'm only then going to review this.
I.e., I have serious concerns that you might not know what you're doing. Well-formed commit is the way to get evidence on that.
Quoted 7 lines
E.g., if I pick and write proper explanation instead of slop, should I call it my own?
To have a review process, there must be two who think. Otherwise, it is just me figuring out all of this; and LLM. You have no role.
This is also why it is important to write proper commits.
Finally, while not knowing if this is the case, it is irresponsible as hell to send patches to subsystems like keyrings *if* you don't understand yourself exactly what you are doing.
Leaf driver mixes up only that leave driver; an uncosidered fix to a subsystem that is always on side-effects can do much worse.
Have you considered this?
I'll hold for for v2 :-) Just do the work properly. That's all.
Br, Jarkko
Hi Jarkko,
Sorry for the sloppy v1 patch and for over-relying on an LLM to write the commit message. That will not happen again. I have removed the inline comments and rewritten the commit message in my own words. Please let me know if any part of it is unclear, as I have tried to describe it as clearly as I can.
The race happens because keyctl_chown_key() looks up the target key by calling lookup_user_key() with KEY_LOOKUP_PARTIAL. That flag lets a caller with CAP_SYS_ADMIN change the UID of an uninstantiated key during construction. When the UID changes, keyctl_chown_key() swaps key->user under key->sem and drops the old reference with key_user_put(). __key_instantiate_and_link() and key_reject_and_link() only hold key_construction_mutex when they increment key->user->nikeys during construction. __key_instantiate_and_link() also calls the key type instantiate callback without holding key->sem on the key.
In key_payload_reserve(), when the key is in quota and its size changes, key->user is read without key->sem. It reads key->user once for spin_lock_irqsave(&key->user->lock, flags) and reads it again for spin_unlock_irqrestore(&key->user->lock, flags). If keyctl_chown_key() replaces key->user between those two reads, key_payload_reserve() unlocks the new spinlock and leaves the old spinlock held.
As the Sashiko review noted on v1, taking down_write_nested(&key->sem,
1) also causes a lockdep cycle against __key_move_lock(). A lockdep test on v1 triggered that warning on the first KEYCTL_MOVE call against the keyring instantiation order. __key_move_lock() takes subclass 1 before keyring_serialise_link_lock, while __key_link_lock() takes keyring_serialise_link_lock before __key_instantiate_and_link() takes key_construction_mutex. In v2 I switched down_write_nested() to subclass 2, which is an unused subclass taken only inside key_construction_mutex. That change ran clean under lockdep on both 7.4-rc2 and your for-next-keys branch across our test workloads.
I will send the v2 patch out to the list right after this message.
Thanks,
Sinan
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] keys: lockdep cycle via key->sem subclass 1 in __key_instantiate_and_link() - [Low] keys…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] keys: lockdep cycle via key->sem subclass 1 in __key_instantiate_and_link()
- [Low] keys: unresolvable Fixes trailer commit SHA 1da177e4c3f4 --
commit 63d8e840b5009e3c4507a5b0e1379f0f635dfd4b
Author: Sinan Turunc <[email protected]>
Quoted 37 lines
keys: serialise instantiation against
keyctl_chown_key
keyctl_chown_key()replaceskey->userunderkey->sem, but the instantiation path readskey->userwithout it:__key_instantiate_and_link()andkey_reject_and_link()bumpkey->user->nikeysunderkey_construction_mutexonly, andkey_payload_reserve(), called from the type's instantiate op, readskey->useronce forspin_lock_irqsave()and again forspin_unlock_irqrestore().A chown of an under-construction key that lands between those two reads locks the old owner's quota spinlock and unlocks the new owner's. The paravirt unlock slow path reports the unheld unlock and the old lock is never released, so the next quota operation on that uid spins with interrupts disabled:
pvqspinlock: lock
0xffff88800f94dc38has corrupted value0x0!WARNING: CPU: 2 PID: 215 at kernel/locking/qspinlock_paravirt.h:504 __pv_queued_spin_unlock_slowpath+0x1dc/0x2e0 Call Trace: _raw_spin_unlock_irqrestore+0xe/0x30 key_payload_reserve+0x230/0x300 generic_key_instantiate+0x47/0x230 __key_instantiate_and_link+0xbd/0x310 key_instantiate_and_link+0x3f0/0x490 keyctl_instantiate_key_common+0x246/0x410The same unsynchronised read lets the instantiator touch the old
key_userafter the chown has dropped the last reference to it.Hold
key->semfor write across the instantiate op and the owner-record updates so that instantiation and chown serialise on the lock that already protectskey->user.key->semnests insidekey_construction_mutexand the destination keyring's semaphore here; nothing takes the construction mutex under a key's semaphore. The acquisition is annotated as nested because a keyring instantiated into a keyring shares the destination's lock class; the key under construction cannot be a destination itself, so no cycle exists.
Quoted 7 lines
Reproducer: a
request_key()helper that chowns the target key between two uids from one thread while instantiating it from another, as root. Triggers within tens of milliseconds on 6.12.104 and on mainline.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Sinan Turunc <[email protected]>
[Severity: Low]
The commit sha in the Fixes: trailer cannot be resolved in the repository (it points to the initial git import).
Quoted 6 lines
security/keys/key.c +0
-0@@ -440,7 +440,13 @@ static int __key_instantiate_and_link(struct key *key,
security/keys/key.c static int __key_instantiate_and_link(struct key *key, · line 449
Quoted 10 lines
security/keys/key.c +7
-1mutex_lock (&key_construction_mutex); -/* can't instantiate twice */ +/* can't instantiate twice; key->sem keeps key->user stable against +* keyctl_chown_key() for the instantiate op and the quota update. +* Nested: the caller may hold the destination keyring's sem and the +* key under construction may be a keyring too, but it cannot be +* anyone's destination yet, so there is no cycle. +*/ +down_write_nested (&key->sem,1 );
[Severity: Medium]
Does using subclass 1 for key->sem in __key_instantiate_and_link() and key_reject_and_link() trigger a lockdep circular dependency report against __key_move_lock()?
All keyrings share &key_type_keyring.lock_class. When instantiating a keyring into a destination keyring, __key_link_lock() takes the destination keyring->sem (subclass 0) and then keyring_serialise_link_lock before __key_instantiate_and_link() takes key->sem at subclass 1. Moving a keyring via key_move() -> __key_move_lock() takes the second keyring's semaphore at subclass 1 before taking keyring_serialise_link_lock:
CPU0 CPU1
---- ----down_write(&keyring->sem)mutex_lock(&keyring_serialise_link_lock)
down_write(&l_keyring->sem)
down_write_nested(&u_keyring->sem, 1)
mutex_lock(&keyring_serialise_link_lock)mutex_lock(&key_construction_mutex)down_write_nested(&key->sem, 1)
*** DEADLOCK ***
CPU0: key_instantiate_and_link() -> __key_link_lock() /
__key_instantiate_and_link()
CPU1: keyctl_keyring_move() -> key_move() -> __key_move_lock()
Although an uninstantiated keyring cannot be looked up by keyctl_keyring_move() at runtime, reusing subclass 1 here inverts the lockdep order between (&key_type_keyring.lock_class, 1) and keyring_serialise_link_lock. Using a distinct subclass (such as 2) for key->sem in __key_instantiate_and_link() and key_reject_and_link() would avoid the collision.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
syzbot ci has tested the following series
syzbot ci has tested the following series
[v1] keys: serialise instantiation against keyctl_chown_key
https://lore.kernel.org/all/[email protected]
* [PATCH] keys: serialise instantiation against keyctl_chown_key
and found the following issue:
possible deadlock in key_move
Full report is available here:
https://ci.syzbot.org/series/51455b74-3344-42d0-9ba7-b64be2ff0b40
***
possible deadlock in key_move
tree: torvalds URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux base: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd arch: amd64 compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8 config: https://ci.syzbot.org/builds/309e9321-2f31-411e-ac93-724f183b5510/config syz repro: https://ci.syzbot.org/findings/89658ad2-f692-4500-bd4e-ef9d90dc18e5/syz_repro
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.0.17/5852 is trying to acquire lock:ffffffff908c1a40 (keyring_serialise_link_lock){+.+.}-{4:4}, at: __key_move_lock security/keys/keyring.c:1305 [inline] ffffffff908c1a40 (keyring_serialise_link_lock){+.+.}-{4:4}, at: key_move+0x1d3/0x7b0 security/keys/keyring.c:1634
but task is already holding lock:ffff888104aa1290 (&type->lock_class/1){+.+.}-{4:4}, at: __key_move_lock security/keys/keyring.c:-1 [inline] ffff888104aa1290 (&type->lock_class/1){+.+.}-{4:4}, at: key_move+0x16a/0x7b0 security/keys/keyring.c:1634
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&type->lock_class/1){+.+.}-{4:4}:
down_write_nested+0x98/0x200 kernel/locking/rwsem.c:1757
__key_instantiate_and_link+0x9d/0x4d0 security/keys/key.c:451
key_instantiate_and_link+0x331/0x4b0 security/keys/key.c:549
keyring_alloc+0x6f/0xb0 security/keys/keyring.c:541
system_trusted_keyring_init+0x67/0x120 certs/system_keyring.c:231
do_one_initcall+0x250/0x870 init/main.c:1419
do_initcall_level+0x10a/0x1a0 init/main.c:1481
do_initcalls+0x59/0xa0 init/main.c:1497
kernel_init_freeable+0x29d/0x3e0 init/main.c:1732
kernel_init+0x22/0x1d0 init/main.c:1622
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245-> #1 (key_construction_mutex){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x197/0x15a0 kernel/locking/mutex.c:821
__key_instantiate_and_link+0x8f/0x4d0 security/keys/key.c:443
key_instantiate_and_link+0x466/0x4b0 security/keys/key.c:549
keyring_alloc+0x6f/0xb0 security/keys/keyring.c:541
look_up_user_keyrings+0x376/0x670 security/keys/process_keys.c:116
do_one_initcall+0x250/0x870 init/main.c:1419
do_initcall_level+0x10a/0x1a0 init/main.c:1481
do_initcalls+0x59/0xa0 init/main.c:1497
kernel_init_freeable+0x29d/0x3e0 init/main.c:1732
kernel_init+0x22/0x1d0 init/main.c:1622
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245-> #0 (keyring_serialise_link_lock){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3209 [inline]
check_prevs_add kernel/locking/lockdep.c:3328 [inline]
validate_chain kernel/locking/lockdep.c:3952 [inline]
__lock_acquire+0x164c/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+0x197/0x15a0 kernel/locking/mutex.c:821
__key_move_lock security/keys/keyring.c:1305 [inline]
key_move+0x1d3/0x7b0 security/keys/keyring.c:1634
keyctl_keyring_move+0xd6/0x110 security/keys/keyctl.c:618
__do_sys_keyctl security/keys/keyctl.c:2023 [inline]
__se_sys_keyctl+0x85a/0xbc0 security/keys/keyctl.c:1885
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7fother info that might help us debug this:
Chain exists of: keyring_serialise_link_lock --> key_construction_mutex --> &type->lock_class/1 Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&type->lock_class/1);
lock(key_construction_mutex);
lock(&type->lock_class/1); lock(keyring_serialise_link_lock);
*** DEADLOCK ***
locks held by syz.0.17/5852: 2, on CPU#0:
#0: ffff888104aa1090 (&type->lock_class#2){+.+.}-{4:4}, at: __key_move_lock security/keys/keyring.c:-1 [inline] #0: ffff888104aa1090 (&type->lock_class#2){+.+.}-{4:4}, at: key_move+0x159/0x7b0 security/keys/keyring.c:1634 #1: ffff888104aa1290 (&type->lock_class/1){+.+.}-{4:4}, at: __key_move_lock security/keys/keyring.c:-1 [inline] #1: ffff888104aa1290 (&type->lock_class/1){+.+.}-{4:4}, at: key_move+0x16a/0x7b0 security/keys/keyring.c:1634
stack backtrace: CPU: 0 UID: 0 PID: 5852 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 print_circular_bug+0x2e2/0x300 kernel/locking/lockdep.c:2087 check_noncircular+0x12f/0x150 kernel/locking/lockdep.c:2219 check_prev_add kernel/locking/lockdep.c:3209 [inline] check_prevs_add kernel/locking/lockdep.c:3328 [inline] validate_chain kernel/locking/lockdep.c:3952 [inline] __lock_acquire+0x164c/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+0x197/0x15a0 kernel/locking/mutex.c:821 __key_move_lock security/keys/keyring.c:1305 [inline] key_move+0x1d3/0x7b0 security/keys/keyring.c:1634 keyctl_keyring_move+0xd6/0x110 security/keys/keyctl.c:618 __do_sys_keyctl security/keys/keyctl.c:2023 [inline] __se_sys_keyctl+0x85a/0xbc0 security/keys/keyctl.c:1885 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x171/0x540 arch/x86/entry/syscall_64.c:89 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f417a9a8fd9 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 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 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f417b7c9028 EFLAGS: 00000246 ORIG_RAX: 00000000000000fa RAX: ffffffffffffffda RBX: 00007f417ac25fa0 RCX: 00007f417a9a8fd9 RDX: fffffffffffffffe RSI: 00000000326b97d4 RDI: 000000000000001e RBP: 00007f417aa37fed R08: 0000000000000000 R09: 0000000000000000 R10: 00000000326b97d4 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f417ac26038 R14: 00007f417ac25fa0 R15: 00007ffc44b5b118 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
kernel test robot
build botkernel test robot noticed "WARNING:possible_circular_locking_dependency_detected" on:
Hello,
kernel test robot noticed "WARNING:possible_circular_locking_dependency_detected" on:
commit: a22ea46d3e3ee6e7fbea90bd9b1ff61cdcdc96c1 ("[PATCH] keys: serialise instantiation against keyctl_chown_key")
url: https://github.com/intel-lab-lkp/linux/commits/Sinan-Turunc/keys-serialise-instantiation-against-keyctl_chown_key/20261115-121740
base: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git 23c62304dde29abe92013d85910d03a77dada35d patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH] keys: serialise instantiation against keyctl_chown_key
in testcase: trinity
version: trinity-x86_64-216a8b36b-1_20261116
with following parameters:
runtime: 300s group: group-02 nr_groups: 5
config: x86_64-randconfig-121-20251020
compiler: gcc-14
test machine: qemu-system-x86_64 -enable-kvm -cpu Haswell-noTSX,enforce -smp 4 -m 16G
(please refer to attached dmesg/kmsg for entire log/backtrace)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
[ 227.133561][ T1501] WARNING: possible circular locking dependency detected
[ 227.137692][ T1501] 7.4.0-rc2-00717-ga22ea46d3e3e #1 Not tainted
[ 227.138989][ T1501] ------------------------------------------------------
[ 227.140436][ T1501] trinity-c3/1501 is trying to acquire lock:
[ 227.141691][ T1501] ffffffff838679e0 (keyring_serialise_link_lock){+.+.}-{4:4}, at: __key_move_lock (keys/keyring.c:1305)
[ 227.143815][ T1501] [ 227.143815][ T1501] but task is already holding lock:
[ 227.143815][ T1501]
[ 227.143815][ T1501] but task is already holding lock:
[ 227.143815][ T1501]
[ 227.143815][ T1501] but task is already holding lock:
[ 227.145340][ T1501] ffff88812a091e08 (&type->lock_class/1){+.+.}-{4:4}, at: __key_move_lock (keys/keyring.c:1298)
[ 227.147290][ T1501]
[ 227.147290][ T1501] which lock already depends on the new lock.
[ 227.147290][ T1501]
[ 227.147290][ T1501] which lock already depends on the new lock.
[ 227.147290][ T1501]
[ 227.147290][ T1501] which lock already depends on the new lock.
[ 227.147290][ T1501]
[ 227.149447][ T1501]
[ 227.149447][ T1501] the existing dependency chain (in reverse order) is:
[ 227.149447][ T1501]
[ 227.149447][ T1501] the existing dependency chain (in reverse order) is:
[ 227.149447][ T1501]
[ 227.149447][ T1501] the existing dependency chain (in reverse order) is:
[ 227.151296][ T1501]
[ 227.151296][ T1501] -> #2 (&type->lock_class/1){+.+.}-{4:4}:
[ 227.151296][ T1501]
[ 227.151296][ T1501] -> #2 (&type->lock_class/1){+.+.}-{4:4}:
[ 227.151296][ T1501]
[ 227.151296][ T1501] -> #2 (&type->lock_class/1){+.+.}-{4:4}:
[ 227.152939][ T1501] validate_chain (locking/lockdep.c:3328 locking/lockdep.c:3952)
[ 227.154012][ T1501] __lock_acquire (locking/lockdep.c:5288)
[ 227.155085][ T1501] lock_acquire (trace/events/lock.h:23 (discriminator 1) locking/lockdep.c:5905 (discriminator 1))
[ 227.156219][ T1501] lock_acquire (locking/lockdep.c:5907)
[ 227.157219][ T1501] down_write_nested (locking/rwsem.c:1757 (discriminator 1))
[ 227.158300][ T1501] __key_instantiate_and_link (keys/key.c:451)
[ 227.159581][ T1501] key_instantiate_and_link (keys/key.c:549)
[ 227.160804][ T1501] keyring_alloc (keys/keyring.c:541)
[ 227.161819][ T1501] blacklist_init (blacklist.c:337)
[ 227.162888][ T1501] do_one_initcall (main.c:1419)
[ 227.163950][ T1501] do_initcalls (main.c:1481 (discriminator 1) main.c:1497 (discriminator 1))
[ 227.164975][ T1501] kernel_init_freeable (main.c:1517 main.c:1732)
[ 227.166136][ T1501] kernel_init (main.c:1622)
[ 227.167132][ T1501] ret_from_fork (x86/kernel/process.c:158)
[ 227.168163][ T1501] ret_from_fork_asm (x86/entry/entry_64.S:245)
[ 227.169265][ T1501]
[ 227.169265][ T1501] -> #1 (key_construction_mutex){+.+.}-{4:4}:
[ 227.169265][ T1501]
[ 227.169265][ T1501] -> #1 (key_construction_mutex){+.+.}-{4:4}:
[ 227.169265][ T1501]
[ 227.169265][ T1501] -> #1 (key_construction_mutex){+.+.}-{4:4}:
[ 227.170969][ T1501] validate_chain (locking/lockdep.c:3328 locking/lockdep.c:3952)
[ 227.172036][ T1501] __lock_acquire (locking/lockdep.c:5288)
[ 227.173115][ T1501] lock_acquire (trace/events/lock.h:23 (discriminator 1) locking/lockdep.c:5905 (discriminator 1))
[ 227.189495][ T1501] lock_acquire (locking/lockdep.c:5907)
[ 227.191295][ T1501] __mutex_lock (locking/mutex.c:646 locking/mutex.c:821)
[ 227.193002][ T1501] mutex_lock_nested (locking/mutex.c:874 (discriminator 1))
[ 227.194980][ T1501] __key_instantiate_and_link (keys/key.c:443)
[ 227.197215][ T1501] key_instantiate_and_link (keys/key.c:549)
[ 227.199432][ T1501] keyring_alloc (keys/keyring.c:541)
[ 227.201173][ T1501] look_up_user_keyrings (keys/process_keys.c:116)
[ 227.202572][ T1501] init_root_keyring (keys/process_keys.c:1044)
[ 227.217442][ T1501] do_one_initcall (main.c:1419)
[ 227.219309][ T1501] do_initcalls (main.c:1481 (discriminator 1) main.c:1497 (discriminator 1))
[ 227.221127][ T1501] kernel_init_freeable (main.c:1517 main.c:1732)
[ 227.223114][ T1501] kernel_init (main.c:1622)
[ 227.224834][ T1501] ret_from_fork (x86/kernel/process.c:158)
[ 227.226598][ T1501] ret_from_fork_asm (x86/entry/entry_64.S:245)
[ 227.228485][ T1501]
[ 227.228485][ T1501] -> #0 (keyring_serialise_link_lock){+.+.}-{4:4}:
[ 227.228485][ T1501]
[ 227.228485][ T1501] -> #0 (keyring_serialise_link_lock){+.+.}-{4:4}:
[ 227.228485][ T1501]
[ 227.228485][ T1501] -> #0 (keyring_serialise_link_lock){+.+.}-{4:4}:
[ 227.231311][ T1501] check_noncircular (locking/lockdep.c:2219)
[ 227.233160][ T1501] check_prev_add (locking/lockdep.c:3209)
[ 227.235032][ T1501] validate_chain (locking/lockdep.c:3328 locking/lockdep.c:3952)
[ 227.236844][ T1501] __lock_acquire (locking/lockdep.c:5288)
[ 227.238525][ T1501] lock_acquire (trace/events/lock.h:23 (discriminator 1) locking/lockdep.c:5905 (discriminator 1))
[ 227.240157][ T1501] lock_acquire (locking/lockdep.c:5907)
[ 227.241603][ T1501] __mutex_lock (locking/mutex.c:646 locking/mutex.c:821)
[ 227.242975][ T1501] mutex_lock_nested (locking/mutex.c:874 (discriminator 1))
[ 227.244070][ T1501] __key_move_lock (keys/keyring.c:1305)
[ 227.245152][ T1501] key_move (keys/keyring.c:1634)
[ 227.246096][ T1501] keyctl_keyring_move (keys/keyctl.c:618 (discriminator 3))
[ 227.247227][ T1501] __do_sys_keyctl (keys/keyctl.c:2023)
[ 227.248314][ T1501] __x64_sys_keyctl (keys/keyctl.c:1885 keys/keyctl.c:1885)
[ 227.249389][ T1501] x64_sys_call (kbuild/obj/consumer/x86_64-randconfig-121-20251020/./arch/x86/include/generated/asm/syscalls_64.h:251)
[ 227.250447][ T1501] do_syscall_64 (x86/entry/syscall_64.c:61 x86/entry/syscall_64.c:89)
[ 227.251533][ T1501] entry_SYSCALL_64_after_hwframe (x86/entry/entry_64.S:121)
[ 227.252848][ T1501]
[ 227.252848][ T1501] other info that might help us debug this:
[ 227.252848][ T1501]
[ 227.252848][ T1501] other info that might help us debug this:
[ 227.252848][ T1501]
[ 227.252848][ T1501] other info that might help us debug this:
[ 227.252848][ T1501]
[ 227.255005][ T1501] Chain exists of:
[ 227.255005][ T1501] keyring_serialise_link_lock --> key_construction_mutex --> &type->lock_class/1
[ 227.255005][ T1501]The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20261119/[email protected]
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki