From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1978B17E90E; Mon, 27 May 2024 19:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836696; cv=none; b=LCgwNqywuQuDUC0BrMqGGCLXyaftA05uV5dKII6dUhFI+aF/7AaefMHjYTvGAMAuGlkAUA41Csvh+Es5aDDSMHdZdE+PATpPhsGaOfGicepa2V5hSkskpTprbNeF9pBPZ6ybFJ0P+on/qu1UCGrwgvO2WX0vhze3rD+uUDyw7Y0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716836696; c=relaxed/simple; bh=2SmamE+a+VeKGvRnTgdBYeapV+vg+a6i/AswPRvsF4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dtWwN09/zDsXH8LkcXGG6kcTAUOJRZjC4OWCFX7qKpRmJPA5hqEfefDp8IetXt2u/aA5vfpX2TL77ieWWMvogBirnajqI8CIUrrBn5i6mKYs2OjjdtDpFe5n4is0JY2eMPYej7D/uXPrAIvN5zoyiHgSTrRgU9M3KKt3uVBfZ6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VfLnJzZx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VfLnJzZx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CA53C2BBFC; Mon, 27 May 2024 19:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1716836695; bh=2SmamE+a+VeKGvRnTgdBYeapV+vg+a6i/AswPRvsF4Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VfLnJzZx0MQAsYHsCRbCVgIsR44rofOq57qJcNfqfvLuNsh37XZytjbZxCx+fIp0S ClhDddaONX8RpO9YSahQo9uIM4E/ynAovf4URfqAlMm+Igp7sJ35GTT8f1I6qOLDuT g/47XhUQYo+tz60V9d5l6u6SvNTZyFtpKbCFqz5I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Aleksandr Mishin , Viresh Kumar , Sasha Levin Subject: [PATCH 6.9 153/427] cppc_cpufreq: Fix possible null pointer dereference Date: Mon, 27 May 2024 20:53:20 +0200 Message-ID: <20240527185616.802435915@linuxfoundation.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527185601.713589927@linuxfoundation.org> References: <20240527185601.713589927@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aleksandr Mishin [ Upstream commit cf7de25878a1f4508c69dc9f6819c21ba177dbfe ] cppc_cpufreq_get_rate() and hisi_cppc_cpufreq_get_rate() can be called from different places with various parameters. So cpufreq_cpu_get() can return null as 'policy' in some circumstances. Fix this bug by adding null return check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a28b2bfc099c ("cppc_cpufreq: replace per-cpu data array with a list") Signed-off-by: Aleksandr Mishin Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/cpufreq/cppc_cpufreq.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 64420d9cfd1ed..15f1d41920a33 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -741,10 +741,15 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) { struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - struct cppc_cpudata *cpu_data = policy->driver_data; + struct cppc_cpudata *cpu_data; u64 delivered_perf; int ret; + if (!policy) + return -ENODEV; + + cpu_data = policy->driver_data; + cpufreq_cpu_put(policy); ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0); @@ -822,10 +827,15 @@ static struct cpufreq_driver cppc_cpufreq_driver = { static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu) { struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - struct cppc_cpudata *cpu_data = policy->driver_data; + struct cppc_cpudata *cpu_data; u64 desired_perf; int ret; + if (!policy) + return -ENODEV; + + cpu_data = policy->driver_data; + cpufreq_cpu_put(policy); ret = cppc_get_desired_perf(cpu, &desired_perf); -- 2.43.0