Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C67ADC433F5 for ; Tue, 4 Oct 2022 14:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YbmzxdMSoUqRHyQcbA9BAVfiSFw4fyzvUbyZOJHTszU=; b=uEv9HsO2PZ0qUV eKnP1+Y8M8Fs9p3bKylTQBgT/3LqR3jepbvkOZMbCp4U082EcYOTM5X7xtvQ946hnsxRDhgg4bnsk 0SU4wEdb1W6izK3Lbut8AmYfUpUy4mP1Uc+SJm02HcdwRiNT8fip1TVrn9Q/3b5Nw+U1no8suSQP9 +pVm+ia4OybRsnIf/DHae7ydlOArJl8nRQgDdUUTdrDoniYnmGpGAAq22iEeXUH70AOFFMa1byZ9c /t88kI+OcOKwF3jmFaoPmqiP7WXoUc80CQwELunVip0ZNZLQR/Y4kWW+49gxTUDm23Iv18zT9Qkz4 SmeNK2puriFNGBgk8nNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofjEz-009xfh-CU; Tue, 04 Oct 2022 14:49:49 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofjEf-009xek-Cf for linux-arm-kernel@lists.infradead.org; Tue, 04 Oct 2022 14:49:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6A52C1063; Tue, 4 Oct 2022 07:49:30 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A4763F792; Tue, 4 Oct 2022 07:49:22 -0700 (PDT) Date: Tue, 4 Oct 2022 15:49:20 +0100 From: Andre Przywara To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, Jean-Philippe Brucker Subject: Re: [boot-wrapper PATCH] fix array boundary check in find_logical_id Message-ID: <20221004154920.006c04e7@donnerap.cambridge.arm.com> In-Reply-To: <20220517134305.3538588-1-andre.przywara@arm.com> References: <20220517134305.3538588-1-andre.przywara@arm.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221004_074929_522237_5872B7F4 X-CRM114-Status: GOOD ( 16.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 17 May 2022 14:43:05 +0100 Andre Przywara wrote: Hi, any chance someone can please have a look at this? Cheers, Andre > When we are trying to find the array index for a given MPIDR, we check > that we don't overrun the array boundary, by comparing against NR_CPUS. > However the resulting conditional branch should also fire when we reach > the exact number of elements, since it's all 0 based. > > Change the comparison to be '>=' instead of just '>', to only allow > array indicies 0 .. (NR_CPUS - 1). > > Signed-off-by: Andre Przywara > --- > arch/aarch32/utils.S | 2 +- > arch/aarch64/utils.S | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/aarch32/utils.S b/arch/aarch32/utils.S > index 58279aa..d28ab19 100644 > --- a/arch/aarch32/utils.S > +++ b/arch/aarch32/utils.S > @@ -24,7 +24,7 @@ ASM_FUNC(find_logical_id) > 1: mov r3, #NR_CPUS > > cmp r1, r3 > - bgt 3f > + bge 3f > ldr r3, [r2, r1, lsl #2] > cmp r3, r0 > beq 2f > diff --git a/arch/aarch64/utils.S b/arch/aarch64/utils.S > index 32393cc..89aa124 100644 > --- a/arch/aarch64/utils.S > +++ b/arch/aarch64/utils.S > @@ -22,7 +22,7 @@ ASM_FUNC(find_logical_id) > mov x1, xzr > 1: mov x3, #NR_CPUS // check we haven't walked off the end of the array > cmp x1, x3 > - b.gt 3f > + b.ge 3f > ldr x3, [x2, x1, lsl #3] > cmp x3, x0 > b.eq 2f _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel