From nobody Fri Oct 31 09:50:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=renesas.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1748795614533779.229986268964; Sun, 1 Jun 2025 09:33:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1002582.1382148 (Exim 4.92) (envelope-from ) id 1uLlcG-0001VF-KF; Sun, 01 Jun 2025 16:32:56 +0000 Received: by outflank-mailman (output) from mailman id 1002582.1382148; Sun, 01 Jun 2025 16:32:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uLlcG-0001Ux-FO; Sun, 01 Jun 2025 16:32:56 +0000 Received: by outflank-mailman (input) for mailman id 1002582; Sun, 01 Jun 2025 16:32:55 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uLlcF-0001Uq-Tk for xen-devel@lists.xenproject.org; Sun, 01 Jun 2025 16:32:55 +0000 Received: from rein-hpcbdc09 (unknown [1.7.42.26]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0f4ee3b5-3f06-11f0-a300-13f23c93f187; Sun, 01 Jun 2025 18:32:53 +0200 (CEST) Received: by rein-hpcbdc09 (Postfix, from userid 1000) id 5852280C03EA; Sun, 1 Jun 2025 22:02:48 +0530 (IST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0f4ee3b5-3f06-11f0-a300-13f23c93f187 From: Jahan Murudi To: xen-devel@lists.xenproject.org Cc: Jahan Murudi , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v2] arm/vgic-v2: Fix undefined behavior in vgic_fetch_itargetsr() Date: Sun, 1 Jun 2025 22:02:12 +0530 Message-Id: <20250601163212.2988162-1-jahan.murudi.zg@renesas.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1748795615784116600 Content-Type: text/plain; charset="utf-8" The current implementation performs left shift operations that may trigger undefined behavior when the target value is too large. This patch: 1. Changes the shift from signed (1) to unsigned (1U) to ensure well-defined behavior for all valid target values 2. Maintains identical functionality while fixing the UBSAN warning The issue was detected by UBSAN: (XEN) UBSAN: Undefined behaviour in arch/arm/vgic-v2.c:73:56 (XEN) left shift of 128 by 24 places cannot be represented in type 'int' (XEN) Xen WARN at common/ubsan/ubsan.c:174 Signed-off-by: Jahan Murudi Reviewed-by: Michal Orzel --- Changed since v1: * Added space after subject line --- xen/arch/arm/vgic-v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c index a19d610178..642407fd5b 100644 --- a/xen/arch/arm/vgic-v2.c +++ b/xen/arch/arm/vgic-v2.c @@ -70,7 +70,7 @@ static uint32_t vgic_fetch_itargetsr(struct vgic_irq_rank= *rank, offset &=3D ~(NR_TARGETS_PER_ITARGETSR - 1); =20 for ( i =3D 0; i < NR_TARGETS_PER_ITARGETSR; i++, offset++ ) - reg |=3D (1 << read_atomic(&rank->vcpu[offset])) << (i * NR_BITS_P= ER_TARGET); + reg |=3D (1U << read_atomic(&rank->vcpu[offset])) << (i * NR_BITS_= PER_TARGET); =20 return reg; } --=20 2.34.1