[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.1 05/32] crypto: avoid leak of ctx when bad cipher mode is g
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.1 05/32] crypto: avoid leak of ctx when bad cipher mode is given |
Date: |
Mon, 7 Oct 2024 22:16:22 +0300 |
From: Daniel P. Berrangé <berrange@redhat.com>
Fixes: Coverity CID 1546884
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 586ac2c67d707c2588766c5195d94fa553cc25af)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/crypto/cipher-nettle.c.inc b/crypto/cipher-nettle.c.inc
index 42b39e18a2..766de036ba 100644
--- a/crypto/cipher-nettle.c.inc
+++ b/crypto/cipher-nettle.c.inc
@@ -734,16 +734,19 @@ static QCryptoCipher
*qcrypto_cipher_ctx_new(QCryptoCipherAlgorithm alg,
#ifdef CONFIG_CRYPTO_SM4
case QCRYPTO_CIPHER_ALG_SM4:
{
- QCryptoNettleSm4 *ctx = g_new0(QCryptoNettleSm4, 1);
+ QCryptoNettleSm4 *ctx;
+ const QCryptoCipherDriver *drv;
switch (mode) {
case QCRYPTO_CIPHER_MODE_ECB:
- ctx->base.driver = &qcrypto_nettle_sm4_driver_ecb;
+ drv = &qcrypto_nettle_sm4_driver_ecb;
break;
default:
goto bad_cipher_mode;
}
+ ctx = g_new0(QCryptoNettleSm4, 1);
+ ctx->base.driver = drv;
sm4_set_encrypt_key(&ctx->key[0], key);
sm4_set_decrypt_key(&ctx->key[1], key);
--
2.39.5
- [Stable-9.1.1 00/32] Patch Round-up for stable 9.1.1, freeze on 2024-10-16, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 01/32] target/hppa: Fix PSW V-bit packaging in cpu_hppa_get for hppa64, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 03/32] crypto: run qcrypto_pbkdf2_count_iters in a new thread, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 02/32] iotests: fix expected output from gnutls, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 04/32] crypto: check gnutls & gcrypt support the requested pbkdf hash, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 05/32] crypto: avoid leak of ctx when bad cipher mode is given,
Michael Tokarev <=
- [Stable-9.1.1 07/32] tests/docker: update debian i686 and mipsel images to bookworm, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 08/32] contrib/plugins/Makefile: Add a 'distclean' target, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 06/32] tests/docker: remove debian-armel-cross, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 09/32] hw/audio/virtio-sound: fix heap buffer overflow, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 10/32] hw/intc/arm_gic: fix spurious level triggered interrupts, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 11/32] ui/sdl2: set swap interval explicitly when OpenGL is enabled, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 12/32] gitlab: fix logic for changing docker tag on stable branches, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 13/32] softmmu: Support concurrent bounce buffers, Michael Tokarev, 2024/10/07
- [Stable-9.1.1 14/32] softmmu/physmem: fix memory leak in dirty_memory_extend(), Michael Tokarev, 2024/10/07
- [Stable-9.1.1 15/32] softmmu/physmem.c: Keep transaction attribute in address_space_map(), Michael Tokarev, 2024/10/07