KEYS changes for v7.3-rc7

This pull request contains two critical bug fixes, which can be briefly
 descibed as follows:
 
 1. key_get_persistent() creates a new persisten keyring for UID  if it does
    not exist yet, and creates a link from it to the nominated keyring.
    Function did not set timeout when linking failed, therefore preventing
    GC. The bug was addressed by calling key_set_timeout() regardless of
    key_link() result when the persistent keyring gets created by
    key_get_persistent().
 2. __key_create_or_update() made a copy of keyring->restrict_link before
    holding keyring->sem, which can cause add_key() to be executed against
    stale keyring restrictions. The bug was fixed by copying the value only
    after keyring->sem was taken.
 
 Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQRE6pSOnaBC00OEHEIaerohdGur0gUCasQmRQAKCRAaerohdGur
 0pa7APwKavlgnkGcbJNLA7kUz+2zt+tI9K/eT/5kgOaelesvmgEA5Xe6gvaXOtjr
 YaxQ2ySKAo4JvTtsPMWgaCn8p2hqVwc=
 =+UWf
 -----END PGP SIGNATURE-----

Merge tag 'keys-v7.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd

Pull keys fixes from Jarkko Sakkinen:

 - key_get_persistent() created a new persistent keyring if one did not
   exist, but failed to set a timeout on it in an error path, preventing
   GC.

   Call key_set_timeout() regardless of key_link() result if a
   persistent keyring was created.

 - __key_create_or_update() made a copy of keyring->restrict_link before
   holding keyring->sem, which could cause add_key() to be executed
   against stale keyring restrictions. Fix it by copying the value only
   after taking keyring->sem

* tag 'keys-v7.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
  KEYS: Fix add_key() race with keyring restriction
  keys: finalize persistent keyring timeout after link attempt
This commit is contained in:
Linus Torvalds 2026-10-06 04:51:54 +02:00
commit 2c3418fffa
2 changed files with 35 additions and 26 deletions