Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2075562lqa; Tue, 30 Apr 2024 07:35:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqmbyrNMhDmikve5cvSa16/CALs7P1Y7aVMTXiKhqMiflbn0GFLigttqj5Ptp1oqHuAlLR4L7qGeGymYfKKmuPval7OOIs/Z+TK3fpOA== X-Google-Smtp-Source: AGHT+IFRdWnWMbptRrtY6j5NPBj8W5Y/FOka7ex7O4VhwCeCEpplotGFeYR8wjFyjiwKW1+KBk7m X-Received: by 2002:a05:6a21:2783:b0:1af:5765:86d6 with SMTP id rn3-20020a056a21278300b001af576586d6mr701pzb.1.1714487745508; Tue, 30 Apr 2024 07:35:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714487745; cv=pass; d=google.com; s=arc-20160816; b=izyf4pB4+jn+VFKZf5Bws78IP0D+JmoVqrDneNgTDWA6l7gf155kqKQbyD7x+NlVZe M9yBwTqs9W9ctSwaK0F0jK93XABE8CK8FREA6IOr/T9TiAuPNtfg+u7pcKIfa8UQ/+hg K7BvhSLOJUKEJr2YwCvBNuGCZdRDATQ2Y9dHz4GQckHpzkjkpfvv6msPRUuReCy8/Q1R P3bmkIcHDKkgoOBSVgeCEtuVkjlpdryhkPALWePTw21qrmCSBlqdW0mICGWWf9Tpqk0l 8G2Kpi+0tyqm1GPc3IA9uxUY8UOmUs1eJxIUgLeB2lNmj5NpA28RZtnHgmF1AikFnnyT fC5w== 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=TwFDFKwz3EAQcSHIFOZtwNik4AH3gfxFnJlwv47X6xU=; fh=25IklNjpQtm3+ZI4w1ifckV22BkO2b6a/wyTwiBBJrk=; b=DIu6E37kjTe4z8Wo2gPg+xBjEjZ5pfOGspYdmZDj4zZ3ld/hjCHNg/VHZ/Xbux1BCp hDWxu//HtU8cs2M+ynHixsg1ziHK9TyR645gXHMveNhT/RpdWThIqauNGxybIIbmE8VC Y3QwbXNVxVW2EgPZ0geNUOvtJpG+34XVLRIh/FARFXIXuCILCImS3FI3d/uo/64CmkKf igWufnagJl2ypIesEjKXtMhnznTYEfCzHWBzwRlz5pb6w6qNgyq4uJiDhn8jyBOw8mx9 LuQlYF48lO1xHx6hDak3Nx6CkfHi6wNEHzIwL49U3iz+jGRx+es17KrKWhUC8HeDBe/O U28g==; 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-164151-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y8-20020a170902b48800b001eb30bc8362si6910485plr.209.2024.04.30.07.35.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164151-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-164151-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164151-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DBD802899C0 for ; Tue, 30 Apr 2024 14:35:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F37FF152798; Tue, 30 Apr 2024 14:30:49 +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 2A7BB181323; Tue, 30 Apr 2024 14:30:47 +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=1714487449; cv=none; b=lXtgVuF9Rb20A210xEJHgzwYlWmO4h/x2lxuNFiMtv113AooVr5rOcw2bCS0K+WlXzEfQJbr/vE6xJLrgiGJveiQB4YwAAuOBb+A11yisFjJmAiByGfnG9yPZXZT+uXKX8v0XzVuNK+5Zmj1m2cFS+xuMPLr+rsdWjWWUpPc92w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714487449; c=relaxed/simple; bh=yY98P/N6n2yJ+hh0iMOlAtnctYZ4RYhJchDwGQX4eZ0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M7aO8J2/80Az8D6D6IrxkxxxNYipCI+dXqrXqX9aabgIkOF1DytwyNAwpGwpz4YoAULflLvKUcHJ+e4VzERQrifiDLjVl+PJ+hYqLLLfQnyL3ySrp4JIhSb87UhvHYysxBH9saX0HQs3YIhK+CiOLn/femZjfkRE0dz4dGIvWgA= 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 4VTMxJ6WjMz6J77T; Tue, 30 Apr 2024 22:28:04 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id B57E8140CB9; Tue, 30 Apr 2024 22:30:45 +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.35; Tue, 30 Apr 2024 15:30:44 +0100 From: Jonathan Cameron To: Thomas Gleixner , Peter Zijlstra , , , , , , , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo , Gavin Shan CC: Ingo Molnar , Borislav Petkov , Dave Hansen , , , Subject: [PATCH v9 12/19] arm64: acpi: Harden get_cpu_for_acpi_id() against missing CPU entry Date: Tue, 30 Apr 2024 15:24:27 +0100 Message-ID: <20240430142434.10471-13-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> References: <20240430142434.10471-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: lhrpeml100003.china.huawei.com (7.191.160.210) 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 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. Signed-off-by: Jonathan Cameron --- v9: New patch in response to a question from Marc Zyngier. Taking the easy way out - harden against a possible condition rather than establishing it never happens! --- 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