Skip to contentSkip to conversation

fscrypt: clear keyring before calling key_put()

PATCH Applied Luis Henriques 2 participants 3 messages Feb 6, 2024 – Feb 7, 2024 fscrypt: file system level encryption support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
Hi!

I know that patch "keys: update key quotas in key_put()" isn't yet merged but since David and Jarkko seem to be OK with it, it doesn't hurt to send this follow-up patch immediately.

Cheers,

Signature · 4 lines
Luis

 fs/crypto/keyring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/crypto/keyring.c +5 -2
index 0edf0b58daa7..dfdaae16b83a 100644
@@ -74,8 +74,11 @@ 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) {
+		keyring_clear(mk->mk_users);
+		key_put(mk->mk_users);
+		mk->mk_users = NULL;
+	}
 	call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key);
 }
 
maintainer Applied
#1 lore raw
Quoted 27 lines · Luis Henriques

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.

---
Hi!

I know that patch "keys: update key quotas in key_put()" isn't yet merged but since David and Jarkko seem to be OK with it, it doesn't hurt to send this follow-up patch immediately.

Cheers,

Signature · 4 lines
Luis

 fs/crypto/keyring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/crypto/keyring.c +0 -0
index 0edf0b58daa7..dfdaae16b83a 100644
@@ -74,8 +74,11 @@ void fscrypt_put_master_key(struct fscrypt_master_key *mk)
 	 * that concurrent keyring lookups can no longer find it.

fs/crypto/keyring.c void fscrypt_put_master_key(struct fscrypt_master_key *mk) · line 82

Quoted 10 lines
fs/crypto/keyring.c +5 -2
 	 */
 	WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 0);
-	key_put(mk->mk_users);
-	mk->mk_users = NULL;
+	if (mk->mk_users) {
+		keyring_clear(mk->mk_users);
+		key_put(mk->mk_users);
+		mk->mk_users = NULL;
+	}
 	call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key);

Applied, thanks. I added a comment above the call to keyring_clear() to explain why it's there:

        /* Clear the keyring so the quota gets released right away. */

- Eric

#2 lore raw
Quoted 42 lines · Eric Biggers
Quoted 27 lines · Luis Henriques

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.

---
Hi!

I know that patch "keys: update key quotas in key_put()" isn't yet merged but since David and Jarkko seem to be OK with it, it doesn't hurt to send this follow-up patch immediately.

Cheers,

Signature · 4 lines
Luis

 fs/crypto/keyring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/crypto/keyring.c +0 -0
index 0edf0b58daa7..dfdaae16b83a 100644
@@ -74,8 +74,11 @@ void fscrypt_put_master_key(struct fscrypt_master_key *mk)
 	 * that concurrent keyring lookups can no longer find it.

fs/crypto/keyring.c void fscrypt_put_master_key(struct fscrypt_master_key *mk) · line 82

Quoted 10 lines
fs/crypto/keyring.c +5 -2
 	 */
 	WARN_ON_ONCE(refcount_read(&mk->mk_active_refs) != 0);
-	key_put(mk->mk_users);
-	mk->mk_users = NULL;
+	if (mk->mk_users) {
+		keyring_clear(mk->mk_users);
+		key_put(mk->mk_users);
+		mk->mk_users = NULL;
+	}
 	call_rcu(&mk->mk_rcu_head, fscrypt_free_master_key);

Applied, thanks. I added a comment above the call to keyring_clear() to explain why it's there:

Quoted 1 line
        /* Clear the keyring so the quota gets released right away. */

Awesome, makes sense. Thanks a lot, Eric!

Cheers,

Signature · 1 line
Luís