Skip to contentSkip to conversation

perf llvm: don't access out-of-scope array

PATCH Applied Ian Rogers 3 participants 3 messages Sep 26, 2019 – Oct 7, 2019

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf llvm: don't access out-of-scope array

test_dir is assigned to the release array which is out-of-scope 3 lines later. Extend the scope of the release array so that an out-of-scope array isn't accessed.
Bug detected by clang's address sanitizer.

---
 tools/perf/util/llvm-utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/llvm-utils.c +3 -3
index 8d04e3d070b1..8b14e4a7f1dc 100644
@@ -233,14 +233,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
 	const char *prefix_dir = "";
 	const char *suffix_dir = "";
 
+	/* _UTSNAME_LENGTH is 65 */
+	char release[128];
+
 	char *autoconf_path;
 
 	int err;
 
 	if (!test_dir) {
-		/* _UTSNAME_LENGTH is 65 */
-		char release[128];
-
 		err = fetch_kernel_version(NULL, release,
 					   sizeof(release));
 		if (err)
Signature · 1 line
2.23.0.444.g18eeb5a265-goog
#1 lore raw

Em Thu, Sep 26, 2019 at 03:00:18PM -0700, Ian Rogers escreveu:

Quoted 4 lines

test_dir is assigned to the release array which is out-of-scope 3 lines later. Extend the scope of the release array so that an out-of-scope array isn't accessed.
Bug detected by clang's address sanitizer.

This one is really ironic, code to support using clang/llvm in perf is caught with a bug detected by clang's utilities ;-)

Please next time try to use 'git blame' so as to add this:

[root@quaco perf]# git tag --contains 07bc5c699a3d | grep ^v[[:digit:]] | sort --version-sort | head -1 v4.4
[root@quaco perf]#

Cc Wang Nan <[email protected]>
Fixes 07bc5c699a3d ("perf tools: Make fetch_kernel_version() publicly available")

And help get noticed by the various backport bots out there.

Thanks a lot, applied!

- Arnaldo

Quoted 29 lines
---
 tools/perf/util/llvm-utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/llvm-utils.c +3 -3
index 8d04e3d070b1..8b14e4a7f1dc 100644
@@ -233,14 +233,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
 	const char *prefix_dir = "";
 	const char *suffix_dir = "";
 
+	/* _UTSNAME_LENGTH is 65 */
+	char release[128];
+
 	char *autoconf_path;
 
 	int err;
 
 	if (!test_dir) {
-		/* _UTSNAME_LENGTH is 65 */
-		char release[128];
-
 		err = fetch_kernel_version(NULL, release,
 					   sizeof(release));
 		if (err)
Signature · 1 line
2.23.0.444.g18eeb5a265-goog
Signature · 1 line
- Arnaldo
merge bot Applied
#2 lore raw

[tip: perf/urgent] perf llvm: Don't access out-of-scope array

In reply to Ian Rogers
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     7d4c85b7035eb2f9ab217ce649dcd1bfaf0cacd3
Gitweb:        https://git.kernel.org/tip/7d4c85b7035eb2f9ab217ce649dcd1bfaf0cacd3
Author:        Ian Rogers <[email protected]>
AuthorDate:    Thu, 26 Sep 2019 15:00:18 -07:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Mon, 30 Sep 2019 17:29:35 -03:00

perf llvm: Don't access out-of-scope array

The 'test_dir' variable is assigned to the 'release' array which is out-of-scope 3 lines later.

Extend the scope of the 'release' array so that an out-of-scope array isn't accessed.

Bug detected by clang's address sanitizer.

Fixes 07bc5c699a3d ("perf tools: Make fetch_kernel_version() publicly available")
Cc Alexander Shishkin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/util/llvm-utils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/llvm-utils.c +3 -3
index 8d04e3d..8b14e4a 100644
@@ -233,14 +233,14 @@ static int detect_kbuild_dir(char **kbuild_dir)
 	const char *prefix_dir = "";
 	const char *suffix_dir = "";
 
+	/* _UTSNAME_LENGTH is 65 */
+	char release[128];
+
 	char *autoconf_path;
 
 	int err;
 
 	if (!test_dir) {
-		/* _UTSNAME_LENGTH is 65 */
-		char release[128];
-
 		err = fetch_kernel_version(NULL, release,
 					   sizeof(release));
 		if (err)