2023-08-01 14:14:44

by Frederick Lawler

[permalink] [raw]
Subject: [PATCH] crypto: af_alg - Decrement struct key.usage in alg_set_by_key_serial()

Calls to lookup_user_key() require a corresponding key_put() to
decrement the usage counter. Once it reaches zero, we schedule key GC.
Therefore decrement struct key.usage in alg_set_by_key_serial().

Fixes: 7984ceb134bf ("crypto: af_alg - Support symmetric encryption via keyring keys")
Cc: <[email protected]>
Signed-off-by: Frederick Lawler <[email protected]>
---
This is rebased ontop of Linus's 6.5-rc1. Original patch was introduced in 6.2.
---
crypto/af_alg.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 6218c773d71c..295ede1996a4 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -320,18 +320,21 @@ static int alg_setkey_by_key_serial(struct alg_sock *ask, sockptr_t optval,

if (IS_ERR(ret)) {
up_read(&key->sem);
+ key_put(key);
return PTR_ERR(ret);
}

key_data = sock_kmalloc(&ask->sk, key_datalen, GFP_KERNEL);
if (!key_data) {
up_read(&key->sem);
+ key_put(key);
return -ENOMEM;
}

memcpy(key_data, ret, key_datalen);

up_read(&key->sem);
+ key_put(key);

err = type->setkey(ask->private, key_data, key_datalen);

--
2.34.1



2023-08-11 11:55:41

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: af_alg - Decrement struct key.usage in alg_set_by_key_serial()

On Tue, Aug 01, 2023 at 08:57:09AM -0500, Frederick Lawler wrote:
> Calls to lookup_user_key() require a corresponding key_put() to
> decrement the usage counter. Once it reaches zero, we schedule key GC.
> Therefore decrement struct key.usage in alg_set_by_key_serial().
>
> Fixes: 7984ceb134bf ("crypto: af_alg - Support symmetric encryption via keyring keys")
> Cc: <[email protected]>
> Signed-off-by: Frederick Lawler <[email protected]>
> ---
> This is rebased ontop of Linus's 6.5-rc1. Original patch was introduced in 6.2.
> ---
> crypto/af_alg.c | 3 +++
> 1 file changed, 3 insertions(+)

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt