linux-stable/tools/power/cpupower/utils
Likhitha Korrapati 99481d2195 cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation.
For both the d and e options in 'cpupower idle_set' command, an
atoi() conversion is done without checking if the input argument
is all numeric. So, an atoi conversion is done on any character
provided as input and the CPU idle_set operation continues with
that integer value, which may not be what is intended or entirely
correct.

The output of cpuidle-set before patch is as follows:

[root@xxx cpupower]# cpupower idle-set -e 1$
Idlestate 1 enabled on CPU 0
[snip]
Idlestate 1 enabled on CPU 47

[root@xxx cpupower]# cpupower idle-set -e 11
Idlestate 11 not available on CPU 0
[snip]
Idlestate 11 not available on CPU 47

[root@xxx cpupower]# cpupower idle-set -d 12
Idlestate 12 not available on CPU 0
[snip]
Idlestate 12 not available on CPU 47

[root@xxx cpupower]# cpupower idle-set -d qw
Idlestate 0 disabled on CPU 0
[snip]
Idlestate 0 disabled on CPU 47

This patch adds a check for both d and e options in cpuidle-set.c
to see that the idle_set value is all numeric before doing a
string-to-int conversion using strtol().

The output of cpuidle-set after the patch is as below:

[root@xxx cpupower]# ./cpupower idle-set -e 1$
Bad idle_set value: 1$. Integer expected

[root@xxx cpupower]# ./cpupower idle-set -e 11
Idlestate 11 not available on CPU 0
[snip]
Idlestate 11 not available on CPU 47

[root@xxx cpupower]# ./cpupower idle-set -d 12
Idlestate 12 not available on CPU 0
[snip]
Idlestate 12 not available on CPU 47

[root@xxx cpupower]# ./cpupower idle-set -d qw
Bad idle_set value: qw. Integer expected

Signed-off-by: Brahadambal Srinivasan <latha@linux.vnet.ibm.com>
Signed-off-by: Likhitha Korrapati <likhitha@linux.ibm.com>
Tested-by: Pavithra Prakash <pavrampu@linux.vnet.ibm.com>
Reviewed-by: Rick Lindsley <ricklind@linux.vnet.ibm.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2023-07-18 16:07:08 -06:00
..
helpers cpupower: Add turbo-boost support in cpupower 2023-07-18 16:07:01 -06:00
idle_monitor cpupower: Make TSC read per CPU for Mperf monitor 2023-05-08 10:46:49 -06:00
builtin.h cpupower: Introduce powercap intel-rapl library and powercap-info command 2022-11-30 16:48:28 -07:00
cpufreq-info.c tools/cpupower: Choose base_cpu to display default cpupower details 2022-11-25 10:50:04 -07:00
cpufreq-set.c cpupower: Provide online and offline CPU information 2020-10-26 13:36:24 -06:00
cpuidle-info.c tools/cpupower: Choose base_cpu to display default cpupower details 2022-11-25 10:50:04 -07:00
cpuidle-set.c cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation. 2023-07-18 16:07:08 -06:00
cpupower-info.c tools/cpupower: Choose base_cpu to display default cpupower details 2022-11-25 10:50:04 -07:00
cpupower-set.c cpupower: Add turbo-boost support in cpupower 2023-07-18 16:07:01 -06:00
cpupower.c cpupower: Introduce powercap intel-rapl library and powercap-info command 2022-11-30 16:48:28 -07:00
powercap-info.c cpupower: Introduce powercap intel-rapl library and powercap-info command 2022-11-30 16:48:28 -07:00
version-gen.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00