mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: virtio/akcipher - Move a pointer assignment in virtio_crypto_rsa_set_key()
@ 2024-10-12  8:06 Markus Elfring
  2024-10-12  8:24 ` zhenwei pi
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2024-10-12  8:06 UTC (permalink / raw)
  To: virtualization, linux-crypto, David S. Miller,
	Eugenio Pérez, Gonglei, Herbert Xu, Jason Wang, lei he,
	Michael S. Tsirkin, Nathan Chancellor, Xuan Zhuo, zhenwei pi
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 12 Oct 2024 09:51:58 +0200

Move the reset of the data structure member “n” to a null pointer
into an if branch so that this assignment will be performed only after
a key parsing failure.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
index 48fee07b7e51..56557d4778b0 100644
--- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
+++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
@@ -355,7 +355,6 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,

 	/* mpi_free will test n, just free it. */
 	mpi_free(rsa_ctx->n);
-	rsa_ctx->n = NULL;

 	if (private) {
 		keytype = VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE;
@@ -365,8 +364,10 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,
 		ret = rsa_parse_pub_key(&rsa_key, key, keylen);
 	}

-	if (ret)
+	if (ret) {
+		rsa_ctx->n = NULL;
 		return ret;
+	}

 	rsa_ctx->n = mpi_read_raw_data(rsa_key.n, rsa_key.n_sz);
 	if (!rsa_ctx->n)
--
2.46.1


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

* Re: [PATCH] crypto: virtio/akcipher - Move a pointer assignment in virtio_crypto_rsa_set_key()
  2024-10-12  8:06 [PATCH] crypto: virtio/akcipher - Move a pointer assignment in virtio_crypto_rsa_set_key() Markus Elfring
@ 2024-10-12  8:24 ` zhenwei pi
  0 siblings, 0 replies; 2+ messages in thread
From: zhenwei pi @ 2024-10-12  8:24 UTC (permalink / raw)
  To: Markus Elfring, Gonglei
  Cc: LKML, linux-crypto, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
	Nathan Chancellor, virtualization, lei he, Herbert Xu,
	Eugenio Pérez, David S. Miller



On 10/12/24 16:06, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 12 Oct 2024 09:51:58 +0200
> 
> Move the reset of the data structure member “n” to a null pointer
> into an if branch so that this assignment will be performed only after
> a key parsing failure.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>   drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> index 48fee07b7e51..56557d4778b0 100644
> --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> @@ -355,7 +355,6 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,
> 
>   	/* mpi_free will test n, just free it. */
>   	mpi_free(rsa_ctx->n);
> -	rsa_ctx->n = NULL;
> 
>   	if (private) {
>   		keytype = VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE;
> @@ -365,8 +364,10 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,
>   		ret = rsa_parse_pub_key(&rsa_key, key, keylen);
>   	}
> 
> -	if (ret)
> +	if (ret) {
> +		rsa_ctx->n = NULL;
>   		return ret;
> +	}
> 
>   	rsa_ctx->n = mpi_read_raw_data(rsa_key.n, rsa_key.n_sz);
>   	if (!rsa_ctx->n)
> --

Hi,

This change only reduces a single assignment on a key parsing failure, 
however it breaks the original "free a pointer, and set it to NULL".
I prefer the original style.

Lei, what's your opinion?


> 2.46.1
> 


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

end of thread, other threads:[~2024-10-12  8:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-12  8:06 [PATCH] crypto: virtio/akcipher - Move a pointer assignment in virtio_crypto_rsa_set_key() Markus Elfring
2024-10-12  8:24 ` zhenwei pi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®