2023-09-14 03:30:32

by Ian Rogers

[permalink] [raw]
Subject: [PATCH v1] perf pmu: Ensure all alias variables are initialized

Fix an error detected by memory sanitizer:
```
==4033==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55fb0fbedfc7 in read_alias_info tools/perf/util/pmu.c:457:6
#1 0x55fb0fbea339 in check_info_data tools/perf/util/pmu.c:1434:2
#2 0x55fb0fbea339 in perf_pmu__check_alias tools/perf/util/pmu.c:1504:9
#3 0x55fb0fbdca85 in parse_events_add_pmu tools/perf/util/parse-events.c:1429:32
#4 0x55fb0f965230 in parse_events_parse tools/perf/util/parse-events.y:299:6
#5 0x55fb0fbdf6b2 in parse_events__scanner tools/perf/util/parse-events.c:1822:8
#6 0x55fb0fbdf8c1 in __parse_events tools/perf/util/parse-events.c:2094:8
#7 0x55fb0fa8ffa9 in parse_events tools/perf/util/parse-events.h:41:9
#8 0x55fb0fa8ffa9 in test_event tools/perf/tests/parse-events.c:2393:8
#9 0x55fb0fa8f458 in test__pmu_events tools/perf/tests/parse-events.c:2551:15
#10 0x55fb0fa6d93f in run_test tools/perf/tests/builtin-test.c:242:9
#11 0x55fb0fa6d93f in test_and_print tools/perf/tests/builtin-test.c:271:8
#12 0x55fb0fa6d082 in __cmd_test tools/perf/tests/builtin-test.c:442:5
#13 0x55fb0fa6d082 in cmd_test tools/perf/tests/builtin-test.c:564:9
#14 0x55fb0f942720 in run_builtin tools/perf/perf.c:322:11
#15 0x55fb0f942486 in handle_internal_command tools/perf/perf.c:375:8
#16 0x55fb0f941dab in run_argv tools/perf/perf.c:419:2
#17 0x55fb0f941dab in main tools/perf/perf.c:535:3
```

Fixes: 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files
from sysfs")

Signed-off-by: Ian Rogers <[email protected]>
---
tools/perf/util/pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index d85602aa4b9f..8de6f39abd1b 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -520,7 +520,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
pmu_name = pe->pmu;
}

- alias = malloc(sizeof(*alias));
+ alias = zalloc(sizeof(*alias));
if (!alias)
return -ENOMEM;

--
2.42.0.459.ge4e396fd5e-goog


2023-09-17 05:28:46

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH v1] perf pmu: Ensure all alias variables are initialized

On Wed, Sep 13, 2023 at 7:24 PM Ian Rogers <[email protected]> wrote:
>
> Fix an error detected by memory sanitizer:
> ```
> ==4033==WARNING: MemorySanitizer: use-of-uninitialized-value
> #0 0x55fb0fbedfc7 in read_alias_info tools/perf/util/pmu.c:457:6
> #1 0x55fb0fbea339 in check_info_data tools/perf/util/pmu.c:1434:2
> #2 0x55fb0fbea339 in perf_pmu__check_alias tools/perf/util/pmu.c:1504:9
> #3 0x55fb0fbdca85 in parse_events_add_pmu tools/perf/util/parse-events.c:1429:32
> #4 0x55fb0f965230 in parse_events_parse tools/perf/util/parse-events.y:299:6
> #5 0x55fb0fbdf6b2 in parse_events__scanner tools/perf/util/parse-events.c:1822:8
> #6 0x55fb0fbdf8c1 in __parse_events tools/perf/util/parse-events.c:2094:8
> #7 0x55fb0fa8ffa9 in parse_events tools/perf/util/parse-events.h:41:9
> #8 0x55fb0fa8ffa9 in test_event tools/perf/tests/parse-events.c:2393:8
> #9 0x55fb0fa8f458 in test__pmu_events tools/perf/tests/parse-events.c:2551:15
> #10 0x55fb0fa6d93f in run_test tools/perf/tests/builtin-test.c:242:9
> #11 0x55fb0fa6d93f in test_and_print tools/perf/tests/builtin-test.c:271:8
> #12 0x55fb0fa6d082 in __cmd_test tools/perf/tests/builtin-test.c:442:5
> #13 0x55fb0fa6d082 in cmd_test tools/perf/tests/builtin-test.c:564:9
> #14 0x55fb0f942720 in run_builtin tools/perf/perf.c:322:11
> #15 0x55fb0f942486 in handle_internal_command tools/perf/perf.c:375:8
> #16 0x55fb0f941dab in run_argv tools/perf/perf.c:419:2
> #17 0x55fb0f941dab in main tools/perf/perf.c:535:3
> ```
>
> Fixes: 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files
> from sysfs")
>
> Signed-off-by: Ian Rogers <[email protected]>

Applied to perf-tools, thanks!

Namhyung