Skip to contentSkip to conversation

perf jevents: Fix suspicious code in fixregex()

PATCH In review Namhyung Kim 3 participants 5 messages Sep 3, 2020 – Sep 4, 2020 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf jevents: Fix suspicious code in fixregex()

The new string should have enough space for the original string and the back slashes IMHO.

Cc John Garry <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Ian Rogers <[email protected]>
---
 tools/perf/pmu-events/jevents.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +1 -1
index fa86c5f997cc..fc9c158bfa13 100644
@@ -137,7 +137,7 @@ static char *fixregex(char *s)
 		return s;
 
 	/* allocate space for a new string */
-	fixed = (char *) malloc(len + 1);
+	fixed = (char *) malloc(len + esc_count + 1);
 	if (!fixed)
 		return NULL;
 
Signature · 1 line
2.28.0.402.g5ffc5be6b7-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Namhyung Kim

The new string should have enough space for the original string and the back slashes IMHO.

Cc John Garry <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Ian Rogers <[email protected]>

Definitely looks like the right fix. I'm surprised this hasn't shown up in sanitizer testing.

Thanks,
Ian

Quoted 20 lines
---
 tools/perf/pmu-events/jevents.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +1 -2
index fa86c5f997cc..fc9c158bfa13 100644
@@ -137,7 +137,7 @@ static char *fixregex(char *s)
                return s;
 
        /* allocate space for a new string */
-       fixed = (char *) malloc(len + 1);
+       fixed = (char *) malloc(len + esc_count + 1);
        if (!fixed)
                return NULL;
 
--

2.28.0.402.g5ffc5be6b7-goog

#2 lore raw

Em Thu, Sep 03, 2020 at 10:47:39AM -0700, Ian Rogers escreveu:

Quoted 9 lines · Namhyung Kim
Quoted 7 lines

The new string should have enough space for the original string and the back slashes IMHO.

Cc John Garry <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Ian Rogers <[email protected]>
Quoted 4 lines

Definitely looks like the right fix. I'm surprised this hasn't shown up in sanitizer testing.

Yeap, good catch! Namyung you forgot to add the Fixes tag + Cc the patch author that introduced that bug, I did it:

Cc William Cohen <[email protected]>
Fixes fbc2844e84038ce3 ("perf vendor events: Use more flexible pattern matching for CPU identification for mapfile.csv"

Please consider doing it next time :-)

Thanks a lot!

- Arnaldo

Quoted 23 lines

Thanks,
Ian

Quoted 20 lines
---
 tools/perf/pmu-events/jevents.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +1 -2
index fa86c5f997cc..fc9c158bfa13 100644
@@ -137,7 +137,7 @@ static char *fixregex(char *s)
                return s;
 
        /* allocate space for a new string */
-       fixed = (char *) malloc(len + 1);
+       fixed = (char *) malloc(len + esc_count + 1);
        if (!fixed)
                return NULL;
 
--

2.28.0.402.g5ffc5be6b7-goog

Signature · 1 line
- Arnaldo
author maintainer
#3 lore raw

Hi Arnaldo and Ian,

Quoted 15 lines · Arnaldo Carvalho de Melo

Em Thu, Sep 03, 2020 at 10:47:39AM -0700, Ian Rogers escreveu:

Quoted 13 lines · Namhyung Kim
Quoted 7 lines

The new string should have enough space for the original string and the back slashes IMHO.

Cc John Garry <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Ian Rogers <[email protected]>

Definitely looks like the right fix. I'm surprised this hasn't shown up in sanitizer testing.

I guess the code didn't run on most arch (including x86) since they don't have backslashes.

Quoted 8 lines

Yeap, good catch! Namyung you forgot to add the Fixes tag + Cc the patch author that introduced that bug, I did it:

Cc William Cohen <[email protected]>
Fixes fbc2844e84038ce3 ("perf vendor events: Use more flexible pattern matching for CPU identification for mapfile.csv"

Please consider doing it next time :-)

Oh, right! Will do it later..

Thanks
Namhyung

#4 lore raw

Em Fri, Sep 04, 2020 at 10:38:35AM +0900, Namhyung Kim escreveu:

Quoted 19 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Thu, Sep 03, 2020 at 10:47:39AM -0700, Ian Rogers escreveu:

Quoted 10 lines · Namhyung Kim
Quoted 6 lines

The new string should have enough space for the original string and the back slashes IMHO.

Cc John Garry <[email protected]>
Cc Kajol Jain <[email protected]>
Cc Ian Rogers <[email protected]>

Definitely looks like the right fix. I'm surprised this hasn't shown up in sanitizer testing.

I guess the code didn't run on most arch (including x86) since they don't have backslashes.

Quoted 2 lines

Yeap, good catch! Namyung you forgot to add the Fixes tag + Cc the patch author that introduced that bug, I did it:

Quoted 6 lines
Quoted 4 lines
Cc William Cohen <[email protected]>
Fixes fbc2844e84038ce3 ("perf vendor events: Use more flexible pattern matching for CPU identification for mapfile.csv"

Please consider doing it next time :-)

Oh, right! Will do it later..

Thanks!

- Arnaldo