From nobody Sat Nov 23 22:06:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1731366110; cv=none; d=zohomail.com; s=zohoarc; b=jhRbga3xO2oHRhbw1sQvD2PIBquj1htTI/EC3gkRVgO6lZ3bjM19gG0O7UzKKPV57ADR3MhfOOLwXVcRsmk015hPq6lx+G4Mj3YsUh189uDE0Xd3C9T0wPL083ulNI3qdF4LYnoe+9NSTFQ/sKYI1WYOHdTGYm4tGQpfBbodwZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731366110; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=25/ELZrXiTJuBOlfElpFvmRMWuKeZY3HCvObpFpP1YA=; b=L4uNpDsMoGa3sHqC/4QlhYqisiuWnVVDmOYIewHIwx2xwTXCDOgJs3S2Z3hUvyhrFKlFD7C9Bixz+qN4Cx5lvc/nuTMbM3Sct2rrbu6jdM+erWkX9D1qRcSCDVRRBr5g/Bp0iuJ4VagXM+976ljTGjLD5bUL6gQ4ZmVg9h2ZayU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731366110567623.8312906613958; Mon, 11 Nov 2024 15:01:50 -0800 (PST) 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) 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) 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-Google-Smtp-Source: AGHT+IHVXB5PacgudOIDwIcxkvjQoVQZeiIMgCAk6DE4FMbhUBgHOkMnVqkZZQNGdgM/dZwN0aLh+g== 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) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , =?UTF-8?q?Alex=20Benn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1731366112094116600 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=C3=A9e 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_fr= amebuffer *fb, fb->offset =3D ss->offsets[0] + ss->r.x * fb->bytes_pp + ss->r.y * fb-= >stride; =20 fbend =3D fb->offset; - fbend +=3D fb->stride * (ss->r.height - 1); - fbend +=3D fb->bytes_pp * ss->r.width; + fbend +=3D (uint64_t) fb->stride * ss->r.height; =20 if (fbend > blob_size) { qemu_log_mask(LOG_GUEST_ERROR, --=20 2.39.5