From patchwork Mon Nov 18 20:41:23 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: 844120 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp827980wrx; Mon, 18 Nov 2024 12:42:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVlmrg4pVRhlqKU4l2bIAfGhOjvIvOcQdb0JPjLVl8hVKkA0ExxqLBfyGUjUf2Sq2Yq7PucMQ==@linaro.org X-Google-Smtp-Source: AGHT+IECvJ3VcLsAZhsZn19Km+D+6dt7jeX5lhQpw5j9qKXbshQJQw4HGk7w3kQJWdx9Z8EQKNa4 X-Received: by 2002:a05:6808:1a23:b0:3e4:d82f:dabb with SMTP id 5614622812f47-3e7bc850578mr10260628b6e.39.1731962554715; Mon, 18 Nov 2024 12:42:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731962554; cv=none; d=google.com; s=arc-20240605; b=NI7SQLlYPB8uPjMix5Yr0j1xKLY1dxeeXeOiBKKSzDmU+tOV6Kf3332H/eNTEUTJX2 dnF9kYOsDMMHak49FypGsl0LSJ/L36eG54ij4GtTSZxh3I1932X+n8nyoxaroVXqySxH QRclud6olgkfTVJbQFv68yNWYO6GU1/BKjZCsvfkNWY6IucAKiT+de0stLpErLkUZ4pa KMguiHKYJGsNppIFNiQTUEpq7UaFj0DEBARR2gldBRhhQJF680BzkapyB1orvFFS/j9b stPtsESfsjQ16MY0wsc4If+5u7VIHPYEtkTOCeYscv7oCWHDQ4GKhkVi/q7e+P7b8vU4 u+Uw== 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=QUG5srLGbOrkRmSwQBWBypd2vcAod2ucdDn5wmB1EIo=; fh=9u82eU2cc3NCEDLYvQ0t2V6OPI4C9vJ6yGyZuqIAtz0=; b=EVNZhYHAA1B19GtLefuGoB6QjVfl3fG4C1tfgldGn0QgSAzxrBZSxxRMnWjMWLbAyN CcEeO0PpoYo5RpF1daVecahWFHraNzcYZOZ2W0jD3ccnuvvFRGLF4SXtVbi0g2zpWFLy C49fMrIvowIhqSA8Z6nm3ct7RQgDe/wH6AeWtvEwdR1QvF89dIAxPwEDWSGMH+q/MInD qkBiaTAgQGiSC+9GPcKChZZBIH249h+Q9ejhGkADQf/Y/xbDLUHyn2H5/6r3liF9vteG ZfPuZrpgpxTS7t01ldjbLf7QZIeTFoSO43o7nPQk6cuWP3lUYmHP7nU6HUIC/o6Reufo Mf1g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="KmJ/eriR"; 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-6d40ddbea03si71861906d6.554.2024.11.18.12.42.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2024 12:42:34 -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="KmJ/eriR"; 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 1tD8Yt-0001V0-FZ; Mon, 18 Nov 2024 15:41:31 -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 1tD8Yr-0001U7-WB for qemu-devel@nongnu.org; Mon, 18 Nov 2024 15:41:30 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tD8Yp-0002Nh-69 for qemu-devel@nongnu.org; Mon, 18 Nov 2024 15:41:29 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a9ed7d8d4e0so392625466b.1 for ; Mon, 18 Nov 2024 12:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1731962485; x=1732567285; 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=QUG5srLGbOrkRmSwQBWBypd2vcAod2ucdDn5wmB1EIo=; b=KmJ/eriRwfiHvuYuMIb2s1HuIlU0gPpQJU4wTzabn42v5TH+COoC7LIZPmYEqdaHbZ kGFkAys5gvn9Fb0LI9a6RmiLo2NDlDlEeTCiXqmHQxGiDFVplRFnn38sc4hii+5AvE/e AjMb7726SAI9qNLY93pUXcKAjV0ICv1/EFcYCHwpImRkAD21imkqNRoIopauriwu1Q5Q 5gQxjDQdGyK7J5Wet+Mss2He7BZ5Qqjo2p8UWvQWJOWI+vH3dPZrM9GRgjIVAutNgZJ8 VjBlJwbnMy9VFHEJ8BOFcO7lhuRNVT7sc1oOId/a3p+IZs/ZednJsLr/u+Oc1f6QLcyZ Xn2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731962485; x=1732567285; 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=QUG5srLGbOrkRmSwQBWBypd2vcAod2ucdDn5wmB1EIo=; b=iBkgqs6n3LNRjEVuGSJuxS4g0CUDz0ds+XgSg9zNQxEUIwWdeJ2GG+SgieA0fCcpR7 MSqHbWF9MW55KIhA9RChGigP3280eAyXhmqN7uJQk+/nn8a/RhAxhqtRihaHnBB88JMX RZNDcAjgW1xN2tCgJJF7yjVQCHxt2YyhHD6dHmmrSNXDT7wUPlAILQjqoUejq35p9mBb HQDXiqiOeZC8l4BqD1PpA3bZqwglNprRi2PPzA7PcQgTlIbVpCJcuSjDoISNP31W7mAI RE8Jy5KHit4hCpiqaQVrwAk8v3YodhSRaoH51bYIVTUvuhMIcGCgdWkYM95wcOCGvI8+ c70w== X-Gm-Message-State: AOJu0YyOUX/RpjUPgTMsvVmD6PqTipx/EoM2b52rkY206Cpg9d/puTWJ PlHQ/clDAqL09Zc7VT54zRRgyWVO/jCsWXAJ21IEkLB+pSDtaP4Z8xAepXhXveE= X-Received: by 2002:a17:906:fe08:b0:a9a:85b5:2aba with SMTP id a640c23a62f3a-aa48341f3bamr1329130266b.21.1731962485227; Mon, 18 Nov 2024 12:41:25 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20e048f12sm573462566b.173.2024.11.18.12.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 12:41:24 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 7B9E25F95C; Mon, 18 Nov 2024 20:41:23 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Dmitry Osipenko , "Michael S. Tsirkin" Subject: [PULL 4/4] hw/display: check frame buffer can hold blob Date: Mon, 18 Nov 2024 20:41:23 +0000 Message-Id: <20241118204123.3083310-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241118204123.3083310-1-alex.bennee@linaro.org> References: <20241118204123.3083310-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.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. Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko Signed-off-by: Alex Bennée Message-Id: <20241111230040.68470-3-alex.bennee@linaro.org> 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,