Skip to contentSkip to conversation

virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request

PATCH Superseded Mauro Matteo Cascella 3 participants 4 messages May 8, 2023 – May 9, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

Fixes 02ed3e7c ("virtio-crypto: zeroize the key material before free")
---
 hw/virtio/virtio-crypto.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
hw/virtio/virtio-crypto.c +11 -9
index 2fe804510f..c729a1f79e 100644
@@ -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
#1 lore raw
Quoted 11 lines

-----Original Message-----
From: Mauro Matteo Cascella [mailto:[email protected]]
Sent: Monday, May 8, 2023 11:02 PM
To: [email protected]
Cc: [email protected]; Gonglei (Arei) <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request

Quoted 4 lines

Ensure op_info is not NULL in case of QCRYPTODEV_BACKEND_ALG_SYM algtype.

Fixes 02ed3e7c ("virtio-crypto: zeroize the key material before free")

I have to say the fixes is incorrect. The bug was introduced by commit 0e660a6f90a, which changed the semantic meaning of request-> flag.

Regards,
-Gonglei

#2 lore raw
Quoted 14 lines · Gonglei (Arei)
Quoted 14 lines

-----Original Message-----
From: Mauro Matteo Cascella [mailto:[email protected]]
Sent: Monday, May 8, 2023 11:02 PM
To: [email protected]
Cc: [email protected]; Gonglei (Arei) <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] 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.

Quoted 8 lines
Quoted 1 line
Fixes 02ed3e7c ("virtio-crypto: zeroize the key material before free")

I have to say the fixes is incorrect. The bug was introduced by commit 0e660a6f90a, which changed the semantic meaning of request-> flag.

Regards,
-Gonglei

Hi Mauro

Agree with Lei, could you please change the Fixes as Lei suggested?

Signature · 1 line
zhenwei pi
#3 lore raw
Quoted 23 lines · zhenwei pi
Quoted 19 lines · Gonglei (Arei)
Quoted 11 lines

-----Original Message-----
From: Mauro Matteo Cascella [mailto:[email protected]]
Sent: Monday, May 8, 2023 11:02 PM
To: [email protected]
Cc: [email protected]; Gonglei (Arei) <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request

Quoted 4 lines

Ensure op_info is not NULL in case of QCRYPTODEV_BACKEND_ALG_SYM algtype.

Fixes 02ed3e7c ("virtio-crypto: zeroize the key material before free")

I have to say the fixes is incorrect. The bug was introduced by commit 0e660a6f90a, which changed the semantic meaning of request-> flag.

Quoted 7 lines
Quoted 3 lines

Regards,
-Gonglei

Hi Mauro

Agree with Lei, could you please change the Fixes as Lei suggested?

Sent v2.

Thanks!

Quoted 3 lines

--
zhenwei pi

Signature · 3 lines
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0