History

keys: Fix UAF in key_put()

Once a key's reference count has been reduced to 0, the garbage collector thread may destroy it at any time and so key_put() is not allowed to touch the key after that point. The most key_put() is normally allowed to do is to touch key_gc_work as that's a static global variable. However, in an effort to speed up the reclamation of quota, this is now done in key_put() once the key's usage is reduced to 0 - but now the code is looking at the key after the deadline, which is forbidden. Fix this by using a flag to indicate that a key can be gc'd now rather than looking at the key's refcount in the garbage collector.

David Howells committed 1 year ago

Commit 75845c61 parent 88d324e3 files · +6 −1Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/key.h+1−0
@@ -236,6 +236,7 @@ struct key { · 235 unmodified lines
236236 #define KEY_FLAG_ROOT_CAN_INVAL 7 /* set if key can be invalidated by root without permission */
237237 #define KEY_FLAG_KEEP 8 /* set if key should not be removed */
238238 #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 */
239240
240241 /* the key type and key description string
241242 * - the desc is used to match a key against search criteria