From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387882; b=xisbhTMfdsLuUH0W1M3fxdzL9wvO0lL8Kc2j0Y0Vxhi6eXR8I6WDwVGR5n4cY1J3yDMX 9D2zzkktDP9dTvq2n7CPK26xxfZnUuNdKjxffZb7h3OfETKPLhfSAsWK5F+rk5Nc+Khaj s1JRrXNnxc+L5ZmGnqpvSkh3vBUGipIPg+nww92oe5Hv1R9HI0Inyb1jAK0/B+Nco993+ zkA/nlskz1EwJVpIevfMFG6AkgjFfjkmPwhPqKaavSMtdb9QfnSr7LoKDYDQac8QOUdB9 rjZcLnf2MoQQsMBBGovBVSAWc0bHVyrn9YqnTnYFCFy1VvnrHNQDDsHIDT8tGithPvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387882; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=BoRjjDmOgo5fkQVyI5RmfVkGSlbDfDR4zPeCF+En7eY=; b=pj11yHTsrbTEiY+iytC9l4KmXd9Gaf80C7SpGlaAkTgzgvqBiu9rnY0H4zkeSh8R5yeX J9AyXeZUvMXp3h2ZyLk61o2vUqTW4jIYDhBFE2stfvryap0cJs+/UPHOipvXEPtcB1/in VUUyNHFY+5wNbVU7Bb0befh6Ax2dgidlv59NmIAIOd+5Ws0dqKqOU/DdJV3xGVn5oI0J2 UAAzDdhgCpNIulHWWMUy8gKPWQIL7qUfmVxdLyIe2bv6qH1ccXLKBvLzu+y/GyuYFzT1z lJFQ26U5yCrUGYAs4obFFPF2ZWiMvsPRvWZtvyju5giRlo4rm8/hZDMGmJRkUTgsF6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lWDhICcX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E47F606A322; Fri, 4 Dec 2026 12:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lWDhICcX Received: by smtp.kernel.org (Postfix) with ESMTPSA id D14521F000C2; Fri, 4 Dec 2026 12:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387882; bh=BoRjjDmOgo5fkQVyI5RmfVkGSlbDfDR4zPeCF+En7eY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lWDhICcXMXeXmjGiKnmTsC4u+czdwXCXBYEbA8jcAuUQ2G1V+IEBpgEup6ul+U/O8 VGbCbqIHs5uETSx7mP2JeJFq73qxUt5fy1fCuh104rn15//qh+Mbz11rWtSpRNHexS DjHS8CjNOgUuyAmkHqHWrPi6WPn43PzVv80R0KeA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhu Ling , Thomas Gleixner , "Zenghui Yu (Huawei)" , Radu Rendec , Marc Zyngier , Sasha Levin Subject: [PATCH 6.1 0396/1059] irqchip/gic: Fix UBSAN shift-out-of-bounds in GIC helpers Date: Fri, 4 Dec 2026 18:58:47 +0900 Message-ID: <20261204100654.573843387@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhu Ling [ Upstream commit 13ce14ca41a35f5ee90b77ffa57da91ce6048a2d ] When running with UBSAN enabled, enabling a GPIO controller that uses a GIC interrupt as its parent triggers several shift-out-of-bounds warnings: shift-out-of-bounds in drivers/irqchip/irq-gic-common.c:50:21 left shift of 2 by 30 places cannot be represented in type 'int' Similar reports are emitted from gic_poke_irq() and gic_peek_irq() in drivers/irqchip/irq-gic-v3.c. The corresponding GICv2 helpers use the same signed-shift pattern. These masks are generated by shifting signed integer constants, which invokes undefined behavior when bit 31 is selected. Use BIT() to generate the masks with an unsigned type and make their intent explicit. Fixes: f27ecacc54cc ("[ARM] Add support for ARM GIC") Fixes: 5c0c1f08abf0 ("ARM: 6150/1: gic: implement set_type") Fixes: 021f653791ad ("irqchip: gic-v3: Initial support for GICv3") Signed-off-by: Zhu Ling Signed-off-by: Thomas Gleixner Reviewed-by: Zenghui Yu (Huawei) Reviewed-by: Radu Rendec Acked-by: Marc Zyngier Link: https://lore.kernel.org/r/2fJDwUUYdEf2_eaRa041L9xkT8RkSWFeo7euOnqMbbPhUatLlEaAvGfB6sOspDmXaxO87Eh7bQLV9UolyjbMtZBT1wB2UGypjPOo0Z-RC0Q=@proton.me Link: https://patch.msgid.link/20260929031050.16988-1-zhuling2709@phytium.com.cn [ sashal: Replaced signed-shift masks with BIT() in irq-gic.c while keeping the existing gic_irq(d) accessor and layout instead of upstream's irqd_to_hwirq(d) context. ] Signed-off-by: Sasha Levin --- drivers/irqchip/irq-gic-common.c | 2 +- drivers/irqchip/irq-gic-v3.c | 4 ++-- drivers/irqchip/irq-gic.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-gic-common.c b/drivers/irqchip/irq-gic-common.c index afd6a1841715a..2efbb880bbc46 100644 --- a/drivers/irqchip/irq-gic-common.c +++ b/drivers/irqchip/irq-gic-common.c @@ -47,7 +47,7 @@ void gic_enable_quirks(u32 iidr, const struct gic_quirk *quirks, int gic_configure_irq(unsigned int irq, unsigned int type, void __iomem *base, void (*sync_access)(void)) { - u32 confmask = 0x2 << ((irq % 16) * 2); + u32 confmask = BIT(((irq % 16) * 2) + 1); u32 confoff = (irq / 16) * 4; u32 val, oldval; int ret = 0; diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index 6ef0be2c0ab87..1a327db3d041c 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -382,7 +382,7 @@ static int gic_peek_irq(struct irq_data *d, u32 offset) u32 index, mask; offset = convert_offset_index(d, offset, &index); - mask = 1 << (index % 32); + mask = BIT(index % 32); if (gic_irq_in_rdist(d)) base = gic_data_rdist_sgi_base(); @@ -398,7 +398,7 @@ static void gic_poke_irq(struct irq_data *d, u32 offset) u32 index, mask; offset = convert_offset_index(d, offset, &index); - mask = 1 << (index % 32); + mask = BIT(index % 32); if (gic_irq_in_rdist(d)) base = gic_data_rdist_sgi_base(); diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index 867b282fa95d4..6bed385d0810b 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -182,13 +182,13 @@ static inline bool cascading_gic_irq(struct irq_data *d) */ static void gic_poke_irq(struct irq_data *d, u32 offset) { - u32 mask = 1 << (gic_irq(d) % 32); + u32 mask = BIT(gic_irq(d) % 32); writel_relaxed(mask, gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4); } static int gic_peek_irq(struct irq_data *d, u32 offset) { - u32 mask = 1 << (gic_irq(d) % 32); + u32 mask = BIT(gic_irq(d) % 32); return !!(readl_relaxed(gic_dist_base(d) + offset + (gic_irq(d) / 32) * 4) & mask); } -- 2.53.0