hw/display: check frame buffer can hold blob
authorAlex Bennée <alex.bennee@linaro.org>
Mon, 11 Nov 2024 23:00:40 +0000 (23:00 +0000)
committerAlex Bennée <alex.bennee@linaro.org>
Mon, 18 Nov 2024 15:54:48 +0000 (15:54 +0000)
Coverity reports (CID 15647691564770) that we potentially overflow
by doing some 32x32 multiplies for something that ends up in a 64 bit
value. Fix this by first using stride for all lines and casting input
to uint64_t to ensure a 64 bit multiply is used.

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20241111230040.68470-3-alex.bennee@linaro.org>

hw/display/virtio-gpu.c
include/hw/virtio/virtio-gpu.h

index e7ca8fd1cfddf898e8e30a8275be3cc540361f99..7d22d03bbfa8e3541fa47ac57ec98a13e8656c12 100644 (file)
@@ -742,8 +742,7 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_framebuffer *fb,
     fb->offset = ss->offsets[0] + ss->r.x * fb->bytes_pp + ss->r.y * fb->stride;
 
     fbend = fb->offset;
-    fbend += fb->stride * (ss->r.height - 1);
-    fbend += fb->bytes_pp * ss->r.width;
+    fbend += (uint64_t) fb->stride * ss->r.height;
 
     if (fbend > blob_size) {
         qemu_log_mask(LOG_GUEST_ERROR,
index 924eb8737e776e7292466a3ae32259ac8af78ed6..8c977beebdc27a1257193d25f2967518fbf2de1a 100644 (file)
@@ -340,7 +340,7 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g,
  * blob_size: size of scanout blob data
  *
  * This will check we have enough space for the frame taking into
- * account that stride for all but the last line.
+ * account that stride.
  *
  * Returns true on success, otherwise logs guest error and returns false
  */