linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fscrypt: clear keyring before calling key_put()
@ 2024-02-06 10:16 Luis Henriques
  2024-02-07  0:57 ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Henriques @ 2024-02-06 10:16 UTC (permalink / raw)
  To: Eric Biggers, Theodore Y. Ts'o, Jaegeuk Kim
  Cc: David Howells, Jarkko Sakkinen, linux-fscrypt, linux-kernel,
	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.

Signed-off-by: Luis Henriques <lhenriques@suse.de>
---
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,
-- 
Luis

 fs/crypto/keyring.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c
index 0edf0b58daa7..dfdaae16b83a 100644
--- a/fs/crypto/keyring.c
+++ b/fs/crypto/keyring.c
@@ -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);
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fscrypt: clear keyring before calling key_put()
  2024-02-06 10:16 [PATCH] fscrypt: clear keyring before calling key_put() Luis Henriques
@ 2024-02-07  0:57 ` Eric Biggers
  2024-02-07  9:37   ` Luis Henriques
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2024-02-07  0:57 UTC (permalink / raw)
  To: Luis Henriques
  Cc: Theodore Y. Ts'o, Jaegeuk Kim, David Howells,
	Jarkko Sakkinen, linux-fscrypt, linux-kernel

On Tue, Feb 06, 2024 at 10:16:19AM +0000, Luis Henriques wrote:
> 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 <lhenriques@suse.de>
> ---
> 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,
> -- 
> Luis
> 
>  fs/crypto/keyring.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c
> index 0edf0b58daa7..dfdaae16b83a 100644
> --- a/fs/crypto/keyring.c
> +++ b/fs/crypto/keyring.c
> @@ -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);

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fscrypt: clear keyring before calling key_put()
  2024-02-07  0:57 ` Eric Biggers
@ 2024-02-07  9:37   ` Luis Henriques
  0 siblings, 0 replies; 3+ messages in thread
From: Luis Henriques @ 2024-02-07  9:37 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Theodore Y. Ts'o, Jaegeuk Kim, David Howells,
	Jarkko Sakkinen, linux-fscrypt, linux-kernel

Eric Biggers <ebiggers@kernel.org> writes:

> On Tue, Feb 06, 2024 at 10:16:19AM +0000, Luis Henriques wrote:
>> 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 <lhenriques@suse.de>
>> ---
>> 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,
>> -- 
>> Luis
>> 
>>  fs/crypto/keyring.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>> 
>> diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c
>> index 0edf0b58daa7..dfdaae16b83a 100644
>> --- a/fs/crypto/keyring.c
>> +++ b/fs/crypto/keyring.c
>> @@ -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);
>
> 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. */

Awesome, makes sense.  Thanks a lot, Eric!

Cheers,
-- 
Luís

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-07  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 10:16 [PATCH] fscrypt: clear keyring before calling key_put() Luis Henriques
2024-02-07  0:57 ` Eric Biggers
2024-02-07  9:37   ` Luis Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).