Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp818355lqj; Mon, 3 Jun 2024 01:22:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuc8aF4V5ODXhxNpKo8iCFUVS3ggo9z8EXA/oOAsBNp3Off5RLPYJpOs3WGxZSJF0eIEOz752itK93G/aIhMUs/f1kReU7EtxrwmlgIA== X-Google-Smtp-Source: AGHT+IH1GmM589H4soZJr8I7MvZmkQCf2mJQwMTucpFcZlATMFZUL8GTZYE6JNOFp3kfKhXXJrbU X-Received: by 2002:a05:620a:8cf:b0:792:b70a:221c with SMTP id af79cd13be357-794f5ebdd16mr867219185a.61.1717402963925; Mon, 03 Jun 2024 01:22:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717402963; cv=pass; d=google.com; s=arc-20160816; b=fqtjrEWJfiMdTtfLhM6+2BYyG5aNAHzaPNdKnAf5XhuRsRovPKhqHt2AVUqLoDgvYT 7YQ9h4Rrvu2p+8N0ZApov+2XJUxf4LQjvnisiTm3OLJZAwc3VD2Jv39xu1SmLpCXJLvp zhUDQvQEoAIHWDnGtzIW9gB0hGS54upUhZAb8tY7OovSh8m4I74a3DP7od+GA90ibzxj LphojNu3C6QnIlOezybQPGndPENVrSsJCyY3ghBgVGWWc5PPCRUAzJF9KsxMwA02Jkh0 aLl+crdYTk3yqW2xEiwBL+koIcm6Vexo5Wiavkz2Q/BT+cptXZDdtohfZuvJKrmtGR3g +04w== 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=VH6OglotzW584MhuhA8uYqaei1xmhOdoAvxhOUtEcG0=; fh=87IK6MSmzCt0b0c7BJM3BJ7okOQYSFhMEnQqWeNSPl8=; b=MIMM1HbpJSKJKqM0cmVUMdHETbrOAP883caHkcS+gEw0fqKN9jGjIlrC4wfpUMX6DK XNWdhB3bqDRsa/RStm4SzdHmmXJ72QGyzPknQtt1iD3IYyrR5cY80Pw/GFd8UHjwGLYX QAnNLgBVmI5/ZkktzYucyHALVy7RbsPe/nlJiK3Bko/ipTXfZgj5/lJmg8Unm/KinuPZ 4xWvSavO4FT/ClyDLDjcwCh07UUhNDeqKifA8L2tstWb2RKT1SwZLN4qIbhmHWkuUyBy K99jau63dZZgQVjq+3SH+jH0K2cIT+yZ7bcNZddPk3rCWRAmTMj7K+JwXOXIfod+Y4YI uFFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-198773-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff2467d67si81599081cf.384.2024.06.03.01.22.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:22:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198773-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-198773-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A34991C21604 for ; Mon, 3 Jun 2024 08:22:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7751F6EB56; Mon, 3 Jun 2024 08:22:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A8C15BAC3 for ; Mon, 3 Jun 2024 08:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717402936; cv=none; b=ZQcWmutcUCNYD5MDv17GR+e+ndU1bgIhOWOKpMqiacfT6n1rAAwzggKxD5EjmfJiqGdE/AlIUKxeHiA97TVm3aUVxSx1yZ/njHpZSc1m6jRcLNIET3Pl3uzrpD6vgAiWzlxLFDeMwlgAeXGLeAgtSLTX8kv7VDz6+PdwniORCw0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717402936; c=relaxed/simple; bh=mcByuKxJJ46kPM0AYKATs2LizIwbORX/DJJd+bwMDLQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DYtCXWASA+dxWVXuUNj7Gea8fZwn8VYtYY6GlnE4B+La5K4m1iYy8kYYPlQiH2Mr4/yHJyPpGKSIScyfEg/rVXI0Q13PLIoUXcQSm8yyOdDmfRHSbVGi2ziKo6XjX3MLCItkYt8pIRYRcwHLYxU2exzpjcTtg0jYr8aBwmzymP4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 3541A106F; Mon, 3 Jun 2024 01:22:38 -0700 (PDT) Received: from e125905.cambridge.arm.com (e125905.cambridge.arm.com [10.1.194.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 37BE93F792; Mon, 3 Jun 2024 01:22:12 -0700 (PDT) From: Beata Michalska To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, ionela.voinescu@arm.com, sudeep.holla@arm.com, will@kernel.org, catalin.marinas@arm.com, vincent.guittot@linaro.org, vanshikonda@os.amperecomputing.com Cc: sumitg@nvidia.com, yang@os.amperecomputing.com, lihuisong@huawei.com, viresh.kumar@linaro.org, rafael@kernel.org Subject: [PATCH v6 2/4] arm64: amu: Delay allocating cpumask for AMU FIE support Date: Mon, 3 Jun 2024 09:21:52 +0100 Message-Id: <20240603082154.3830591-3-beata.michalska@arm.com> In-Reply-To: <20240603082154.3830591-1-beata.michalska@arm.com> References: <20240603082154.3830591-1-beata.michalska@arm.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 For the time being, the amu_fie_cpus cpumask is being exclusively used by the AMU-related internals of FIE support and is guaranteed to be valid on every access currently made. Still the mask is not being invalidated on one of the error handling code paths, which leaves a soft spot with theoretical risk of uaf for CPUMASK_OFFSTACK cases. To make things sound, delay allocating said cpumask (for CPUMASK_OFFSTACK) avoiding otherwise nasty sanitising case failing to register the cpufreq policy notifications. Signed-off-by: Beata Michalska --- arch/arm64/kernel/topology.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 1a2c72f3e7f8..e475ec2705e1 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -194,11 +194,16 @@ static void amu_fie_setup(const struct cpumask *cpus) int cpu; /* We are already set since the last insmod of cpufreq driver */ - if (unlikely(cpumask_subset(cpus, amu_fie_cpus))) - return; + if (cpumask_available(amu_fie_cpus) && + unlikely(cpumask_subset(cpus, amu_fie_cpus))) + return; for_each_cpu(cpu, cpus) { - if (!freq_counters_valid(cpu)) + if (!cpumask_available(amu_fie_cpus) && + !zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) + return; + + if (!freq_counters_valid(cpu)) return; } @@ -237,17 +242,8 @@ static struct notifier_block init_amu_fie_notifier = { static int __init init_amu_fie(void) { - int ret; - - if (!zalloc_cpumask_var(&amu_fie_cpus, GFP_KERNEL)) - return -ENOMEM; - - ret = cpufreq_register_notifier(&init_amu_fie_notifier, + return cpufreq_register_notifier(&init_amu_fie_notifier, CPUFREQ_POLICY_NOTIFIER); - if (ret) - free_cpumask_var(amu_fie_cpus); - - return ret; } core_initcall(init_amu_fie); -- 2.25.1