From patchwork Mon Apr 8 09:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mishin X-Patchwork-Id: 787100 Received: from mx1.t-argos.ru (mx1.t-argos.ru [109.73.34.58]) (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 9B79A4EB54; Mon, 8 Apr 2024 09:38:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.73.34.58 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712569104; cv=none; b=Hr46CpAyeNu1XXGdxQtljAGYJrn28/0vIotqcAcqNnm3ijiTVxy9FZCwprTd7b9ks8p+uXI9QqByH8bApBu6Cfx5GrehBgIqWnNiR9G4/44UZtEe/4dMkWW3/ugGuloBv8IShH3/+yWVD8Hj1E7+a6kseNNaAD+9i94Ynl0XON8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712569104; c=relaxed/simple; bh=H+zPOpmZR4l5c0oeQGM2NXVXZuHY/mOAxUBkn+hY5ng=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j63iqSHNLM+njQfrY+eRrATGvXmStll89lmkIzxqdBYpjqdzgNKzMLjFWS0hmrmPk0ir6VTse1SnGStuBkYtOYkiF357I1S3YvCelDfx3gsp9bE5W7H5qJ2RM3Tjo2h+Ocn04XOULo9XbasLfTxJGkvaRGth+xPuc3cxDMFyYZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru; spf=pass smtp.mailfrom=t-argos.ru; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b=NSgtco00; arc=none smtp.client-ip=109.73.34.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=t-argos.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=t-argos.ru header.i=@t-argos.ru header.b="NSgtco00" Received: from mx1.t-argos.ru (localhost [127.0.0.1]) by mx1.t-argos.ru (Postfix) with ESMTP id 4C561100003; Mon, 8 Apr 2024 12:38:01 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=t-argos.ru; s=mail; t=1712569081; bh=h50psJaMeumsGCm0bUiI8H/m9L5vMNpSqmXAdhWyywk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NSgtco00Ak4LWJU1ma628ay6u/x4KEAuXLUsFBF4C7jYOAaebwtiotU0rPFfjCcu/ Y02oj+8NGgYKiaC1GUWsnPcAuEfyxe8DAPgWO9rJMuysqOXIBgncYT8V0nPsSxgpRS Ato6EVIqOtZJQ/XURVW2pIt/cnThlmLp6QFXYN630Wd+qyVYhaUD0IM7XSbkN02aSt ANO28i0mkEh3vv5kLMYu1zeLOl7bFJ1qjPVR3SMuxTY2kOkkKpbsMJgl+CupyhOGlM hTkFiQ19dG9MZy62OmX+1LqOTm9rqYZIqAUvT2/zXC1pCznKOrAvQGmjeD/0bV/Zxc HRf3QbaeWORbg== Received: from mx1.t-argos.ru.ru (ta-mail-02.ta.t-argos.ru [172.17.13.212]) by mx1.t-argos.ru (Postfix) with ESMTP; Mon, 8 Apr 2024 12:36:38 +0300 (MSK) Received: from localhost.localdomain (172.17.215.6) by ta-mail-02 (172.17.13.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 8 Apr 2024 12:35:43 +0300 From: Aleksandr Mishin To: Ionela Voinescu CC: Aleksandr Mishin , "Rafael J. Wysocki" , Viresh Kumar , , , Subject: [PATCH v2] cppc_cpufreq: Fix possible null pointer dereference Date: Mon, 8 Apr 2024 12:35:36 +0300 Message-ID: <20240408093536.19485-1-amishin@t-argos.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240405094005.18545-1-amishin@t-argos.ru> References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: ta-mail-02.ta.t-argos.ru (172.17.13.212) To ta-mail-02 (172.17.13.212) X-KSMG-Rule-ID: 1 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 184614 [Apr 08 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: amishin@t-argos.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 15 0.3.15 adb41f89e2951eb37b279104a7abb8e79494a5e7, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1; mx1.t-argos.ru.ru:7.1.1; 127.0.0.199:7.1.2; t-argos.ru:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2024/04/08 07:15:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2024/04/08 06:53:00 #24704467 X-KSMG-AntiVirus-Status: Clean, skipped 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 --- v2: Fix mixed declarations 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 64420d9cfd1e..15f1d41920a3 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);