From patchwork Mon Nov 11 23:00:39 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: 842479 Delivered-To: patch@linaro.org Received: by 2002:a5d:6307:0:b0:381:e71e:8f7b with SMTP id i7csp3288989wru; Mon, 11 Nov 2024 15:01:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVkd9iW9vIXXkEfbtnyoMubsloXklgTTHxOuyDAcJi99nYr9vYL4biMaAcfidDqYj+tBmUvNw==@linaro.org X-Google-Smtp-Source: AGHT+IEMpKdb2UqZ9qNPt1KhXFoNlTTXdhU71aaEfZH4fC4P0BWxoddtxRvIB5AzUCUqhBKh4ZUl X-Received: by 2002:a05:620a:24cb:b0:7b1:5334:8d31 with SMTP id af79cd13be357-7b331f2efc0mr1869477985a.62.1731366110238; Mon, 11 Nov 2024 15:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731366110; cv=none; d=google.com; s=arc-20240605; b=MA9DmsL+q38aj/lTBPXBe7Kv1q1q0po0TmA0bQOF1bbOxFoQ7PhhnemymIJBSpQ4Kv Qgte6UxHUnf5P8lOQHWF0ZdNtQDhSugj3UEilFBJfPRmazVzt95X4VhathsWVvjNZtGK 97xP5qejnIiMiZk6/fDSnn9zuMmLuu952JFLJcJ0wGPPFl5x5UcAEXS6+IQRbIVuRj61 QCCq3Dls4zMaEdlEJXvuIVtmze6vrju6XqZ+2qAyP9b7h7e8P7G/h0IC5C799KPQMMU5 CCeYubb2b4vwlCQL7wPe8gQd/GBSXtlGIsjWNrGhdT21yPUp3DWMXi44v+bBRn3IJrDD HWew== 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=UxzzjInQDdcHJ2SqBgIRmm2wxmj26K0aTYuxqLWAoGk=; fh=LIYLKah8x7JUCP304tTJaLMhsdh1czlfTXwJCy1DZZI=; b=MrSdIcTSYIbs3+v67imhMMOYOqKganMq5lBCWeDRKaJI5ZZizls/CsfSiouNiwzhTU DtEqBaH3o1/d/yhqmwsfBrXNI7t+6VvhdxrvHbBn7i9YeOzdKZVs7TUGZ42k1HE+c6iZ ZrdorZjcDP8Y2Vv+0DJhCRcbfYV+HPTbI6RYXHYHGl+u0wbwTq1FVQ826NHjfDH8bGss 3TH55q6LojD7wYAjiFvPmGU4XxUjRNJiam1GdxL9vFFEikAPa00ipLq9f4nF4/sSMEXb PVuXKn1BxzcjsrwZfU6ZLy1inTWcQkHdeok7w5XXhmyKpbPS3fEzR6OOPOffPY3mdyFv c5HA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VvR6Q/Pb"; 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-7b32ac3d625si1183638785a.112.2024.11.11.15.01.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Nov 2024 15:01:50 -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="VvR6Q/Pb"; 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 1tAdP0-0000uM-QV; Mon, 11 Nov 2024 18:01:01 -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 1tAdOp-0000tL-KE for qemu-devel@nongnu.org; Mon, 11 Nov 2024 18:00:48 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAdOn-0001ir-Hx for qemu-devel@nongnu.org; Mon, 11 Nov 2024 18:00:47 -0500 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-37d4821e6b4so3538711f8f.3 for ; Mon, 11 Nov 2024 15:00:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731366043; x=1731970843; 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=UxzzjInQDdcHJ2SqBgIRmm2wxmj26K0aTYuxqLWAoGk=; b=VvR6Q/PbWb6xMt0sc+RqgLQ7zVnUkDyDq3iP4c64M+ULmeBMJ9PnC920rKc9v3ciAD cF0z2LFJTEDMvp7z6T2n76MrQNpkkHy4ywMAeUpnPqkcY1GwgilJgUoJQyEuY8EBmAoR 0yJP4R3pvyXMJAEpClSp6E6726zQLghiEi6QBuriQ/63uXxBpqC6czicDc8n5kNcl+dT +x4q7gsDa6TOUCsCcK2owcdRke4ex1qeaduC1CJqcYeyEVhM28lImwHf2pG6doLbbv20 1BpM8oz1vHRNS5NQg6/95YGYKVDkntCJ1mKAhVjKxyw6n9b4ZpzTHTvCbcUSmAnmgcl3 J/jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731366043; x=1731970843; 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=UxzzjInQDdcHJ2SqBgIRmm2wxmj26K0aTYuxqLWAoGk=; b=l1rVHIDO20Dr6S5kHpm/7/+o6QP9uAJYxBoPPDpnKEfpUcwRaKJqgMerZdtOFvQx87 1lfvlpnfyD9oQ6zM16PZJn/WgiYRvWEmmpSgAi2dUk/q6p0GNxFJDJupc3456DHmJHJf qSLfrSFMV2Zh9vtCYy1qgi619osGwn/EwWJuX22IxOencrbYKlPmWifKYbSepP34hXwi vfwRoLouikqE3fhy1ItJfzjYXdhf86MZJqjoC9NRmxtlKE4uSAepvHLaUnwUhCgz3SP+ U/zNOTlK5w2B+vlWJBu7vc2ttorHYNlqjQv8YPTx2MN+04RTEXrbSsrEOixmuXJeoPy3 vjYw== X-Gm-Message-State: AOJu0YzDZXlG186hI/4/Ye2IElvW7sPz8Q+GJLDZBCgYCy9yo3+EDJVz tq8gCegO6NQD6aev8eqnfK+iR83iVyYztLiH6iOKg1PFwdZZrLUKlL4G2ONqdw0= X-Received: by 2002:a5d:64e3:0:b0:37d:4ebe:163e with SMTP id ffacd0b85a97d-381f188c956mr11150775f8f.53.1731366043104; Mon, 11 Nov 2024 15:00:43 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432aa709ec7sm230433125e9.35.2024.11.11.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:00:42 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DFB745FA3C; Mon, 11 Nov 2024 23:00:40 +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 v2 1/2] hw/display: factor out the scanout blob to fb conversion Date: Mon, 11 Nov 2024 23:00:39 +0000 Message-Id: <20241111230040.68470-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241111230040.68470-1-alex.bennee@linaro.org> References: <20241111230040.68470-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.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 Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko --- v2 - fix compile of virtio-gpu-virgl - tweak comment for blob_size --- include/hw/virtio/virtio-gpu.h | 15 +++++++++ hw/display/virtio-gpu-virgl.c | 22 +------------ hw/display/virtio-gpu.c | 60 +++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 553799b8cc..924eb8737e 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: 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. + * + * 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..145a0b3879 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -805,7 +805,6 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g, struct virtio_gpu_framebuffer fb = { 0 }; struct virtio_gpu_virgl_resource *res; struct virtio_gpu_set_scanout_blob ss; - uint64_t fbend; VIRTIO_GPU_FILL_CMD(ss); virtio_gpu_scanout_blob_bswap(&ss); @@ -852,26 +851,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->base.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 11 23:00:40 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: 842478 Delivered-To: patch@linaro.org Received: by 2002:a5d:6307:0:b0:381:e71e:8f7b with SMTP id i7csp3288987wru; Mon, 11 Nov 2024 15:01:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWbErezAJVfAdRMzAVVD9rbWQNCP93GjDxB8MnwQLZS8q9/GGNvEF9By96KIUBO7Z2F7q+70g==@linaro.org X-Google-Smtp-Source: AGHT+IEUwK2LbfQ3f4kudjeA9+P1RhTYPti719UnLj9LYwlX+IMXcKsqqoBV65DkTxdTBUkLr5TH X-Received: by 2002:a05:6214:3b87:b0:6d3:6577:ab09 with SMTP id 6a1803df08f44-6d3d008e17dmr6518296d6.6.1731366110124; Mon, 11 Nov 2024 15:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731366110; cv=none; d=google.com; s=arc-20240605; b=e+oSNTL61859wGsBPJ4FeBZSgjhKvnQxUmE3lKoN1gjBhuzSXMNZfyWpe69TG9WTFP PXNafTovaf91pVvSn95344/c4qfOByoAR/WLlFOHArOceMxKXZ9ViNBgkhBSGpUm0Rn0 qTyd4h/5vfbxnPlg2HQDhg6l8fQ2vgNjbCjk+wyktvAuJi3MX0M147eSSBX3tEOakNpm fsNIZMM7L+qk2DRB8h4rjK1F+mXAdj5Db+VtRAy3LyE7aihiM9JZafkJULYbLY7kWOon ZfldsW9FiomIYx3FoOeCkpJ+f8hR0kj071c8k3qhKe0h/3nmFZeUldKGKx8OaEDqZ8ho xqSQ== 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=25/ELZrXiTJuBOlfElpFvmRMWuKeZY3HCvObpFpP1YA=; fh=LIYLKah8x7JUCP304tTJaLMhsdh1czlfTXwJCy1DZZI=; b=JC3MOSQRrTIgwhJznIsveREehGEyMt+cH8EwRepBHv4p1unyaLoMk6PdZPcEcCJllt mW59UGvBQ0gfA3nSfDDmK/g3O3VzGJCf17Eh+ybgzx+ihUNSlG+YKJ/w5AM2IqX89TPr +8D/gdv0S7jkebv4rtLhLaWxxlUxwpO0DmdgIe/903tVe3G1X3RhsWtkLTTPsFaRedGl mw2GkbwGDpBNDwU80XJ0Au14EigAIGtDf4hH2+dj62RXVAUF36qzQZYontzpQ27Qbkbl eo/CV9lu4YYYpWEQ2/FWWKnJP6Yp4kSOV/RQIEKSjnMO2zXMUOWRpvnUH5J5cJVX413w Ro7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vwx9aVWY; 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 6a1803df08f44-6d39622864esi118963176d6.139.2024.11.11.15.01.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Nov 2024 15:01:50 -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=Vwx9aVWY; 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 1tAdOv-0000tw-Ol; Mon, 11 Nov 2024 18:00:53 -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 1tAdOq-0000tO-JI for qemu-devel@nongnu.org; Mon, 11 Nov 2024 18:00:48 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tAdOo-0001j9-Lk for qemu-devel@nongnu.org; Mon, 11 Nov 2024 18:00:48 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-37d538fe5f2so3655425f8f.2 for ; Mon, 11 Nov 2024 15:00:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731366045; x=1731970845; 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=25/ELZrXiTJuBOlfElpFvmRMWuKeZY3HCvObpFpP1YA=; b=Vwx9aVWY8/Sa2DmpcHG69YkDOP1A5fxE3nWq+GcuTa+1TdgJ8rdVWOgfr37Z3M3bpr kW87G+f04U5c5nf3gEhGBlD0C4Lu4YdsdQAQNaoqE0CkkFjRZI1xzQ0sWDvIo/576i+z Y/9L6kaiwL7rtEKI3exS6Z9SFWi5wU+b+SciMELOnxw0ldETp2gNvBjpQiYHmu9Gd2in ipAi4xK8VYy7aOIMosz+lp30tWSc2CtaGh0fXx5+5Vh3z48ltiK4R2Ss0bZVh/TPLuwf wnVm9dOPpX1ztrsby/w28T9S7sFAGgy0RNgs00Zz+UK0bHk8DB2G+aMyL8RGZxgcnJfD XjqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731366045; x=1731970845; 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=25/ELZrXiTJuBOlfElpFvmRMWuKeZY3HCvObpFpP1YA=; b=OCcv0nC2RP4ct3dH0JRghzsc3+JNflpY2KIsmwqEHivOkxEJ8hCSxnxWZFM7YjM9Kd qj0//G3gc+RyuyZFdgklIMHZSFwAlWvCRQflTG0mgOJo33awmnOiTYFa0eYcznsj8XkC fckIKzXTJ5rSAyCrO6xfhg3+1qhS9xNukd7v1zMCtkj6tLstaGA0MZbaz7681x/IdID3 NakHoR0vzVIRVHWre8tb8kv5MeqZieiiGesZ+okZkTX2w/3rW9aMUsj0EISWXNMN4LU5 RBixLajHg1paJlHozv2IZkbwNQaPdizg8e7KmO997vHwRdIhCH0L6TuVcYBKIRXqpi+Z 6XCA== X-Gm-Message-State: AOJu0YzVD5RoZIQ1Ko+dCEuZEJRJa9Ptw0sTlXdOo4yXTVU9ZOhGb+Sd M5ymd+ig6rZ9S2zTMr/ESt5EurGZHIOeczNf9wZIiZxQ13DRHox1l2TYRyziJfZHiZu7AkqJMWu I X-Received: by 2002:a05:6000:2d11:b0:381:f443:21d8 with SMTP id ffacd0b85a97d-381f443261fmr7728815f8f.0.1731366045115; Mon, 11 Nov 2024 15:00:45 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed97f544sm13994532f8f.40.2024.11.11.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:00:41 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 01D415FA3D; Mon, 11 Nov 2024 23:00:41 +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 v2 2/2] hw/display: check frame buffer can hold blob Date: Mon, 11 Nov 2024 23:00:40 +0000 Message-Id: <20241111230040.68470-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241111230040.68470-1-alex.bennee@linaro.org> References: <20241111230040.68470-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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 first using stride for all lines and casting input to uint64_t to ensure a 64 bit multiply is used. Signed-off-by: Alex Bennée Cc: Dmitry Osipenko Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko --- v2 - just use stride * height - tweak comment --- include/hw/virtio/virtio-gpu.h | 2 +- hw/display/virtio-gpu.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 924eb8737e..8c977beebd 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -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 */ diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index e7ca8fd1cf..7d22d03bbf 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -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,