All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.9 v2] virtio-crypto: zeroize the key material before free
@ 2016-12-07  2:29 Gonglei
  2016-12-07 15:21 ` Eric Blake
  2016-12-07 15:49 ` Max Reitz
  0 siblings, 2 replies; 14+ messages in thread
From: Gonglei @ 2016-12-07  2:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, stefanha, eblake, Gonglei

Common practice with sensitive information (key material, passwords,
etc). Prevents sensitive information from being exposed by accident later in
coredumps, memory disclosure bugs when heap memory is reused, etc.

Sensitive information is sometimes also held in mlocked pages to prevent
it being swapped to disk but that's not being done here.

Let's zeroize the memory of CryptoDevBackendSymOpInfo structure pointed
for key material security.

[v2: Stefan perfects the commit message, thanks]
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/virtio-crypto.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 2f2467e..ecb19b6 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -337,7 +337,18 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req)
 {
     if (req) {
         if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) {
-            g_free(req->u.sym_op_info);
+            size_t max_len;
+            CryptoDevBackendSymOpInfo *op_info = req->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);
         }
         g_free(req);
     }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-12-12  3:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-07  2:29 [Qemu-devel] [PATCH for-2.9 v2] virtio-crypto: zeroize the key material before free Gonglei
2016-12-07 15:21 ` Eric Blake
2016-12-08  2:33   ` Gonglei (Arei)
2016-12-08 15:20     ` Eric Blake
2016-12-11  2:51       ` Michael S. Tsirkin
2016-12-12  3:14         ` Gonglei (Arei)
2016-12-07 15:49 ` Max Reitz
2016-12-08  2:28   ` Gonglei (Arei)
2016-12-08 15:23     ` Eric Blake
2016-12-08 19:31       ` Max Reitz
2016-12-09  1:42         ` Gonglei (Arei)
2016-12-09 13:54           ` Max Reitz
2016-12-10  2:58             ` Gonglei (Arei)
2016-12-10 14:56               ` Max Reitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.