Skip to contentSkip to conversation

Prevent normalize() from reading into undefined memory

PATCH Applied Sohom Datta 3 participants 3 messages Dec 4, 2022 – Jan 18, 2023 1 message not in the archive perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Prevent normalize() from reading into undefined memory

The current implementation does not account for a trailing backslash followed by a null-byte. If a null-byte is encountered following a backslash, normalize() will continue reading (and potentially writing) into garbage memory ignoring the EOS null-byte.

---
 tools/perf/util/expr.l | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/expr.l +4 -1
index 0168a9637330..d47de5f270a8 100644
@@ -42,8 +42,11 @@ static char *normalize(char *str, int runtime)
 	char *dst = str;
 
 	while (*str) {
-		if (*str == '\\')
+		if (*str == '\\') {
 			*dst++ = *++str;
+			if (!*str)
+				break;
+		}
 		else if (*str == '?') {
 			char *paramval;
 			int i = 0;
Signature · 1 line
2.38.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sohom Datta

The current implementation does not account for a trailing backslash followed by a null-byte. If a null-byte is encountered following a backslash, normalize() will continue reading (and potentially writing) into garbage memory ignoring the EOS null-byte.

thanks,
jirka

Quoted 24 lines
---
 tools/perf/util/expr.l | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/expr.l +4 -1
index 0168a9637330..d47de5f270a8 100644
@@ -42,8 +42,11 @@ static char *normalize(char *str, int runtime)
 	char *dst = str;
 
 	while (*str) {
-		if (*str == '\\')
+		if (*str == '\\') {
 			*dst++ = *++str;
+			if (!*str)
+				break;
+		}
 		else if (*str == '?') {
 			char *paramval;
 			int i = 0;
Signature · 1 line
2.38.1

A message that is not in the archive (sent off-list or not yet received): CAP-5=fUjto38BaJX+Uj-BUOc74vg5KqZFewVCuUTW81Q=PAXHA@mail.gmail.com

maintainer Applied
#3 lore raw

Em Sun, Jan 08, 2023 at 04:55:59PM -0800, Ian Rogers escreveu:

Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Sohom Datta
Quoted 8 lines

The current implementation does not account for a trailing backslash followed by a null-byte. If a null-byte is encountered following a backslash, normalize() will continue reading (and potentially writing) into garbage memory ignoring the EOS null-byte.

Quoted 7 lines
Quoted 5 lines

thanks,
jirka

Thanks, applied. Sorry for the delay, probably I didn't saw the "perf
tools: ' prefix in the subject and this fell thru the cracks :-\

Thanks to Ingo for pinging me about this, appreciated.

- Arnaldo

Quoted 28 lines

Thanks,
Ian

Quoted 25 lines

---

Quoted 23 lines
 tools/perf/util/expr.l | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/expr.l +4 -2
index 0168a9637330..d47de5f270a8 100644
@@ -42,8 +42,11 @@ static char *normalize(char *str, int runtime)
      char *dst = str;
 
      while (*str) {
-             if (*str == '\\')
+             if (*str == '\\') {
                      *dst++ = *++str;
+                     if (!*str)
+                             break;
+             }
              else if (*str == '?') {
                      char *paramval;
                      int i = 0;
--

2.38.1