diff options
| author | Thomas Richter <tmricht@linux.ibm.com> | 2025-03-19 13:28:20 +0100 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-04-10 14:44:34 +0200 |
| commit | d70e3e8a38928c3dc0aa605ba8731c3a0071c871 (patch) | |
| tree | a924a05c0b47ce5fa026c66078fb2035c39c5796 | |
| parent | 3b77fa84b2f2cca1aafc11ca373a6c7009b11f8d (diff) | |
| download | linux-d70e3e8a38928c3dc0aa605ba8731c3a0071c871.tar.gz linux-d70e3e8a38928c3dc0aa605ba8731c3a0071c871.tar.bz2 linux-d70e3e8a38928c3dc0aa605ba8731c3a0071c871.zip | |
perf pmu: Handle memory failure in tool_pmu__new()
[ Upstream commit 431db90a7303cb394c5a881b4479946f64052727 ]
On linux-next
commit 72c6f57a4193 ("perf pmu: Dynamically allocate tool PMU")
allocated PMU named "tool" dynamicly. However that allocation
can fail and a NULL pointer is returned. That case is currently
not handled and would result in an invalid address reference.
Add a check for NULL pointer.
Fixes: 72c6f57a4193 ("perf pmu: Dynamically allocate tool PMU")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250319122820.2898333-1-tmricht@linux.ibm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rw-r--r-- | tools/perf/util/pmus.c | 3 | ||||
| -rw-r--r-- | tools/perf/util/tool_pmu.c | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6498021acef0..7959af59908c 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -269,7 +269,8 @@ skip_pe_pmus: if ((to_read_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) != 0 && (read_pmu_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) == 0) { tool_pmu = tool_pmu__new(); - list_add_tail(&tool_pmu->list, &other_pmus); + if (tool_pmu) + list_add_tail(&tool_pmu->list, &other_pmus); } if ((to_read_types & PERF_TOOL_PMU_TYPE_HWMON_MASK) != 0 && (read_pmu_types & PERF_TOOL_PMU_TYPE_HWMON_MASK) == 0) diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c index 9156745ea180..d43d6cf6e4a2 100644 --- a/tools/perf/util/tool_pmu.c +++ b/tools/perf/util/tool_pmu.c @@ -494,12 +494,20 @@ struct perf_pmu *tool_pmu__new(void) { struct perf_pmu *tool = zalloc(sizeof(struct perf_pmu)); + if (!tool) + goto out; tool->name = strdup("tool"); + if (!tool->name) { + zfree(&tool); + goto out; + } + tool->type = PERF_PMU_TYPE_TOOL; INIT_LIST_HEAD(&tool->aliases); INIT_LIST_HEAD(&tool->caps); INIT_LIST_HEAD(&tool->format); tool->events_table = find_core_events_table("common", "common"); +out: return tool; } |
