]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
luks: Catch integer overflow for huge sizes
authorKevin Wolf <kwolf@redhat.com>
Mon, 5 Mar 2018 17:15:26 +0000 (18:15 +0100)
committerKevin Wolf <kwolf@redhat.com>
Mon, 19 Mar 2018 11:01:24 +0000 (12:01 +0100)
When you request an image size close to UINT64_MAX, the addition of the
crypto header may cause an integer overflow. Catch it instead of
silently truncating the image size.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
block/crypto.c

index 00fb40c631445b221cb205eae4fc9886f2d80888..e0b8856f74357c7103b242e522e4927f16c22166 100644 (file)
@@ -102,6 +102,11 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
 {
     struct BlockCryptoCreateData *data = opaque;
 
+    if (data->size > INT64_MAX || headerlen > INT64_MAX - data->size) {
+        error_setg(errp, "The requested file size is too large");
+        return -EFBIG;
+    }
+
     /* User provided size should reflect amount of space made
      * available to the guest, so we must take account of that
      * which will be used by the crypto header