* [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
@ 2020-03-08 10:59 zhe.he
2020-03-18 10:32 ` Jiri Olsa
2020-05-08 13:05 ` [tip: perf/core] libperf: " tip-bot2 for He Zhe
0 siblings, 2 replies; 5+ messages in thread
From: zhe.he @ 2020-03-08 10:59 UTC (permalink / raw)
To: acme, jolsa, ak, meyerk, linux-kernel, zhe.he
From: He Zhe <zhe.he@windriver.com>
NULL pointer may be passed to perf_cpu_map__cpu and then cause crash,
such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value")
fix.
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
tools/perf/lib/cpumap.c | 2 +-
tools/perf/lib/evlist.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index f93f4e7..ca02150 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
{
- if (idx < cpus->nr)
+ if (cpus && idx < cpus->nr)
return cpus->map[idx];
return -1;
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 5b9f2ca..f87a239 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -127,6 +127,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
perf_cpu_map__put(evlist->cpus);
perf_thread_map__put(evlist->threads);
evlist->cpus = NULL;
+ evlist->all_cpus = NULL;
evlist->threads = NULL;
fdarray__exit(&evlist->pollfd);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
2020-03-08 10:59 [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus zhe.he
@ 2020-03-18 10:32 ` Jiri Olsa
2020-03-18 13:34 ` Arnaldo Carvalho de Melo
2020-05-08 13:05 ` [tip: perf/core] libperf: " tip-bot2 for He Zhe
1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2020-03-18 10:32 UTC (permalink / raw)
To: zhe.he; +Cc: acme, jolsa, ak, meyerk, linux-kernel
On Sun, Mar 08, 2020 at 06:59:17PM +0800, zhe.he@windriver.com wrote:
> From: He Zhe <zhe.he@windriver.com>
>
> NULL pointer may be passed to perf_cpu_map__cpu and then cause crash,
> such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value")
> fix.
>
> Signed-off-by: He Zhe <zhe.he@windriver.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
thanks,
jirka
> ---
> tools/perf/lib/cpumap.c | 2 +-
> tools/perf/lib/evlist.c | 1 +
> 2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
> index f93f4e7..ca02150 100644
> --- a/tools/perf/lib/cpumap.c
> +++ b/tools/perf/lib/cpumap.c
> @@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
>
> int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
> {
> - if (idx < cpus->nr)
> + if (cpus && idx < cpus->nr)
> return cpus->map[idx];
>
> return -1;
> diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
> index 5b9f2ca..f87a239 100644
> --- a/tools/perf/lib/evlist.c
> +++ b/tools/perf/lib/evlist.c
> @@ -127,6 +127,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
> perf_cpu_map__put(evlist->cpus);
> perf_thread_map__put(evlist->threads);
> evlist->cpus = NULL;
> + evlist->all_cpus = NULL;
> evlist->threads = NULL;
> fdarray__exit(&evlist->pollfd);
> }
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
2020-03-18 10:32 ` Jiri Olsa
@ 2020-03-18 13:34 ` Arnaldo Carvalho de Melo
2020-04-29 17:49 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-03-18 13:34 UTC (permalink / raw)
To: Jiri Olsa; +Cc: zhe.he, jolsa, ak, meyerk, linux-kernel
Em Wed, Mar 18, 2020 at 11:32:24AM +0100, Jiri Olsa escreveu:
> On Sun, Mar 08, 2020 at 06:59:17PM +0800, zhe.he@windriver.com wrote:
> > From: He Zhe <zhe.he@windriver.com>
> >
> > NULL pointer may be passed to perf_cpu_map__cpu and then cause crash,
> > such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value")
> > fix.
> >
> > Signed-off-by: He Zhe <zhe.he@windriver.com>
>
> Acked-by: Jiri Olsa <jolsa@redhat.com>
>
> thanks,
> jirka
>
> > ---
> > tools/perf/lib/cpumap.c | 2 +-
> > tools/perf/lib/evlist.c | 1 +
> > 2 files changed, 2 insertions(+), 1 deletion(-)
this is in tools/lib/perf/ for some time already, I'll do the changes
there, thanks,
- Arnaldo
> >
> > diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
> > index f93f4e7..ca02150 100644
> > --- a/tools/perf/lib/cpumap.c
> > +++ b/tools/perf/lib/cpumap.c
> > @@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
> >
> > int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
> > {
> > - if (idx < cpus->nr)
> > + if (cpus && idx < cpus->nr)
> > return cpus->map[idx];
> >
> > return -1;
> > diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
> > index 5b9f2ca..f87a239 100644
> > --- a/tools/perf/lib/evlist.c
> > +++ b/tools/perf/lib/evlist.c
> > @@ -127,6 +127,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
> > perf_cpu_map__put(evlist->cpus);
> > perf_thread_map__put(evlist->threads);
> > evlist->cpus = NULL;
> > + evlist->all_cpus = NULL;
> > evlist->threads = NULL;
> > fdarray__exit(&evlist->pollfd);
> > }
> > --
> > 2.7.4
> >
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
2020-03-18 13:34 ` Arnaldo Carvalho de Melo
@ 2020-04-29 17:49 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-04-29 17:49 UTC (permalink / raw)
To: Jiri Olsa; +Cc: zhe.he, jolsa, ak, meyerk, linux-kernel
Em Wed, Mar 18, 2020 at 10:34:35AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Mar 18, 2020 at 11:32:24AM +0100, Jiri Olsa escreveu:
> > On Sun, Mar 08, 2020 at 06:59:17PM +0800, zhe.he@windriver.com wrote:
> > > From: He Zhe <zhe.he@windriver.com>
> > >
> > > NULL pointer may be passed to perf_cpu_map__cpu and then cause crash,
> > > such as the one commit cb71f7d43ece ("libperf: Setup initial evlist::all_cpus value")
> > > fix.
> > >
> > > Signed-off-by: He Zhe <zhe.he@windriver.com>
> >
> > Acked-by: Jiri Olsa <jolsa@redhat.com>
> >
> > thanks,
> > jirka
> >
> > > ---
> > > tools/perf/lib/cpumap.c | 2 +-
> > > tools/perf/lib/evlist.c | 1 +
> > > 2 files changed, 2 insertions(+), 1 deletion(-)
>
> this is in tools/lib/perf/ for some time already, I'll do the changes
> there, thanks,
Fixed up from tools/perf/lib to tools/lib/perf and applied.
> - Arnaldo
>
> > >
> > > diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
> > > index f93f4e7..ca02150 100644
> > > --- a/tools/perf/lib/cpumap.c
> > > +++ b/tools/perf/lib/cpumap.c
> > > @@ -247,7 +247,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
> > >
> > > int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
> > > {
> > > - if (idx < cpus->nr)
> > > + if (cpus && idx < cpus->nr)
> > > return cpus->map[idx];
> > >
> > > return -1;
> > > diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
> > > index 5b9f2ca..f87a239 100644
> > > --- a/tools/perf/lib/evlist.c
> > > +++ b/tools/perf/lib/evlist.c
> > > @@ -127,6 +127,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
> > > perf_cpu_map__put(evlist->cpus);
> > > perf_thread_map__put(evlist->threads);
> > > evlist->cpus = NULL;
> > > + evlist->all_cpus = NULL;
> > > evlist->threads = NULL;
> > > fdarray__exit(&evlist->pollfd);
> > > }
> > > --
> > > 2.7.4
> > >
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: perf/core] libperf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
2020-03-08 10:59 [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus zhe.he
2020-03-18 10:32 ` Jiri Olsa
@ 2020-05-08 13:05 ` tip-bot2 for He Zhe
1 sibling, 0 replies; 5+ messages in thread
From: tip-bot2 for He Zhe @ 2020-05-08 13:05 UTC (permalink / raw)
To: linux-tip-commits
Cc: He Zhe, Jiri Olsa, Andi Kleen, Kyle Meyer,
Arnaldo Carvalho de Melo, x86, LKML
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 44d041b7b2c11b6739501fd3763cc6fed62cf0ed
Gitweb: https://git.kernel.org/tip/44d041b7b2c11b6739501fd3763cc6fed62cf0ed
Author: He Zhe <zhe.he@windriver.com>
AuthorDate: Sun, 08 Mar 2020 18:59:17 +08:00
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 05 May 2020 16:35:29 -03:00
libperf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus.
A NULL pointer may be passed to perf_cpu_map__cpu and then cause a
crash, such as the one commit cb71f7d43ece ("libperf: Setup initial
evlist::all_cpus value") fix.
Signed-off-by: He Zhe <zhe.he@windriver.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Kyle Meyer <meyerk@hpe.com>
Link: http://lore.kernel.org/lkml/1583665157-349023-1-git-send-email-zhe.he@windriver.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/perf/cpumap.c | 2 +-
tools/lib/perf/evlist.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
index f93f4e7..ca02150 100644
--- a/tools/lib/perf/cpumap.c
+++ b/tools/lib/perf/cpumap.c
@@ -247,7 +247,7 @@ out:
int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
{
- if (idx < cpus->nr)
+ if (cpus && idx < cpus->nr)
return cpus->map[idx];
return -1;
diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c
index def5505..c481b62 100644
--- a/tools/lib/perf/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -125,6 +125,7 @@ void perf_evlist__exit(struct perf_evlist *evlist)
perf_cpu_map__put(evlist->cpus);
perf_thread_map__put(evlist->threads);
evlist->cpus = NULL;
+ evlist->all_cpus = NULL;
evlist->threads = NULL;
fdarray__exit(&evlist->pollfd);
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-05-08 13:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-08 10:59 [PATCH] perf: Add NULL pointer check for cpu_map iteration and NULL assignment for all_cpus zhe.he
2020-03-18 10:32 ` Jiri Olsa
2020-03-18 13:34 ` Arnaldo Carvalho de Melo
2020-04-29 17:49 ` Arnaldo Carvalho de Melo
2020-05-08 13:05 ` [tip: perf/core] libperf: " tip-bot2 for He Zhe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.