* [PATCH] perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init
@ 2025-08-05 6:32 Miaoqian Lin
2025-08-15 20:35 ` Namhyung Kim
0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2025-08-05 6:32 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Liang, Kan, James Clark,
linux-perf-users, linux-kernel
Cc: linmq006
Replace NULL check with IS_ERR() check after calling
hashmap__new() since this function return error pointers (ERR_PTR).
Using NULL check could lead to invalid pointer dereference.
Fixes: 754baf426e09 ("perf pmu: Change aliases from list to hashmap")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
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 5a291f1380ed..da6f05872493 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1176,7 +1176,7 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
return -ENOMEM;
pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
- if (!pmu->aliases)
+ if (IS_ERR(pmu->aliases))
return -ENOMEM;
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init
2025-08-05 6:32 [PATCH] perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init Miaoqian Lin
@ 2025-08-15 20:35 ` Namhyung Kim
2025-08-18 19:54 ` Ian Rogers
0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2025-08-15 20:35 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
Adrian Hunter, Liang, Kan, James Clark, linux-perf-users,
linux-kernel
Hello,
On Tue, Aug 05, 2025 at 10:32:07AM +0400, Miaoqian Lin wrote:
> Replace NULL check with IS_ERR() check after calling
> hashmap__new() since this function return error pointers (ERR_PTR).
> Using NULL check could lead to invalid pointer dereference.
>
> Fixes: 754baf426e09 ("perf pmu: Change aliases from list to hashmap")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
> ---
> 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 5a291f1380ed..da6f05872493 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1176,7 +1176,7 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
> return -ENOMEM;
>
> pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
> - if (!pmu->aliases)
> + if (IS_ERR(pmu->aliases))
> return -ENOMEM;
>
> return 0;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init
2025-08-15 20:35 ` Namhyung Kim
@ 2025-08-18 19:54 ` Ian Rogers
0 siblings, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2025-08-18 19:54 UTC (permalink / raw)
To: Namhyung Kim
Cc: Miaoqian Lin, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, James Clark,
linux-perf-users, linux-kernel
On Fri, Aug 15, 2025 at 1:35 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> Hello,
>
> On Tue, Aug 05, 2025 at 10:32:07AM +0400, Miaoqian Lin wrote:
> > Replace NULL check with IS_ERR() check after calling
> > hashmap__new() since this function return error pointers (ERR_PTR).
> > Using NULL check could lead to invalid pointer dereference.
> >
> > Fixes: 754baf426e09 ("perf pmu: Change aliases from list to hashmap")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
>
> Acked-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-18 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 6:32 [PATCH] perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init Miaoqian Lin
2025-08-15 20:35 ` Namhyung Kim
2025-08-18 19:54 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).