]> Git Repo - qemu.git/commitdiff
virtio-crypto: fix possible integer and heap overflow
authorGonglei <[email protected]>
Tue, 3 Jan 2017 06:50:03 +0000 (14:50 +0800)
committerMichael S. Tsirkin <[email protected]>
Tue, 10 Jan 2017 03:56:58 +0000 (05:56 +0200)
Because the 'size_t' type is 4 bytes in 32-bit platform, which
is the same with 'int'. It's easy to make 'max_len' to zero when
integer overflow and then cause heap overflow if 'max_len' is zero.

Using uint_64 instead of size_t to avoid the integer overflow.

Cc: [email protected]
Reported-by: Li Qiang <[email protected]>
Signed-off-by: Gonglei <[email protected]>
Tested-by: Li Qiang <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
hw/virtio/virtio-crypto.c

index 2f2467e859f0941c8ecd9d0aaa6b5daa4c29d30e..c23e1ad4588a4d17c9f1e4553d1186c053fe5e29 100644 (file)
@@ -416,7 +416,7 @@ virtio_crypto_sym_op_helper(VirtIODevice *vdev,
     uint32_t hash_start_src_offset = 0, len_to_hash = 0;
     uint32_t cipher_start_src_offset = 0, len_to_cipher = 0;
 
-    size_t max_len, curr_size = 0;
+    uint64_t max_len, curr_size = 0;
     size_t s;
 
     /* Plain cipher */
@@ -441,7 +441,7 @@ virtio_crypto_sym_op_helper(VirtIODevice *vdev,
         return NULL;
     }
 
-    max_len = iv_len + aad_len + src_len + dst_len + hash_result_len;
+    max_len = (uint64_t)iv_len + aad_len + src_len + dst_len + hash_result_len;
     if (unlikely(max_len > vcrypto->conf.max_size)) {
         virtio_error(vdev, "virtio-crypto too big length");
         return NULL;
This page took 0.027915 seconds and 4 git commands to generate.