From nobody Sat May 18 12:12:29 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1684859547; cv=none; d=zohomail.com; s=zohoarc; b=FnqKLKymdBWUFwYvhCSFKOfAm8r3li8nsvBetIph+ghcoxPg4o1fqfzl77BBd3bbJoZiG4NbJxjZJNu2QHAUyPo3dkReA29k76HP5qLZaBJmos/gGjL+8+i+FiuqWZfE5975EDk208f+9XdDkeQdL2nl2W8Seb4eNhM6rCQQvEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684859547; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=EET2Da+kTu3BqzjQiQx4jbxb1dx6dRVpwsShZHnt/l0=; b=XgPkvrFQDW6GkDFJFDZmQlqnosAsnKpV0OiZY1Q+lImkLVFwmM15CMNLj5bUX3Q6JA+NrwzJPg/alw29dsKdZOcby4Qp7L9ZJfMmtxH0/NADHzXLuHhtOLxPuGYFEUJLIja2zlvwFBe8JHLivYrg7GhK1qAroNM+5WqP0iMPOeY= 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 1684859547636477.2910368226384; Tue, 23 May 2023 09:32:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1Uvk-0002q4-EF; Tue, 23 May 2023 12:32:12 -0400 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 1q1Uvh-0002pe-Fx for qemu-devel@nongnu.org; Tue, 23 May 2023 12:32:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1Uvf-0000QF-Om for qemu-devel@nongnu.org; Tue, 23 May 2023 12:32:09 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-E0Z7ADgPPeWJlP_Io0iPyA-1; Tue, 23 May 2023 12:31:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C14A92999B2C; Tue, 23 May 2023 16:31:45 +0000 (UTC) Received: from f38-work.redhat.com (unknown [10.39.193.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 251DF200B673; Tue, 23 May 2023 16:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684859526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EET2Da+kTu3BqzjQiQx4jbxb1dx6dRVpwsShZHnt/l0=; b=ZzRFOqc8RujfKKcGEAGYlqOKjvn2TxolfKSZcXRJ/pqPP/O6ESus62yNuhG/poMLzPtZcB dX7sIQnLkYzpFf2Vi6uUfd2ClaM3jajW7/h3LzRujFj6S31p6CZjn3P/6nCHHKOyb/vINK iqGf1CWJtgu9tOQadcnREjJ1EOZ8efg= X-MC-Unique: E0Z7ADgPPeWJlP_Io0iPyA-1 From: Mauro Matteo Cascella To: qemu-devel@nongnu.org Cc: mcascell@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, berrange@redhat.com, philmd@linaro.org, richard.henderson@linaro.org, jacek.halon@gmail.com, yairh33@gmail.com, e.elrefaei99@gmail.com Subject: [PATCH v2] ui/cursor: make width/height unsigned 16-bit integer Date: Tue, 23 May 2023 18:30:23 +0200 Message-Id: <20230523163023.608121-1-mcascell@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.133.124; envelope-from=mcascell@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @redhat.com) X-ZM-MESSAGEID: 1684859549630100003 Although not actually exploitable at the moment, a negative width/height could make datasize wrap around and potentially lead to buffer overflow. Since there is no reason a negative width/height is ever appropriate, modify QEMUCursor struct and cursor_alloc prototype to accept uint16_t. This protects us against accidentally introducing future bugs. Signed-off-by: Mauro Matteo Cascella Reported-by: Jacek Halon Reported-by: Yair Mizrahi Reported-by: Elsayed El-Refa'ei Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- v2: - update commit summary/description - add Reported-by/Reviewed-by - use uint16_t instead of uint32_t - add comment in cursor_alloc include/ui/console.h | 4 ++-- ui/cursor.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 2a8fab091f..ae5ec466c1 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -144,13 +144,13 @@ typedef struct QemuUIInfo { =20 /* cursor data format is 32bit RGBA */ typedef struct QEMUCursor { - int width, height; + uint16_t width, height; int hot_x, hot_y; int refcount; uint32_t data[]; } QEMUCursor; =20 -QEMUCursor *cursor_alloc(int width, int height); +QEMUCursor *cursor_alloc(uint16_t width, uint16_t height); QEMUCursor *cursor_ref(QEMUCursor *c); void cursor_unref(QEMUCursor *c); QEMUCursor *cursor_builtin_hidden(void); diff --git a/ui/cursor.c b/ui/cursor.c index 6fe67990e2..29717b3ecb 100644 --- a/ui/cursor.c +++ b/ui/cursor.c @@ -90,11 +90,12 @@ QEMUCursor *cursor_builtin_left_ptr(void) return cursor_parse_xpm(cursor_left_ptr_xpm); } =20 -QEMUCursor *cursor_alloc(int width, int height) +QEMUCursor *cursor_alloc(uint16_t width, uint16_t height) { QEMUCursor *c; size_t datasize =3D width * height * sizeof(uint32_t); =20 + /* Modern physical hardware typically uses 512x512 sprites */ if (width > 512 || height > 512) { return NULL; } --=20 2.40.1