Re: [RFC PATCH v2] keys: update key quotas in key_put()

From: Eric Biggers
Date: Wed Jan 24 2024 - 17:12:35 EST


On Mon, Jan 15, 2024 at 12:03:00PM +0000, Luis Henriques wrote:
> Delaying key quotas update when key's refcount reaches 0 in key_put() has
> been causing some issues in fscrypt testing. This patches fixes this test
> flakiness by dealing with the quotas immediately, but leaving all the other
> clean-ups to the key garbage collector. Unfortunately, this means that we
> also need to switch to the irq-version of the spinlock that protects quota.
>
> Signed-off-by: Luis Henriques <lhenriques@xxxxxxx>
> ---
> Hi David!
>
> I have these changes in my local disk for a while; I wanted to send them
> before EOY break but... yeah, it didn't happen. Anyway, I'm still sending
> it as an RFC as I'm probably missing something.
>
> security/keys/gc.c | 8 --------
> security/keys/key.c | 32 ++++++++++++++++++++++----------
> security/keys/keyctl.c | 11 ++++++-----
> 3 files changed, 28 insertions(+), 23 deletions(-)

This patch seems reasonable to me, though I'm still thinking about changing
fs/crypto/ to manage its key quotas itself which would avoid the issue entirely.

Note that as I said before, fs/crypto/ does key_put() on a whole keyring at
once, in order to release the quota of the keys in the keyring. Do you plan to
also change fs/crypto/ to keyring_clear() the keyring before putting it?
Without that, I don't think the problem is solved, as the quota release will
still happen asynchronously due to the keyring being cleared asynchronously.

- Eric