* [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
@ 2023-03-08 13:23 Chen Yu
2023-03-14 19:39 ` Rafael J. Wysocki
0 siblings, 1 reply; 4+ messages in thread
From: Chen Yu @ 2023-03-08 13:23 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Robert Moore
Cc: linux-acpi, linux-kernel, Chen Yu, Hariganesh Govindarajulu
The user provides arbitrary non-numeic value to level and type,
which could bring expected behavior. In this case the expected
behavior would be to throw an error.
pfrut -h
usage: pfrut [OPTIONS]
code injection:
-l, --load
-s, --stage
-a, --activate
-u, --update [stage and activate]
-q, --query
-d, --revid
update telemetry:
-G, --getloginfo
-T, --type(0:execution, 1:history)
-L, --level(0, 1, 2, 4)
-R, --read
-D, --revid log
pfrut -T A
pfrut -G
log_level:0
log_type:0
log_revid:2
max_data_size:65536
chunk1_size:0
chunk2_size:1530
rollover_cnt:0
reset_cnt:17
Fix this by restricting the input to be in the expected range.
Reported-by: Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
Suggested-by: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
v2: Replace atoi() with strtol() to filter the number. (Rafael)
---
tools/power/acpi/tools/pfrut/pfrut.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/power/acpi/tools/pfrut/pfrut.c b/tools/power/acpi/tools/pfrut/pfrut.c
index 52aa0351533c..388c9e3ad040 100644
--- a/tools/power/acpi/tools/pfrut/pfrut.c
+++ b/tools/power/acpi/tools/pfrut/pfrut.c
@@ -97,7 +97,7 @@ static struct option long_options[] = {
static void parse_options(int argc, char **argv)
{
int option_index = 0;
- char *pathname;
+ char *pathname, *endptr;
int opt;
pathname = strdup(argv[0]);
@@ -125,11 +125,23 @@ static void parse_options(int argc, char **argv)
log_getinfo = 1;
break;
case 'T':
- log_type = atoi(optarg);
+ log_type = strtol(optarg, &endptr, 0);
+ if (*endptr || (log_type != 0 && log_type != 1)) {
+ printf("Number expected: type(0:execution, 1:history) - Quit.\n");
+ exit(1);
+ }
+
set_log_type = 1;
break;
case 'L':
- log_level = atoi(optarg);
+ log_level = strtol(optarg, &endptr, 0);
+ if (*endptr ||
+ (log_level != 0 && log_level != 1 &&
+ log_level != 2 && log_level != 4)) {
+ printf("Number expected: level(0, 1, 2, 4) - Quit.\n");
+ exit(1);
+ }
+
set_log_level = 1;
break;
case 'R':
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
2023-03-08 13:23 [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range Chen Yu
@ 2023-03-14 19:39 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2023-03-14 19:39 UTC (permalink / raw)
To: Chen Yu
Cc: Rafael J. Wysocki, Len Brown, Robert Moore, linux-acpi,
linux-kernel, Hariganesh Govindarajulu
On Wed, Mar 8, 2023 at 6:28 AM Chen Yu <yu.c.chen@intel.com> wrote:
>
> The user provides arbitrary non-numeic value to level and type,
> which could bring expected behavior. In this case the expected
> behavior would be to throw an error.
>
> pfrut -h
> usage: pfrut [OPTIONS]
> code injection:
> -l, --load
> -s, --stage
> -a, --activate
> -u, --update [stage and activate]
> -q, --query
> -d, --revid
> update telemetry:
> -G, --getloginfo
> -T, --type(0:execution, 1:history)
> -L, --level(0, 1, 2, 4)
> -R, --read
> -D, --revid log
>
> pfrut -T A
> pfrut -G
> log_level:0
> log_type:0
> log_revid:2
> max_data_size:65536
> chunk1_size:0
> chunk2_size:1530
> rollover_cnt:0
> reset_cnt:17
>
> Fix this by restricting the input to be in the expected range.
>
> Reported-by: Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
> Suggested-by: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> ---
> v2: Replace atoi() with strtol() to filter the number. (Rafael)
>
> ---
> tools/power/acpi/tools/pfrut/pfrut.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/tools/power/acpi/tools/pfrut/pfrut.c b/tools/power/acpi/tools/pfrut/pfrut.c
> index 52aa0351533c..388c9e3ad040 100644
> --- a/tools/power/acpi/tools/pfrut/pfrut.c
> +++ b/tools/power/acpi/tools/pfrut/pfrut.c
> @@ -97,7 +97,7 @@ static struct option long_options[] = {
> static void parse_options(int argc, char **argv)
> {
> int option_index = 0;
> - char *pathname;
> + char *pathname, *endptr;
> int opt;
>
> pathname = strdup(argv[0]);
> @@ -125,11 +125,23 @@ static void parse_options(int argc, char **argv)
> log_getinfo = 1;
> break;
> case 'T':
> - log_type = atoi(optarg);
> + log_type = strtol(optarg, &endptr, 0);
> + if (*endptr || (log_type != 0 && log_type != 1)) {
> + printf("Number expected: type(0:execution, 1:history) - Quit.\n");
> + exit(1);
> + }
> +
> set_log_type = 1;
> break;
> case 'L':
> - log_level = atoi(optarg);
> + log_level = strtol(optarg, &endptr, 0);
> + if (*endptr ||
> + (log_level != 0 && log_level != 1 &&
> + log_level != 2 && log_level != 4)) {
> + printf("Number expected: level(0, 1, 2, 4) - Quit.\n");
> + exit(1);
> + }
> +
> set_log_level = 1;
> break;
> case 'R':
> --
Applied as 6.3-rc material, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
@ 2023-03-08 13:09 Chen Yu
2023-03-08 5:15 ` Chen Yu
0 siblings, 1 reply; 4+ messages in thread
From: Chen Yu @ 2023-03-08 13:09 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Robert Moore
Cc: linux-acpi, acpica-devel, linux-kernel, Chen Yu,
Hariganesh Govindarajulu
The user provides arbitrary non-numeic value to level and type, which could
bring expected bahavior. In this case the expected behavior would be to throw
an error.
pfrut -h
usage: pfrut [OPTIONS]
code injection:
-l, --load
-s, --stage
-a, --activate
-u, --update [stage and activate]
-q, --query
-d, --revid
update telemetry:
-G, --getloginfo
-T, --type(0:execution, 1:history)
-L, --level(0, 1, 2, 4)
-R, --read
-D, --revid log
pfrut -T A
pfrut -G
log_level:0
log_type:0
log_revid:2
max_data_size:65536
chunk1_size:0
chunk2_size:1530
rollover_cnt:0
reset_cnt:17
Fix this by restricting the input to be in the expected range.
Reported-by: Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
Suggested-by: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
tools/power/acpi/tools/pfrut/pfrut.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/tools/power/acpi/tools/pfrut/pfrut.c b/tools/power/acpi/tools/pfrut/pfrut.c
index 52aa0351533c..13161a6e672d 100644
--- a/tools/power/acpi/tools/pfrut/pfrut.c
+++ b/tools/power/acpi/tools/pfrut/pfrut.c
@@ -97,7 +97,7 @@ static struct option long_options[] = {
static void parse_options(int argc, char **argv)
{
int option_index = 0;
- char *pathname;
+ char *pathname, *endptr;
int opt;
pathname = strdup(argv[0]);
@@ -125,11 +125,21 @@ static void parse_options(int argc, char **argv)
log_getinfo = 1;
break;
case 'T':
- log_type = atoi(optarg);
+ log_type = strtol(optarg, &endptr, 0);
+ if(*endptr || (log_type != 0 && log_type != 1)) {
+ printf("Please provide numeric value for type (0:execution, 1:history) - Exiting.\n");
+ exit(1);
+ }
+
set_log_type = 1;
break;
case 'L':
- log_level = atoi(optarg);
+ log_level = strtol(optarg, &endptr, 0);
+ if(*endptr || (log_level != 0 && log_level != 1 && log_level != 2 && log_level != 4)) {
+ printf("Please provide numeric value for level (0, 1, 2, 4) - Exiting.\n");
+ exit(1);
+ }
+
set_log_level = 1;
break;
case 'R':
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range
2023-03-08 13:09 Chen Yu
@ 2023-03-08 5:15 ` Chen Yu
0 siblings, 0 replies; 4+ messages in thread
From: Chen Yu @ 2023-03-08 5:15 UTC (permalink / raw)
To: Rafael J. Wysocki, Len Brown, Robert Moore
Cc: linux-acpi, acpica-devel, linux-kernel, Hariganesh Govindarajulu
On 2023-03-08 at 21:09:02 +0800, Chen Yu wrote:
> The user provides arbitrary non-numeic value to level and type, which could
> bring expected bahavior. In this case the expected behavior would be to throw
> an error.
>
> pfrut -h
> usage: pfrut [OPTIONS]
> code injection:
> -l, --load
> -s, --stage
> -a, --activate
> -u, --update [stage and activate]
> -q, --query
> -d, --revid
> update telemetry:
> -G, --getloginfo
> -T, --type(0:execution, 1:history)
> -L, --level(0, 1, 2, 4)
> -R, --read
> -D, --revid log
>
> pfrut -T A
> pfrut -G
> log_level:0
> log_type:0
> log_revid:2
> max_data_size:65536
> chunk1_size:0
> chunk2_size:1530
> rollover_cnt:0
> reset_cnt:17
>
> Fix this by restricting the input to be in the expected range.
>
> Reported-by: Hariganesh Govindarajulu <hariganesh.govindarajulu@intel.com>
> Suggested-by: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>
>
Please ignore this version due to broken format, I'll send a new one.
Sorry for the noise.
thanks,
Chenyu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-14 19:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 13:23 [PATCH v2] ACPI: tools: pfrut: Check if the input of level and type is in the right numeric range Chen Yu
2023-03-14 19:39 ` Rafael J. Wysocki
-- strict thread matches above, loose matches on Subject: below --
2023-03-08 13:09 Chen Yu
2023-03-08 5:15 ` Chen Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).