From d3a7bd4200762d11c33ebe7e2c47c5813ddc65b4 Mon Sep 17 00:00:00 2001 From: Luis Henriques Date: Tue, 6 Feb 2024 10:16:19 +0000 Subject: fscrypt: clear keyring before calling key_put() Now that the key quotas are handled immediately on key_put() instead of being postponed to the key management garbage collection worker, a call to keyring_clear() is all that is required in fscrypt_put_master_key() so that the keyring clean-up is also done synchronously. This patch should fix the fstest generic/581 flakiness. Signed-off-by: Luis Henriques Link: https://lore.kernel.org/r/20240206101619.8083-1-lhenriques@suse.de [ebiggers: added comment] Signed-off-by: Eric Biggers --- fs/crypto/keyring.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'fs') diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index 0edf0b58daa7..6681a71625f0 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -74,8 +74,12 @@ void fscrypt_put_master_key(struct fscrypt_master_key *mk) * that concurrent keyring lookups can no longer find it. */ WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 0); - key_put(mk->mk_users); - mk->mk_users = NULL; + if (mk->mk_users) { + /* Clear the keyring so the quota gets released right away. */ + keyring_clear(mk->mk_users); + key_put(mk->mk_users); + mk->mk_users = NULL; + } call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key); } -- cgit v1.2.3-58-ga151