Merge tag 'keys-next-6.14-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd

Pull keys fix from Jarkko Sakkinen:
"Fix potential use-after-free in key_put()"

* tag 'keys-next-6.14-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
keys: Fix UAF in key_put()

+6 -1
+1
include/linux/key.h
··· 236 #define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */ 237 #define KEY_FLAG_KEEP 8 /* set if key should not be removed */ 238 #define KEY_FLAG_UID_KEYRING 9 /* set if key is a user or user session keyring */ 239 240 /* the key type and key description string 241 * - the desc is used to match a key against search criteria
··· 236 #define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */ 237 #define KEY_FLAG_KEEP 8 /* set if key should not be removed */ 238 #define KEY_FLAG_UID_KEYRING 9 /* set if key is a user or user session keyring */ 239 + #define KEY_FLAG_FINAL_PUT 10 /* set if final put has happened on key */ 240 241 /* the key type and key description string 242 * - the desc is used to match a key against search criteria
+3 -1
security/keys/gc.c
··· 218 key = rb_entry(cursor, struct key, serial_node); 219 cursor = rb_next(cursor); 220 221 - if (refcount_read(&key->usage) == 0) 222 goto found_unreferenced_key; 223 224 if (unlikely(gc_state & KEY_GC_REAPING_DEAD_1)) { 225 if (key->type == key_gc_dead_keytype) {
··· 218 key = rb_entry(cursor, struct key, serial_node); 219 cursor = rb_next(cursor); 220 221 + if (test_bit(KEY_FLAG_FINAL_PUT, &key->flags)) { 222 + smp_mb(); /* Clobber key->user after FINAL_PUT seen. */ 223 goto found_unreferenced_key; 224 + } 225 226 if (unlikely(gc_state & KEY_GC_REAPING_DEAD_1)) { 227 if (key->type == key_gc_dead_keytype) {
+2
security/keys/key.c
··· 658 key->user->qnbytes -= key->quotalen; 659 spin_unlock_irqrestore(&key->user->lock, flags); 660 } 661 schedule_work(&key_gc_work); 662 } 663 }
··· 658 key->user->qnbytes -= key->quotalen; 659 spin_unlock_irqrestore(&key->user->lock, flags); 660 } 661 + smp_mb(); /* key->user before FINAL_PUT set. */ 662 + set_bit(KEY_FLAG_FINAL_PUT, &key->flags); 663 schedule_work(&key_gc_work); 664 } 665 }