From patchwork Mon Nov 18 12:46:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 844086 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp595332wrx; Mon, 18 Nov 2024 04:48:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUT4ehb3IT8YUdOwq7HJRxOFXGzKcuw5rVTTR1gCKRFrl0ha5ApU6PaFQSeeoUNVJIjF+gQug==@linaro.org X-Google-Smtp-Source: AGHT+IHcE/nzfp4faqgj6I4Mu0xuIh2ZEGmTa7r0l5b5e81jeCBq61+itzdF8tHBLISjT6Irugsf X-Received: by 2002:a05:622a:188c:b0:461:52b3:7ce5 with SMTP id d75a77b69052e-46363e970bemr179773481cf.37.1731934133399; Mon, 18 Nov 2024 04:48:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731934133; cv=none; d=google.com; s=arc-20240605; b=Httee/3xvagsvtOX32cWUwwdlC6565Gs0XB/4MazSU1FvDjSrDZvZq+aW0RH2sUBln oBpn6N0Kwc7u676T0btpj3cpi4kHzsrjeeLiVYRPp+AzTcw3TpN4+xdpQ4rAK8kMTDZV F9zqKsYzi2AZzb7oB5bnodpDI5CLfZr2gDOcfEgtNo19fsM2H13HW8RmMklfB/VE9Jjs UmeQlZfw7gVrLkM03nzlbyxs1pz2iu216QnFdyardrmh+wL4x7of5sQAiX5RTUDndYZ2 g0ahrZQycrryOd+7iuYxS7GyQE4PmPnAzavNa7CC1RSI4rgK8IjvHQAHAYaBk7298eG4 Nm4Q== 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=ub7X6sJHrjB0SzaYTR/xmHntoa5aUSaWnEy/yeF5Dbw=; fh=Rd6L/sBFZKAs+7WmvdDGFhm2efHDi0nixzl4z8FARRs=; b=HjdHiFE4ZPQcWOaKVjbANNoSm7ZeuFqJz7bDhRjpSRmvPiWYz5+eQ4Q/yWW22/fqdf o9WXFeIyVnTRm9IRoSYZiFTfNwNv4hMsWulKC/edh+9nt2uSo1eSk+PVFvCJy6EJbkX2 pU/IhrDPGOYCckaXiD8u8RNtysgkJCBWzOtCSNAazbI8/vGaeWwaJLp/3YrpbYo/t1TP gFm88qtbvyX3aqEsG5M7Qh1uq6O9mz/vigU/IvYDxHWqaG74PMx2d+Cc1iFZH3s24EtG 5suOcvEm2T5qeOJvchRF+eSJkZMGsfiO8iLEoX2Z9ZlEAAMiwCgOYilSoB27OzMbW59H n7dA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qH3ksDh8; 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-4635a987252si101571801cf.102.2024.11.18.04.48.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 04:48:53 -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=qH3ksDh8; 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 1tD1A0-00037i-24; Mon, 18 Nov 2024 07:47:20 -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 1tD19x-00036l-Mg for qemu-devel@nongnu.org; Mon, 18 Nov 2024 07:47:17 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tD19w-0005Oi-3c for qemu-devel@nongnu.org; Mon, 18 Nov 2024 07:47:17 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3823cf963f1so992643f8f.1 for ; Mon, 18 Nov 2024 04:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731934034; x=1732538834; 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=ub7X6sJHrjB0SzaYTR/xmHntoa5aUSaWnEy/yeF5Dbw=; b=qH3ksDh8AOeUFeTRRfg6RyCDwV92sxwPTl5zouS+2a8tGfTq94nVl2O064Dky83hCH HJNyf3LrghGxhO8jRU+MhNLtrWFN2swPYCxrU6TWUrRxVGy9TrivOIvwcVWDr0jVONYq bT5abUKR8M5TfAdLFa9WMmsieCYPS85QhYgJjdLvQA3jh8cVDlriRm8SPYlREx1lepO2 IFRb79IA4HR0Rww7Ah70BYWWbQ3u+hMHyfHla9ju3eyfzh/qQIT8nM/QTSrJqdr8z8eo +StbxY1awK9GJZrq2YarU1wAhYE9aHp+4HoDbX3XXhqhwlv5hUSjn1Ab190TkUkgY413 ODdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731934034; x=1732538834; 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=ub7X6sJHrjB0SzaYTR/xmHntoa5aUSaWnEy/yeF5Dbw=; b=OY0CxyvM6Z/mSHZhGkDd5fiq0kptX6j9FPKXgjzOeoHPU1GfU8+DzmfjN8BxKBwzbD liu9Et/Akcq9fsyTytGjdBWNXcd5PcgkYjky1OQ18f50PIdcj1/cAg5A/6B4oVl9Nm9p ogMhngqlJBwGJezKI2Fm2W3/3JcqOQc1G1bJZ+i0nBF69zA6xKZKbZVToBACiYab+ytt TsDUM5oSmX0YV/L3baEq7M6ELcVFYmvIwfDEI1LUWEc1pTQcSUZC0uA0jdNbnIMnI/Ha 08EG7oTr62jOVpAb8tK6Nc/2AthK3CGz+Nllfos1vNjY2AQSLMQRvwJzvUcMqm1Zoy9l Ks0A== X-Gm-Message-State: AOJu0Yx7nOTPy147JhIEmkPr5RbQ0Mf4z9F3++HUchf3m/6L7oC3SXD9 tWB+3D31fZxc4CKgx9RwTo+PKwUgFNjAkdBMdxnaFB0nRCnFiJ27Lz+mSnRYeiR2w20Amw+2XQY d X-Received: by 2002:a5d:5c0e:0:b0:382:4a4e:25bb with SMTP id ffacd0b85a97d-3824a4e2883mr1474474f8f.46.1731934034135; Mon, 18 Nov 2024 04:47:14 -0800 (PST) Received: from localhost.localdomain ([176.187.198.1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38244355924sm4098904f8f.46.2024.11.18.04.47.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 04:47:13 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Dmitry Osipenko , =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Subject: [PULL 05/15] hw/display: check frame buffer can hold blob Date: Mon, 18 Nov 2024 13:46:32 +0100 Message-ID: <20241118124643.6958-6-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241118124643.6958-1-philmd@linaro.org> References: <20241118124643.6958-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philmd@linaro.org; helo=mail-wr1-x42f.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 From: Alex Bennée 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 Message-ID: <20241111230040.68470-3-alex.bennee@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- 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,