[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/63] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_c
From: |
Michael S. Tsirkin |
Subject: |
[PULL 01/63] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session |
Date: |
Sun, 21 Jul 2024 20:16:50 -0400 |
From: Zheyu Ma <zheyuma97@gmail.com>
Currently, if the function fails during the key_len check, the op_code
does not have a proper value, causing virtio_crypto_free_create_session_req
not to free the memory correctly, leading to a memory leak.
By setting the op_code before performing any checks, we ensure that
virtio_crypto_free_create_session_req has the correct context to
perform cleanup operations properly, thus preventing memory leaks.
ASAN log:
==3055068==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 512 byte(s) in 1 object(s) allocated from:
#0 0x5586a75e6ddd in malloc
llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:129:3
#1 0x7fb6b63b6738 in g_malloc
(/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x5e738)
#2 0x5586a864bbde in virtio_crypto_handle_ctrl
hw/virtio/virtio-crypto.c:407:19
#3 0x5586a94fc84c in virtio_queue_notify_vq hw/virtio/virtio.c:2277:9
#4 0x5586a94fc0a2 in virtio_queue_host_notifier_read
hw/virtio/virtio.c:3641:9
Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
Message-Id: <20240702211835.3064505-1-zheyuma97@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-crypto.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index bbe8aa4b99..5034768bff 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -205,6 +205,7 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
int queue_index;
uint32_t algo, keytype, keylen;
+ sreq->info.op_code = opcode;
algo = ldl_le_p(&sess_req->para.algo);
keytype = ldl_le_p(&sess_req->para.keytype);
keylen = ldl_le_p(&sess_req->para.keylen);
@@ -224,7 +225,6 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
iov_discard_front(&iov, &out_num, keylen);
}
- sreq->info.op_code = opcode;
asym_info = &sreq->info.u.asym_sess_info;
asym_info->algo = algo;
asym_info->keytype = keytype;
--
MST
- [PULL 00/63] virtio,pci,pc: features,fixes, Michael S. Tsirkin, 2024/07/21
- [PULL 01/63] hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session,
Michael S. Tsirkin <=
- [PULL 02/63] MAINTAINERS: add Stefano Garzarella as vhost/vhost-user reviewer, Michael S. Tsirkin, 2024/07/21
- [PULL 04/63] hw/cxl: Check for multiple mappings of memory backends., Michael S. Tsirkin, 2024/07/21
- [PULL 05/63] hw/cxl/cxl-host: Fix segmentation fault when getting cxl-fmw property, Michael S. Tsirkin, 2024/07/21
- [PULL 03/63] hw/cxl/cxl-mailbox-utils: remove unneeded mailbox output payload space zeroing, Michael S. Tsirkin, 2024/07/21
- [PULL 07/63] hw/cxl/mbox: replace sanitize_running() with cxl_dev_media_disabled(), Michael S. Tsirkin, 2024/07/21
- [PULL 06/63] hw/cxl: Add get scan media capabilities cmd support, Michael S. Tsirkin, 2024/07/21
- [PULL 08/63] hw/cxl/events: discard all event records during sanitation, Michael S. Tsirkin, 2024/07/21
- [PULL 09/63] hw/cxl: Add get scan media results cmd support, Michael S. Tsirkin, 2024/07/21
- [PULL 10/63] cxl/mailbox: move mailbox effect definitions to a header, Michael S. Tsirkin, 2024/07/21
- [PULL 11/63] hw/cxl/cxl-mailbox-utils: Add support for feature commands (8.2.9.6), Michael S. Tsirkin, 2024/07/21