* [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query
@ 2025-04-16 7:48 Herbert Xu
2025-04-20 5:46 ` Lukas Wunner
0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2025-04-16 7:48 UTC (permalink / raw)
To: Linux Crypto Mailing List, Lukas Wunner, Ignat Korchagin
The recent code changes in this function triggered a false-positive
maybe-uninitialized warning in software_key_query. Rearrange the
code by moving the sig/tfm variables into the if clause where they
are actually used.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 89dc887d2c5c..e5b177c8e842 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -163,10 +163,8 @@ static u8 *pkey_pack_u32(u8 *dst, u32 val)
static int software_key_query(const struct kernel_pkey_params *params,
struct kernel_pkey_query *info)
{
- struct crypto_akcipher *tfm;
struct public_key *pkey = params->key->payload.data[asym_crypto];
char alg_name[CRYPTO_MAX_ALG_NAME];
- struct crypto_sig *sig;
u8 *key, *ptr;
int ret, len;
bool issig;
@@ -191,6 +189,8 @@ static int software_key_query(const struct kernel_pkey_params *params,
memset(info, 0, sizeof(*info));
if (issig) {
+ struct crypto_sig *sig;
+
sig = crypto_alloc_sig(alg_name, 0, 0);
if (IS_ERR(sig)) {
ret = PTR_ERR(sig);
@@ -202,7 +202,7 @@ static int software_key_query(const struct kernel_pkey_params *params,
else
ret = crypto_sig_set_pubkey(sig, key, pkey->keylen);
if (ret < 0)
- goto error_free_tfm;
+ goto error_free_sig;
len = crypto_sig_keysize(sig);
info->key_size = len;
@@ -221,7 +221,12 @@ static int software_key_query(const struct kernel_pkey_params *params,
if (pkey->key_is_private)
info->supported_ops |= KEYCTL_SUPPORTS_DECRYPT;
}
+
+error_free_sig:
+ crypto_free_sig(sig);
} else {
+ struct crypto_akcipher *tfm;
+
tfm = crypto_alloc_akcipher(alg_name, 0, 0);
if (IS_ERR(tfm)) {
ret = PTR_ERR(tfm);
@@ -233,7 +238,7 @@ static int software_key_query(const struct kernel_pkey_params *params,
else
ret = crypto_akcipher_set_pub_key(tfm, key, pkey->keylen);
if (ret < 0)
- goto error_free_tfm;
+ goto error_free_akcipher;
len = crypto_akcipher_maxsize(tfm);
info->key_size = len * BITS_PER_BYTE;
@@ -245,15 +250,11 @@ static int software_key_query(const struct kernel_pkey_params *params,
info->supported_ops = KEYCTL_SUPPORTS_ENCRYPT;
if (pkey->key_is_private)
info->supported_ops |= KEYCTL_SUPPORTS_DECRYPT;
+
+error_free_akcipher:
+ crypto_free_akcipher(tfm);
}
- ret = 0;
-
-error_free_tfm:
- if (issig)
- crypto_free_sig(sig);
- else
- crypto_free_akcipher(tfm);
error_free_key:
kfree_sensitive(key);
pr_devel("<==%s() = %d\n", __func__, ret);
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query
2025-04-16 7:48 [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query Herbert Xu
@ 2025-04-20 5:46 ` Lukas Wunner
2025-04-20 5:48 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Lukas Wunner @ 2025-04-20 5:46 UTC (permalink / raw)
To: Herbert Xu; +Cc: Linux Crypto Mailing List, Ignat Korchagin
On Wed, Apr 16, 2025 at 03:48:26PM +0800, Herbert Xu wrote:
> The recent code changes in this function triggered a false-positive
> maybe-uninitialized warning in software_key_query. Rearrange the
> code by moving the sig/tfm variables into the if clause where they
> are actually used.
>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Hm, I've tried to reproduce the warning with W=1 and W=2 to no avail
(with gcc 14). How did you trigger it?
FWIW,
Reviewed-by: Lukas Wunner <lukas@wunner.de>
I suppose this may have been introduced by 63ba4d67594a ("KEYS:
asymmetric: Use new crypto interface without scatterlists").
Thanks,
Lukas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query
2025-04-20 5:46 ` Lukas Wunner
@ 2025-04-20 5:48 ` Herbert Xu
0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2025-04-20 5:48 UTC (permalink / raw)
To: Lukas Wunner; +Cc: Linux Crypto Mailing List, Ignat Korchagin
On Sun, Apr 20, 2025 at 07:46:24AM +0200, Lukas Wunner wrote:
>
> Hm, I've tried to reproduce the warning with W=1 and W=2 to no avail
> (with gcc 14). How did you trigger it?
>
> FWIW,
> Reviewed-by: Lukas Wunner <lukas@wunner.de>
>
> I suppose this may have been introduced by 63ba4d67594a ("KEYS:
> asymmetric: Use new crypto interface without scatterlists").
It was with Debian stable gcc 12 so it could've been fixed already.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-20 5:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-16 7:48 [PATCH] crypto: public_key - Make sig/tfm local to if clause in software_key_query Herbert Xu
2025-04-20 5:46 ` Lukas Wunner
2025-04-20 5:48 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox