Skip to contentSkip to conversation

perf dwarf-regs: s390: Fix an off by one bug

PATCH In review Dan Carpenter 4 participants 6 messages Apr 23 – Apr 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf dwarf-regs: s390: Fix an off by one bug

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
index 310a37451bdc..f79216a7665a 100644
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
 	if (perf_regnum == 0)
 		return 0;
 
-	if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+	if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||
 	    dwarf_s390_regnums[perf_regnum] == 0)
 		return -ENOENT;
 
Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Dan Carpenter

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
index 310a37451bdc..f79216a7665a 100644

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 51

Quoted 8 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
 	if (perf_regnum == 0)
 		return 0;
 
-	if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+	if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||
 	    dwarf_s390_regnums[perf_regnum] == 0)
 		return -ENOENT;
 
Signature · 9 lines
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH

Vorsitzender des Aufsichtsrats: Wolfgang Wendt

Geschäftsführung: David Faller

Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
reviewer
#2 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
index 310a37451bdc..f79216a7665a 100644

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 48

Quoted 5 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
        if (perf_regnum == 0)
                return 0;
 
-       if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+       if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||

It looks like this mistake was copy-pasted into these files as well:
- tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-powerpc.c

Could you fix them all?

Thanks,
Ian

Quoted 6 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -1
            dwarf_s390_regnums[perf_regnum] == 0)
                return -ENOENT;
 
--

2.53.0

#3 lore raw
Quoted 27 lines · Ian Rogers
Quoted 15 lines · Dan Carpenter

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
index 310a37451bdc..f79216a7665a 100644

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 48

Quoted 5 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
        if (perf_regnum == 0)
                return 0;
 
-       if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+       if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||

It looks like this mistake was copy-pasted into these files as well:
- tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-powerpc.c

Quoted 1 line

Could you fix them all?

Sure. Do you want that as four separate patches or just one patch with four Fixes tags?

regards,
dan carpenter

reviewer
#4 lore raw
Quoted 29 lines · Dan Carpenter
Quoted 27 lines · Ian Rogers
Quoted 15 lines · Dan Carpenter

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
index 310a37451bdc..f79216a7665a 100644

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 48

Quoted 5 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
        if (perf_regnum == 0)
                return 0;
 
-       if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+       if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||

It looks like this mistake was copy-pasted into these files as well:
- tools/perf/util/dwarf-regs-arch/dwarf-regs-csky.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-x86.c
- tools/perf/util/dwarf-regs-arch/dwarf-regs-powerpc.c

Quoted 4 lines
Quoted 1 line

Could you fix them all?

Sure. Do you want that as four separate patches or just one patch with four Fixes tags?

Probably the latter as it will make backports easier. Thanks! Ian

Quoted 3 lines

regards,
dan carpenter

#5 lore raw
In reply to Dan Carpenter
Quoted 14 lines · Dan Carpenter

Change the > comparison to >= to prevent an out of bounds access of the dwarf_s390_regnums[] array.

Fixes 1e452dd850f3 ("perf dwarf-regs: Add S390 perf to DWARF register number mapping functions")
---
 tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c | 1 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
index 310a37451bdc..f79216a7665a 100644

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 48

Quoted 5 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +1 -1
@@ -45,7 +45,7 @@ int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum)
 	if (perf_regnum == 0)
 		return 0;
 
-	if (perf_regnum <  0 || perf_regnum > (int)ARRAY_SIZE(dwarf_s390_regnums) ||
+	if (perf_regnum <  0 || perf_regnum >= (int)ARRAY_SIZE(dwarf_s390_regnums) ||
                     ^^

Why leave the two spaces?

tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c int __get_dwarf_regnum_for_perf_regnum_s390(int perf_regnum) · line 51

Quoted 3 lines
tools/perf/util/dwarf-regs-arch/dwarf-regs-s390.c +0 -0
 	    dwarf_s390_regnums[perf_regnum] == 0)
 		return -ENOENT;
 

Br,
Linus