Skip to content

Commit

Permalink
Merge tag 'keys-next-6.14-rc8' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…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()
  • Loading branch information
Linus Torvalds committed Mar 22, 2025
2 parents bb18645 + 75845c6 commit fcea541
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ struct key {
#define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */
#define KEY_FLAG_KEEP 8 /* set if key should not be removed */
#define KEY_FLAG_UID_KEYRING 9 /* set if key is a user or user session keyring */
#define KEY_FLAG_FINAL_PUT 10 /* set if final put has happened on key */

/* the key type and key description string
* - the desc is used to match a key against search criteria
Expand Down
4 changes: 3 additions & 1 deletion security/keys/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ static void key_garbage_collector(struct work_struct *work)
key = rb_entry(cursor, struct key, serial_node);
cursor = rb_next(cursor);

if (refcount_read(&key->usage) == 0)
if (test_bit(KEY_FLAG_FINAL_PUT, &key->flags)) {
smp_mb(); /* Clobber key->user after FINAL_PUT seen. */
goto found_unreferenced_key;
}

if (unlikely(gc_state & KEY_GC_REAPING_DEAD_1)) {
if (key->type == key_gc_dead_keytype) {
Expand Down
2 changes: 2 additions & 0 deletions security/keys/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ void key_put(struct key *key)
key->user->qnbytes -= key->quotalen;
spin_unlock_irqrestore(&key->user->lock, flags);
}
smp_mb(); /* key->user before FINAL_PUT set. */
set_bit(KEY_FLAG_FINAL_PUT, &key->flags);
schedule_work(&key_gc_work);
}
}
Expand Down

0 comments on commit fcea541

Please sign in to comment.