summaryrefslogtreecommitdiff
path: root/include/linux/processor.h
diff options
context:
space:
mode:
authorCen Zhang <zzzccc427@gmail.com>2026-10-31 17:26:36 +0800
committerJarkko Sakkinen <jarkko@kernel.org>2026-11-05 19:19:36 +0200
commit51bcd09b9ffca7a2a3b66fb57182bb391364f612 (patch)
treef10e86f4e79cc2b96c2a7c517fdb4f749ec99dd6 /include/linux/processor.h
parent7a7f70ff7b26519c98b339a3e0cd9ee3c8d17f77 (diff)
KEYS: Protect the update method check against type removal
key_update() reads key->type->update, ->def_datalen and ->preparse before it takes key->sem. A reference on the key does not pin the module that provides its type, so KEYCTL_UPDATE can race with the unloading of that module, for example dns_resolver: KEYCTL_UPDATE task Module unload and key GC ------------------ ------------------------ keyctl_update_key() key_update() key_permission() load key->type exit_dns_resolver() unregister_key_type() GC: down_write(&key->sem) GC: retype to key_type_dead GC: up_write(&key->sem) unregister_key_type() returns free_module() read saved type's update member The final access reads freed module memory. With the updating task held after the key->type load, it faults: BUG: unable to handle page fault for address: fffffbfff804107f #PF: supervisor read access in kernel mode RIP: 0010:key_update+0x12d/0x550 Call Trace: keyctl_update_key+0x6b/0x110 __do_sys_keyctl+0x21d/0x4f0 This is the same problem that commit 925c84e3cc21 ("keys: Protect the read method check against type removal") fixed for KEYCTL_READ. For dns_resolver, which has no update method, key_update() returns at the check, so doing the check with key->sem held would be enough. A key type that is built as a module and has an update method, like encrypted or trusted, gets past the check. If its module is unloaded after the check and before key_update() takes key->sem, the GC has already moved the key to key_type_dead, and key_update() calls the update method of key_type_dead, which is NULL. So key->sem has to stay held from the check until the update is done. Take key->sem before the first access to key->type and hold it until the preparsed payload has been freed. Once a key exists, only the GC changes key->type, and it does so with key->sem held for writing. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Cen Zhang <zzzccc427@gmail.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Reviewed-by: Eric Biggers <ebiggers@kernel.org> Link: https://lore.kernel.org/r/pm-keys-update-type-removal-20261029-v8-a0dbc48c588bf2b6a278@gmail.com Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Diffstat (limited to 'include/linux/processor.h')
0 files changed, 0 insertions, 0 deletions