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 5B93FC433EF for ; Tue, 17 May 2022 13:50:53 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=lB3v39foeSL5bAfU0KtpYaACfDmE8AcQIMw5vxk4hEs=; b=Ok9NbQ/0EpADTY 2DxnF2njOyqd6Ig8T0Ydjq1Mf+oTIn0sCK8ZBbgBDsumcGlGz/guJOZnjMDEyOxkjRy9GSe1+pPWu xqENPYNY4cy4eEuEW1JwGDgJvixZ1NpRHHttRP0H1IN0ZK+rdWy2gEtC6LzNSL/PiJzht/lQy6p3U KdS6dCxzJ2LwtkGidxdV0lwiJZAWGejRHunQD7jwdU/QF6FSF/srw9HhyUNk6Dfw3V1KZZLQKoOt7 fPuK9zYxUr1A1590p4CiZutJxLzmHUgUjVdu6dJvUP4IG5byXxlhJAzUZLCntkHRIxj2imn457c6I U6YbhrvM5cfnHMFrwlVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqxa3-00E4CY-8e; Tue, 17 May 2022 13:49:44 +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 1nqxTj-00E0p7-P7 for linux-arm-kernel@lists.infradead.org; Tue, 17 May 2022 13:43:13 +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 9AD011042; Tue, 17 May 2022 06:43:10 -0700 (PDT) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.197.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E8F0E3F718; Tue, 17 May 2022 06:43:09 -0700 (PDT) From: Andre Przywara To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, Jean-Philippe Brucker Subject: [boot-wrapper PATCH] fix array boundary check in find_logical_id Date: Tue, 17 May 2022 14:43:05 +0100 Message-Id: <20220517134305.3538588-1-andre.przywara@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220517_064311_955213_6F785CAE X-CRM114-Status: GOOD ( 10.98 ) 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 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 -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel