keys: update key quotas in key_put()
authorLuis Henriques <lhenriques@suse.de>
Tue, 30 Jan 2024 10:13:44 +0000 (10:13 +0000)
committerJarkko Sakkinen <jarkko@kernel.org>
Thu, 9 May 2024 13:28:58 +0000 (16:28 +0300)
commit9578e327b2b4935a25d49e3891b8fcca9b6c10c6
tree5b61b324bd79925ebcc6cae2139a4b81a084bd0e
parent45db3ab70092637967967bfd8e6144017638563c
keys: update key quotas in key_put()

Delaying key quotas update when key's refcount reaches 0 in key_put() has
been causing some issues in fscrypt testing, specifically in fstest
generic/581.  This commit fixes this test flakiness by dealing with the
quotas immediately, and leaving all the other clean-ups to the key garbage
collector.

This is done by moving the updates to the qnkeys and qnbytes fields in
struct key_user from key_gc_unused_keys() into key_put().  Unfortunately,
this also means that we need to switch to the irq-version of the spinlock
that protects these fields and use spin_lock_{irqsave,irqrestore} in all
the code that touches these fields.

Signed-off-by: Luis Henriques <lhenriques@suse.de>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Acked-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@kernel.org>
security/keys/gc.c
security/keys/key.c
security/keys/keyctl.c