virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request
PATCH v2 1/1 virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request
Ensure op_info is not NULL in case of QCRYPTODEV_BACKEND_ALG_SYM algtype.
---
v2:
- updated 'Fixes:' tag
hw/virtio/virtio-crypto.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
hw/virtio/virtio-crypto.c +11 -9
@@ -476,15 +476,17 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)size_t max_len;CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; - max_len = op_info->iv_len + - op_info->aad_len + - op_info->src_len + - op_info->dst_len + - op_info->digest_result_len; - -/* Zeroize and free request data structure */ -memset (op_info,0 ,sizeof (*op_info) + max_len); -g_free (op_info); +if (op_info) { + max_len = op_info->iv_len + + op_info->aad_len + + op_info->src_len + + op_info->dst_len + + op_info->digest_result_len; + +/* Zeroize and free request data structure */ +memset (op_info,0 ,sizeof (*op_info) + max_len); +g_free (op_info); + } }else if (req->flags ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info;if (op_info) {
Signature · 1 line
2.40.1
Quoted 17 lines
-----Original Message-----
From: Mauro Matteo Cascella [mailto:[email protected]]
Sent: Tuesday, May 9, 2023 3:53 PM
To: [email protected]
Cc: [email protected]; Gonglei (Arei) <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2] virtio-crypto: fix NULL pointer dereference invirtio_crypto_free_requestEnsure
op_infois not NULL in case ofQCRYPTODEV_BACKEND_ALG_SYMalgtype.Fixes 0e660a6f90a ("crypto: Introduce RSA algorithm")Signed-off-by Mauro Matteo Cascella <[email protected]>Reported-by Yiming Tao <[email protected]>
Quoted 7 lines
---
v2:
- updated 'Fixes:' taghw/virtio/virtio-crypto.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
Regards,
-Gonglei
Quoted 36 lines
hw/virtio/virtio-crypto.c index renamed from hw/virtio/virtio-crypto.c +0
-0
2fe804510f..c729a1f79e100644hw/virtio/virtio-crypto.c +11
-9@@ -476,15 +476,17 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)size_t max_len;CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; - max_len = op_info->iv_len + - op_info->aad_len + - op_info->src_len + - op_info->dst_len + - op_info->digest_result_len; - -/* Zeroize and free request data structure */ -memset (op_info,0 ,sizeof (*op_info) + max_len); -g_free (op_info); +if (op_info) { + max_len = op_info->iv_len + + op_info->aad_len + + op_info->src_len + + op_info->dst_len + + op_info->digest_result_len; + +/* Zeroize and free request data structure */ +memset (op_info,0 ,sizeof (*op_info) + max_len); +g_free (op_info); + } }else if (req->flags ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo
*op_info=req->op_info.u.asym_op_info; if (op_info) {--
2.40.1
LGTM. Thanks!
Quoted 43 lines · Mauro Matteo Cascella
Ensure
op_infois not NULL in case ofQCRYPTODEV_BACKEND_ALG_SYMalgtype.Fixes 0e660a6f90a ("crypto: Introduce RSA algorithm")Signed-off-by Mauro Matteo Cascella <[email protected]>Reported-by Yiming Tao <[email protected]>---
v2:
- updated 'Fixes:' taghw/virtio/virtio-crypto.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)hw/virtio/virtio-crypto.c +11
-9@@ -476,15 +476,17 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)size_t max_len;CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; - max_len = op_info->iv_len + - op_info->aad_len + - op_info->src_len + - op_info->dst_len + - op_info->digest_result_len; - -/* Zeroize and free request data structure */ -memset (op_info,0 ,sizeof (*op_info) + max_len); -g_free (op_info); +if (op_info) { + max_len = op_info->iv_len + + op_info->aad_len + + op_info->src_len + + op_info->dst_len + + op_info->digest_result_len; + +/* Zeroize and free request data structure */ +memset (op_info,0 ,sizeof (*op_info) + max_len); +g_free (op_info); + } }else if (req->flags ==QCRYPTODEV_BACKEND_ALG_ASYM ) {CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info;if (op_info) {
Signature · 1 line
zhenwei pi