From patchwork Mon Nov 4 16:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 840564 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp2237820wrb; Mon, 4 Nov 2024 08:54:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX162ruEoYnVoV3XnUa01c9SWA1RhoxnW71OwQQ/XY+N3dO0y7j3WBSkPOn5mBR2i5Y4AC2SA==@linaro.org X-Google-Smtp-Source: AGHT+IE6Zg5f+7CdhchJ9qFGT8w42okUXoQYcG0J28wijxa+vQ6H+Mb+DHFVAadtB//d8ldAnjbo X-Received: by 2002:a05:620a:170c:b0:7a9:c333:c559 with SMTP id af79cd13be357-7b2fb9d0b96mr2025009785a.48.1730739276567; Mon, 04 Nov 2024 08:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730739276; cv=none; d=google.com; s=arc-20240605; b=Q4BV9HwrvBmK/Rit6UJl6wdpYp2Zj5jIaYreJnsgCNOF8nsXqI2xmGrfwjukv1zyqK fBcXIy+mDmV7QdoSX0IgYEOjG0yTRMactX9NlUdDsSq44bG4OZqQR7RWqQKFyb+nEVWU NZHs4BsnBzKYhxmnGRDA+wbuYjWtrRxbViNrcWRHMgXSOG3NYMOk61GA6iYLGhtQNDAq 7h825xCytYf0x2WGItGUJBvRplT2t0j5VTRQAb3XxGzh+FO56UAetKzbh69+Raqzq4rC Len6DhGVra9OsmI7Gi6m99krV5tZ4SAnEqxFQ64umDgSLGiAy6u/edp5XbC2/KYcYP1u w2hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7/So9pG2LMx/q/DZBv0lbwhuc0H7Ruhh4U8wSoq6I6Q=; fh=LIYLKah8x7JUCP304tTJaLMhsdh1czlfTXwJCy1DZZI=; b=IPMv5ZaXHFghJjp2hjbnGn/1DltZ/j9UFXa0qqJqgx1I9sgDLuApG1qMOHVov9e8xs n/n7t6Jcf3pDmf/VtEh+ALKdYQ5YYo7omRHrOkycW0AGGB6GCAj8NcWewjgsmVfPHYLh GRX0MlLZ6V/d5GnzOF6X7yI5hwnif2vjdU+4ZEZPbe0xypyosifJwk/Vn92END1Vk7U0 xGyhEFDcvy8viWPRk6NolTuH4VJ9Quv8F1A+y0P8Pu80VJJAHsgJADyq/miYW2ctvYg/ i4XkHM8MY5XtJI3uBI6RJxyi452ByIGpnX+hBbHh7e8QKNKVvmxosSfvL09vvF05j+sn 0dYg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JGD77aLx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3a9ef0dsi1124856185a.513.2024.11.04.08.54.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Nov 2024 08:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JGD77aLx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80Kz-00055g-5p; Mon, 04 Nov 2024 11:53:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80Kw-00053L-Uu for qemu-devel@nongnu.org; Mon, 04 Nov 2024 11:53:55 -0500 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t80Kv-0004gu-0P for qemu-devel@nongnu.org; Mon, 04 Nov 2024 11:53:54 -0500 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a9e71401844so407986166b.3 for ; Mon, 04 Nov 2024 08:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730739231; x=1731344031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7/So9pG2LMx/q/DZBv0lbwhuc0H7Ruhh4U8wSoq6I6Q=; b=JGD77aLxiTATihHVqtwjUAFX1DJsuLKfnQyG+JUFqFU8j4Z4LyAyclngTG9oBhZRTN pPbPJIe7yshSMl6WlIl2qi4jZOOdhIHSy5Vy0WkQUtnUgcDaDYqHVlXq9eSzV1QSzzYG YstVnVirH1RM4bs0fTuiOPiqxcw+RQG6I96blXsLSJ43bzUCwD3Lwk2J4TTWV1kY4LqE uZ6C7O++9xnDHr3DRP/6WtjqgPw3yDRXrT9DsgkQRjIOM43GVH9+MGlmKEfHILWDl2c/ NMxBs3Wv3I6ZZeUprpAezONKaO4xxnU4lHuBSFKh4wt2W0yXm4T0SwLigsRMp1SHa1FX vYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730739231; x=1731344031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7/So9pG2LMx/q/DZBv0lbwhuc0H7Ruhh4U8wSoq6I6Q=; b=XjGUR/5QZ2tV2yrYUx5bFt2SlSMJqtnnyCcZJvvC8mv/JKXI2iySgnlGCVE5CRYOD7 meZ5orD1jT4elsH0ozztwuM1RT1zLLhCbDiY8OQxjtwZZBeTtd3u1VlaXI9/pzNRg7gE oyC7r4oBX3TLlqq2l81m50zZbgwcIW3g4RJOQCWshwhZtsNmAyFReCQNM083Rnu+XgFC Nds/Zwk9Na+XN6kyNdFCxEXl2kGaBWaNpQMW7byTeOX+0luP5mo644hCS714N6byq4Fp N5dGLVuEn8Wn3KirvBg7akQxAeZeOUieCnbEdVd5Zzf+5n1yguJUJIZ7BBIJ1HdQjQxW AokA== X-Gm-Message-State: AOJu0YyTL+YEZlFKHnFnGZGIzcQE2+Zi7vmyuds+JHfTLbvIR/UxzVf5 TwUTvq5FtxhiUAnt5qSN1CJIOh+lmd8CTIcEFLd35aqkhYQ/e5AwpWjK3f4JFKI= X-Received: by 2002:a17:906:dc95:b0:a99:f77f:b489 with SMTP id a640c23a62f3a-a9e50b9430cmr1474837866b.43.1730739231320; Mon, 04 Nov 2024 08:53:51 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17f93f9sm4047066b.163.2024.11.04.08.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 08:53:49 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 621F85F89E; Mon, 4 Nov 2024 16:53:48 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Dmitry Osipenko Subject: [PATCH 1/2] hw/display: factor out the scanout blob to fb conversion Date: Mon, 4 Nov 2024 16:53:47 +0000 Message-Id: <20241104165348.2361299-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241104165348.2361299-1-alex.bennee@linaro.org> References: <20241104165348.2361299-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org There are two identical sequences of a code doing the same thing that raise warnings with Coverity. Before fixing those issues lets factor out the common code into a helper function we can share. Signed-off-by: Alex Bennée Cc: Dmitry Osipenko --- include/hw/virtio/virtio-gpu.h | 15 +++++++++ hw/display/virtio-gpu-virgl.c | 21 +----------- hw/display/virtio-gpu.c | 60 +++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 553799b8cc..90e4abe788 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -333,6 +333,21 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id); +/** + * virtio_gpu_scanout_blob_to_fb() - fill out fb based on scanout data + * fb: the frame-buffer descriptor to fill out + * ss: the scanout blob data + * blob_size: the maximum size the blob can accommodate + * + * This will check we have enough space for the frame taking into + * account that stride for all but the last line. + * + * Returns true on success, otherwise logs guest error and returns false + */ +bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_framebuffer *fb, + struct virtio_gpu_set_scanout_blob *ss, + uint64_t blob_size); + /* virtio-gpu-udmabuf.c */ bool virtio_gpu_have_udmabuf(void); void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index eedae7357f..35599cddab 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -852,26 +852,7 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g, return; } - fb.format = virtio_gpu_get_pixman_format(ss.format); - if (!fb.format) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: pixel format not supported %d\n", - __func__, ss.format); - cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; - return; - } - - fb.bytes_pp = DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); - fb.width = ss.width; - fb.height = ss.height; - fb.stride = ss.strides[0]; - 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; - if (fbend > res->base.blob_size) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: fb end out of range\n", - __func__); + if (!virtio_gpu_scanout_blob_to_fb(&fb, &ss, res->blob_size)) { cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; return; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index c0570ef856..e7ca8fd1cf 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -721,13 +721,48 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } +bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_framebuffer *fb, + struct virtio_gpu_set_scanout_blob *ss, + uint64_t blob_size) +{ + uint64_t fbend; + + fb->format = virtio_gpu_get_pixman_format(ss->format); + if (!fb->format) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: host couldn't handle guest format %d\n", + __func__, ss->format); + return false; + } + + fb->bytes_pp = DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb->format), 8); + fb->width = ss->width; + fb->height = ss->height; + fb->stride = ss->strides[0]; + 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; + + if (fbend > blob_size) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: fb end out of range\n", + __func__); + return false; + } + + return true; +} + + + static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_simple_resource *res; struct virtio_gpu_framebuffer fb = { 0 }; struct virtio_gpu_set_scanout_blob ss; - uint64_t fbend; VIRTIO_GPU_FILL_CMD(ss); virtio_gpu_scanout_blob_bswap(&ss); @@ -753,28 +788,7 @@ static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, return; } - fb.format = virtio_gpu_get_pixman_format(ss.format); - if (!fb.format) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: host couldn't handle guest format %d\n", - __func__, ss.format); - cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; - return; - } - - fb.bytes_pp = DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); - fb.width = ss.width; - fb.height = ss.height; - fb.stride = ss.strides[0]; - 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; - if (fbend > res->blob_size) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: fb end out of range\n", - __func__); + if (!virtio_gpu_scanout_blob_to_fb(&fb, &ss, res->blob_size)) { cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; return; } From patchwork Mon Nov 4 16:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 840563 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp2237714wrb; Mon, 4 Nov 2024 08:54:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVCRRZQVgcxdVRT/Zqc5pErQpPc9D0zErE7YAgV+JtQt+5AvO+hkJ++sYZ82ounUhzBVbcXog==@linaro.org X-Google-Smtp-Source: AGHT+IHP/nrblwXjd3zIaych1D3c2FZ5XBIkU6H1dn8MiXkI8A5MdMUQnsu/a0nNbkCZQolmJY5A X-Received: by 2002:ac8:5dce:0:b0:462:b553:5d3a with SMTP id d75a77b69052e-462b87561demr182953771cf.44.1730739260980; Mon, 04 Nov 2024 08:54:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730739260; cv=none; d=google.com; s=arc-20240605; b=b7hYLw3w3y9qmNO/qF3ugAQPeQmVZDN/WFv5EgaCO3KyCMQBUqlyxQKFKX+MxPqmVb CcJ4LoUbRHuM/znmPq8vdPr9Ekq7niNXlb4I6s0YgjFPO8CHU2dGBquheTzosFlrhNO0 gQVAlDDRm+nKnF2L3cyvOkCDbK8jJo/5+O+CHajjbKfAj7UHkSGsuSu6ft+jWhchveSF oODaBjKy+BpCKfbE7rABzs85Mkg6kVFSh9mivJ5qA1M7RXi45mTQUQix5U8BrCKr4n+o lVvKQ86mkJbwEexxcuUoVtw5uIH2FWleB6KQYr7+cnIH5vOgdTfVIyNnqeP4Wayp/bpG J7ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lB8vB/PMzeP5scWej6wNyd9gn12J752qtp8raWtHWDs=; fh=LIYLKah8x7JUCP304tTJaLMhsdh1czlfTXwJCy1DZZI=; b=HR8AiIAYIJapsAHavxjPx9EcdLXSI1T+VTJHQm+PbYcjG0q+okj6Y/7bizOB4vFL+d jkO5ySvqTCDQaQw5gXB167k7PIcqLIbfzQwBYCNmoddu8Ms32QqPl8WIy9dvPfkeHSR0 1aYq9gCwz9OYGy/yqq2BV9WWXz+Q0JzEtMxlrG2zgjJXFMa5Lag2rMNaxstAOwdpg1L3 NkTwvT0EpmWea6XhmZCqoLUVR18OEZLUpVmeNm41VHAvuAnn40FIDalEK0iJNMSAHD4W wECXAmZDzRh305c+skCU0kBte1pYK0QQ82XTWvejF0stJqjcmz90jqEyIK4O9VNnXP7D LmLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rXY+5ddm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-462ad242314si122459311cf.587.2024.11.04.08.54.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Nov 2024 08:54:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rXY+5ddm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80Kx-00053J-6Y; Mon, 04 Nov 2024 11:53:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80Kv-00052S-HK for qemu-devel@nongnu.org; Mon, 04 Nov 2024 11:53:53 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t80Ku-0004gd-1y for qemu-devel@nongnu.org; Mon, 04 Nov 2024 11:53:53 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9abe139088so687875166b.1 for ; Mon, 04 Nov 2024 08:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730739230; x=1731344030; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lB8vB/PMzeP5scWej6wNyd9gn12J752qtp8raWtHWDs=; b=rXY+5ddm2uT0pfKnU7GomqUon4As2T2RGhMZsTdpdC8Hd0+B0hEkIbsli1Fa4NFSMc UIBedh1gXW85y63Tp3SThPEbwJS/POm9SFk2FYAwChi15mx7UBwbFQthxQt7LqCF/dVZ nYdHmpCE8zUFbdvrJDyj3G7QchDRiQ0c3aRmLph7JCQtMrHfUlIZLJbbRNKhZnk+yIvO Wk86bwT+W8jj7qF23HY2SIM2bQUbs+uTqEbf9M8/UAudR2Do2PCCnur4bHMxNfGhLtT3 evwiFxhThQOu6fq7pUmD/HDd46i2nIJV2fSoMtPbR2mk/O7Q56SlPnsc2mJX+u6cOT2l 1G7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730739230; x=1731344030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lB8vB/PMzeP5scWej6wNyd9gn12J752qtp8raWtHWDs=; b=Kn+/1VsVQFfCo5GPSUiHXnAuawgPIbne2CiDhCwn1Nk/PGJR/necF9Ci+kqoLtjPLY RvVTPBvG1tjNvho3YwBqaT7vABqYl7X1lA0f144INOl1t/XlQFrbtqPy3DBmJU6eewzt p1g7oeLJFNY12ZPIsiLWFwD4MiJlevEA8ovzGZsranKK5Xu6QXujVVBhwCoNSvLR8Ed6 UNYZBgU8dfuoltz1+0q7ixIelCucQGedOmDF0pFxZeUm37K5OGvTX2RmLvx5qSp39yCZ jsuaJgfU9gME9WeUupcoKekTjryZ5//bXGhs/KzVw0VQpicVXpIVDvCc7+4YgJyV4faa yA5Q== X-Gm-Message-State: AOJu0Yy4gAgD9IdOi8eMBN0Wx9v9ug+paMRZK78WLHFqCWhJWR7NmtQw bNuOQ2biEbpl7R6xe2JB9WLo/1dWkxwAwSIzH9IrM99jUXZ8PIXcfMmBe0qTuac= X-Received: by 2002:a17:907:e8b:b0:a9a:714:4399 with SMTP id a640c23a62f3a-a9de6167a45mr3222665566b.51.1730739230016; Mon, 04 Nov 2024 08:53:50 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9eb17cecb5sm4199966b.99.2024.11.04.08.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 08:53:49 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 7864A5F8CF; Mon, 4 Nov 2024 16:53:48 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , =?utf-8?q?Alex_Benn=C3=A9e?= , Dmitry Osipenko Subject: [PATCH 2/2] hw/display: check frame buffer can hold blob Date: Mon, 4 Nov 2024 16:53:48 +0000 Message-Id: <20241104165348.2361299-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241104165348.2361299-1-alex.bennee@linaro.org> References: <20241104165348.2361299-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Coverity reports (CID 1564769, 1564770) that we potentially overflow by doing some 32x32 multiplies for something that ends up in a 64 bit value. Fix this by casting the first input to uint64_t to ensure a 64 bit multiply is used. While we are at it note why we split the calculation into stride and bytes_pp parts. Signed-off-by: Alex Bennée Cc: Dmitry Osipenko --- hw/display/virtio-gpu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index e7ca8fd1cf..572e4d92c6 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -741,9 +741,14 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_framebuffer *fb, fb->stride = ss->strides[0]; fb->offset = ss->offsets[0] + ss->r.x * fb->bytes_pp + ss->r.y * fb->stride; + /* + * We calculate fb->stride for every line but the last which we + * calculate purely by its width. The stride will often be larger + * than width to meet alignment requirements. + */ 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 - 1); + fbend += (uint64_t) fb->bytes_pp * ss->r.width; if (fbend > blob_size) { qemu_log_mask(LOG_GUEST_ERROR,