From nobody Sat Nov 23 22:24:51 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=1730739261; cv=none; d=zohomail.com; s=zohoarc; b=EgT5n2gZEHY3XY6RKq/QP4stFrOOC0d3ETZXc/fB1vtMWV7WTdx32idfHJ4GslOjbCWzgGElxOjeteEvDbxXOU3M2drclLbVzBz1UYPnsGhZDeSzg/+1QEZvVe/0dv1o4gITXzFkHAPxPD4W3AdQtU0uiXAH/Pb6M0fuM61iOXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730739261; 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=lB8vB/PMzeP5scWej6wNyd9gn12J752qtp8raWtHWDs=; b=Y5lfD9awSPo9Emm4wUuGp+Sj4jfI9ioV0tK4S30PMgP8/ULkDfkM0jpHM1Rjycg4hUT/HptZlk/w0UIXgfWhCnX8aCuWxomkV8stlIcWDkHi8WjjoPBBrVJzTnCFpFSOKCciQFZ8/S9FeM6FEPXFnRm1zxR8WWBaLWoPyhsvztU= 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 1730739261280287.9220321114194; Mon, 4 Nov 2024 08:54:21 -0800 (PST) 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) 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) 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-Google-Smtp-Source: AGHT+IE6xFMS48rSdWjpI+kN2STgUhu7Kzmv4KaSjCmAhsUcJ/SfX0elJCRcYy1zjxWT1kaMEV1zrg== 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) 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 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 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::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1730739262441116600 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=C3=A9e 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_f= ramebuffer *fb, fb->stride =3D ss->strides[0]; fb->offset =3D ss->offsets[0] + ss->r.x * fb->bytes_pp + ss->r.y * fb-= >stride; =20 + /* + * 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 =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 - 1); + fbend +=3D (uint64_t) fb->bytes_pp * ss->r.width; =20 if (fbend > blob_size) { qemu_log_mask(LOG_GUEST_ERROR, --=20 2.39.5