Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1227319lqe; Mon, 8 Apr 2024 02:39:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUL7GH+Imf8cQA2gGmK+dK2hGllfDpqti8nG6ZCMx6los/qjPaW9Kh5MW3DwT0rAE1lypI9SFsoC9KEpXHPT44wEaRKJTIyAAwtjM2t4w== X-Google-Smtp-Source: AGHT+IGtGk44VH0UFgnEeBO5PSWuXXwQ1IPIShUwfI8Bbw+5xJMchJ2XyoItKdUAzO5D/EprtCwv X-Received: by 2002:a81:9216:0:b0:615:16a1:9190 with SMTP id j22-20020a819216000000b0061516a19190mr7812047ywg.22.1712569186786; Mon, 08 Apr 2024 02:39:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712569186; cv=pass; d=google.com; s=arc-20160816; b=nG5THtEvc3JhKfXfjaYhVlopNco4mhuACIvdtFy0JAR5a/V5GZmoRv6PE4lgiPKRSN i3KS+YDZVu1NmclVGCaD//IKIK/aXUoLoYR7FllQqJmyxAFo8iFP+ohogdE8vmPKuxtm iPRe4zqibX4WxZHR8ybscsNs4JQUxhd5MrH5jGGLGftAJkg49GWkRmA9rpU5jYm8vNR8 qJ8VoXA2jffvXIeG/0mZAooHCnskltXVEAyuEsyqcOuYCELyKpzHF0ER1HusnneFURTD jsRgXSV4udK4eRMrNZKj4+Y4mRWyaWKDZrSSLVmedotL0HUz71oJtfqyXx92b0e70ZZL 8i9g== 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:dkim-signature; bh=h50psJaMeumsGCm0bUiI8H/m9L5vMNpSqmXAdhWyywk=; fh=TjXrpZsB5G0HCQzTxdZoWUrX+U/uDhFrGrA27wFd/KU=; b=mvpuinyvWIzV6VtnRbhZmgpYpMQXrwKVrl0iHWxhklUP6kJaXyhn620uY266NTXhkF 97kzGwZOuAAeUaIrLo0afrpuJAxK9/+jnqrrqnK4XUlKIxKgKT8Sn0ReZndvvORFa1Es pTZfBSyqWQq93IG1togzdbw8rzYy7LWsze5OFC44IU4+dS72wuCLvgB91dfnsJcngdQH 0tWCjV7vniB8sTVhFvadIYCArPvNfH/5zL9iD2KfgAmGzwgWzHgzVVUvEWG4bQ1DHTxv WiQzzgwQgueQE5SFn/d8wSvzB9RLhcNuqCqDQsx66aLWyK1lVIrB3TZYfPtKa8fqh9Ot usTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@t-argos.ru header.s=mail header.b=NSgtco00; arc=pass (i=1 spf=pass spfdomain=t-argos.ru dkim=pass dkdomain=t-argos.ru dmarc=pass fromdomain=t-argos.ru); spf=pass (google.com: domain of linux-kernel+bounces-135166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135166-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=t-argos.ru Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jx17-20020a05622a811100b00434affed9c3si856726qtb.332.2024.04.08.02.39.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 02:39:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@t-argos.ru header.s=mail header.b=NSgtco00; arc=pass (i=1 spf=pass spfdomain=t-argos.ru dkim=pass dkdomain=t-argos.ru dmarc=pass fromdomain=t-argos.ru); spf=pass (google.com: domain of linux-kernel+bounces-135166-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135166-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=t-argos.ru 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 3CAD01C2211A for ; Mon, 8 Apr 2024 09:39:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CA1B51C34; Mon, 8 Apr 2024 09:38:25 +0000 (UTC) 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 (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 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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); -- 2.30.2