Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp641063lqb; Wed, 29 May 2024 06:41:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXn46ehZ8rotpZtM9Itf7KHvLnkrNRS0nuut/GBj3yLMxcJXCusftFgxxrOrAqLsEjs7/YAZpcLzIMs+MhzOOK7vJCqr/7NLz56lhgVAg== X-Google-Smtp-Source: AGHT+IGyvqnPM3vrdJSaXg71b3LlKxdyC6HbsIfzmsUK4XlpHM54hErx4u7ZvtR8a46SmFStaIDc X-Received: by 2002:a50:bb41:0:b0:574:f27a:b3ec with SMTP id 4fb4d7f45d1cf-57851942786mr13414002a12.16.1716990075956; Wed, 29 May 2024 06:41:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716990075; cv=pass; d=google.com; s=arc-20160816; b=fLCWds437PBaGV/OODLRFnh1hD6hcD018wddu6ukPzD+QTXTYSpznWefPHD2iNBKx0 jP2dGJ45Fgu3GSTXa6yuplDfQ3T+zdBfZ8d0Sezsh2Vdla6+aUxb1dYg80tszsZWrbtv yN5d8wEgsOEvNogwK5cgrrbt/SZTBBtmsMVHiC0gQ7YydkiRiCJO4A5swVGawUd5I4Vr RFVVeJAwhhqwDfEKS26un77LQF9l4QtblnkJqmhSLMviTnNqvsBA25l2sdV5taZ8HJlr Q0THhD7tOvwnNtz9fSi102fcykfvyEtf9Ikfd+d+wDjvTaEu07jH21mJjdF2dEDLRMK5 J8WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=lESQ7aqW/cF/NUgne9gk35Kr7gtGuAZ+Ze06Hiy9A5U=; fh=NxmCHexitX7P6x/7ARv3vZBmyAUGQGWkF2RSnxwWsIo=; b=X6lCF0VUImbEAZiJFYOhgzY1hl55nnGsxvsBtlEV+le1hrtMBOQvO2twj2gW82uSHE Nf4noG0e6Dq17VCmGObllKEU9InT1WMULEKyCd0kyT/zG7tWJS1h73Qhz5/6A2MrbvHo fWy9O6VEJAPYsF8WK8mzc1zkQ0j0x0VsEOS9Rg82sgCPVZeqLwCnxGKr50pfKFHCC3ML UGr5zcCxDTm1XjsckyD7qy6bp2i3b+KYPD8GJaqUkw2PLYT+rFsGWweuRJRejQvGhQlh FkqatrZHRBCsZUqZ90hV+MjlJrTNYZipjflnJCaYq8kFq71JYu3+GoJ+1DU8Z/1HGtgq Vckg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-194181-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-579c3d0e45dsi4375781a12.389.2024.05.29.06.41.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:41:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194181-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-194181-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 87CDF1F22BC8 for ; Wed, 29 May 2024 13:41:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F9DC18EA8; Wed, 29 May 2024 13:41:03 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C38F617BAF; Wed, 29 May 2024 13:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990062; cv=none; b=oTOqrdivD/vtxkLsQDpCK90jRl19OfvQqPf5hnaEbJouMP3TQ6+ccly+LNcxcqjJxmckKsHpXQAFSt1s0Vw48YVVjBm+7n17X/Tlb+06mY+6JC99TlihlPS9FNcWyHz7oUNOWMhTCiFaRMMRFkunZfHrz7ukRj7k3yJdbF23rMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990062; c=relaxed/simple; bh=HRhhejitLik28OgzlcVBvJkb8ZtOvIVvfPv96DprgD8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=byAze06mzPoeX46ov2Ktjssjmw5AoFv0W+VXj4Q6XOTDOBTIC+Vyr76GmwKTZ99w80uNBj3SBEUYLyHi+dcqNSxpCPsiJaL3ncMFcS5byLcBi0KtgoVI9OQ1T/k7irGP7l7phxir5XSzdC+DC2kOmj8LpluxqKWmkUpDPRRLkQk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Vq9Qh6LRGz6J6m1; Wed, 29 May 2024 21:36:44 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 0F0C5140DDB; Wed, 29 May 2024 21:40:59 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 29 May 2024 14:40:58 +0100 From: Jonathan Cameron To: Marc Zyngier , Will Deacon , Catalin Marinas , , , , , CC: Mark Rutland , Thomas Gleixner , Peter Zijlstra , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Hanjun Guo , Gavin Shan , Ingo Molnar , Borislav Petkov , Dave Hansen , , , Subject: [PATCH v10 12/19] arm64: acpi: Harden get_cpu_for_acpi_id() against missing CPU entry Date: Wed, 29 May 2024 14:34:39 +0100 Message-ID: <20240529133446.28446-13-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240529133446.28446-1-Jonathan.Cameron@huawei.com> References: <20240529133446.28446-1-Jonathan.Cameron@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) In a review discussion of the changes to support vCPU hotplug where a check was added on the GICC being enabled if was online, it was noted that there is need to map back to the cpu and use that to index into a cpumask. As such, a valid ID is needed. If an MPIDR check fails in acpi_map_gic_cpu_interface() it is possible for the entry in cpu_madt_gicc[cpu] == NULL. This function would then cause a NULL pointer dereference. Whilst a path to trigger this has not been established, harden this caller against the possibility. Reviewed-by: Gavin Shan Signed-off-by: Jonathan Cameron --- V10: Fix description above (duplicated word). Picked up Gavin's tag. --- arch/arm64/include/asm/acpi.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index bc9a6656fc0c..a407f9cd549e 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -124,7 +124,8 @@ static inline int get_cpu_for_acpi_id(u32 uid) int cpu; for (cpu = 0; cpu < nr_cpu_ids; cpu++) - if (uid == get_acpi_id_for_cpu(cpu)) + if (acpi_cpu_get_madt_gicc(cpu) && + uid == get_acpi_id_for_cpu(cpu)) return cpu; return -EINVAL; -- 2.39.2