Skip to content

Commit a96e8ae

Browse files
ZheyuMaPatchew Applier
authored and
Patchew Applier
committed
hw/virtio/virtio-crypto: Fix op_code assignment in virtio_crypto_create_asym_session
The assignment of the op_code in the virtio_crypto_create_asym_session function was moved before its usage to ensure it is correctly set. Previously, if the function failed during the key_len check, the op_code did not have a proper value, causing virtio_crypto_free_create_session_req to not 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 <[email protected]> Message-Id: <[email protected]>
1 parent ff6d849 commit a96e8ae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

hw/virtio/virtio-crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
205205
int queue_index;
206206
uint32_t algo, keytype, keylen;
207207

208+
sreq->info.op_code = opcode;
208209
algo = ldl_le_p(&sess_req->para.algo);
209210
keytype = ldl_le_p(&sess_req->para.keytype);
210211
keylen = ldl_le_p(&sess_req->para.keylen);
@@ -224,7 +225,6 @@ virtio_crypto_create_asym_session(VirtIOCrypto *vcrypto,
224225
iov_discard_front(&iov, &out_num, keylen);
225226
}
226227

227-
sreq->info.op_code = opcode;
228228
asym_info = &sreq->info.u.asym_sess_info;
229229
asym_info->algo = algo;
230230
asym_info->keytype = keytype;

0 commit comments

Comments
 (0)