lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <DM4PR12MB52783DEBD0E16631D5796BA09CD99@DM4PR12MB5278.namprd12.prod.outlook.com>
Date:   Thu, 9 Feb 2023 02:02:36 +0000
From:   "Yuan, Perry" <Perry.Yuan@....com>
To:     Arnd Bergmann <arnd@...nel.org>
CC:     "Huang, Ray" <Ray.Huang@....com>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Viresh Kumar <viresh.kumar@...aro.org>,
        "Karny, Wyes" <Wyes.Karny@....com>,
        "Limonciello, Mario" <Mario.Limonciello@....com>,
        "Meng, Li (Jassmine)" <Li.Meng@....com>,
        "linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "arnd@...db.de" <arnd@...db.de>
Subject: RE: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use

[AMD Official Use Only - General]

Hi Arnd,

> -----Original Message-----
> From: Arnd Bergmann <arnd@...nel.org>
> Sent: Wednesday, February 8, 2023 12:13 AM
> To: Huang, Ray <Ray.Huang@....com>; Rafael J. Wysocki
> <rafael@...nel.org>; Viresh Kumar <viresh.kumar@...aro.org>; Karny, Wyes
> <Wyes.Karny@....com>; Yuan, Perry <Perry.Yuan@....com>; Limonciello,
> Mario <Mario.Limonciello@....com>
> Cc: Arnd Bergmann <arnd@...db.de>; Yuan, Perry <Perry.Yuan@....com>;
> Limonciello, Mario <Mario.Limonciello@....com>; Jinzhou Su
> <Jinzhou.Su@....com>; Meng, Li (Jassmine) <Li.Meng@....com>; linux-
> pm@...r.kernel.org; linux-kernel@...r.kernel.org
> Subject: [PATCH] cpufreq: amd-pstate: avoid uninitialized variable use
> 
> From: Arnd Bergmann <arnd@...db.de>
> 
> The new epp support causes warnings about three separate but related bugs:
> 
> 1) failing before allocation should just return an error:
> 
> drivers/cpufreq/amd-pstate.c:951:6: error: variable 'ret' is used uninitialized
> whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>         if (!dev)
>             ^~~~
> drivers/cpufreq/amd-pstate.c:1018:9: note: uninitialized use occurs here
>         return ret;
>                ^~~
> 
> 2) wrong variable to store return code:
> 
> drivers/cpufreq/amd-pstate.c:963:6: error: variable 'ret' is used uninitialized
> whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>         if (rc)
>             ^~
> drivers/cpufreq/amd-pstate.c:1019:9: note: uninitialized use occurs here
>         return ret;
>                ^~~
> drivers/cpufreq/amd-pstate.c:963:2: note: remove the 'if' if its condition is
> always false
>         if (rc)
>         ^~~~~~~
> 
> 3) calling amd_pstate_set_epp() in cleanup path after determining that it
> should not be called:
> 
> drivers/cpufreq/amd-pstate.c:1055:6: error: variable 'epp' is used
> uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-
> uninitialized]
>         if (cpudata->epp_policy == cpudata->policy)
>             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/cpufreq/amd-pstate.c:1080:30: note: uninitialized use occurs here
>         amd_pstate_set_epp(cpudata, epp);
>                                     ^~~
> 
> All three are trivial to fix, but most likely there are additional bugs in this
> function when the error handling was not really tested.
> 
> Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support
> for the AMD processors")
> Signed-off-by: Arnd Bergmann <arnd@...db.de>
> ---
>  drivers/cpufreq/amd-pstate.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 168a28bed6ee..847f5f31396d 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -940,7 +940,6 @@ static int amd_pstate_epp_cpu_init(struct
> cpufreq_policy *policy)
>  	int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
>  	struct amd_cpudata *cpudata;
>  	struct device *dev;
> -	int rc;
>  	u64 value;
> 
>  	/*
> @@ -950,7 +949,7 @@ static int amd_pstate_epp_cpu_init(struct
> cpufreq_policy *policy)
>  	amd_perf_ctl_reset(policy->cpu);
>  	dev = get_cpu_device(policy->cpu);
>  	if (!dev)
> -		goto free_cpudata1;
> +		return -ENODEV;
> 
>  	cpudata = kzalloc(sizeof(*cpudata), GFP_KERNEL);
>  	if (!cpudata)
> @@ -959,8 +958,8 @@ static int amd_pstate_epp_cpu_init(struct
> cpufreq_policy *policy)
>  	cpudata->cpu = policy->cpu;
>  	cpudata->epp_policy = 0;
> 
> -	rc = amd_pstate_init_perf(cpudata);
> -	if (rc)
> +	ret = amd_pstate_init_perf(cpudata);
> +	if (ret)
>  		goto free_cpudata1;
> 
>  	min_freq = amd_get_min_freq(cpudata);
> @@ -1076,9 +1075,9 @@ static void amd_pstate_epp_init(unsigned int cpu)
>  		value |= (u64)epp << 24;
>  	}
> 
> +	amd_pstate_set_epp(cpudata, epp);
>  skip_epp:
>  	WRITE_ONCE(cpudata->cppc_req_cached, value);
> -	amd_pstate_set_epp(cpudata, epp);
>  	cpufreq_cpu_put(policy);
>  }
> 
> --
> 2.39.1

Thanks for your quick fix patch.
 
Reviewed-by: Yuan Perry <Perry.Yuan@....com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ