Re: [PATCH v7 3/5] perf namespaces: Add reference count checking

From: Arnaldo Carvalho de Melo
Date: Mon Apr 17 2023 - 17:30:24 EST


Em Fri, Apr 07, 2023 at 04:04:03PM -0700, Ian Rogers escreveu:
> Add reference count checking controlled by REFCNT_CHECKING ifdef. The
> reference count checking interposes an allocated pointer between the
> reference counted struct on a get and frees the pointer on a put.
> Accesses after a put cause faults and use after free, missed puts are
> caughts as leaks and double puts are double frees.
>
> This checking helped resolve a memory leak and use after free:
> https://lore.kernel.org/linux-perf-users/CAP-5=fWZH20L4kv-BwVtGLwR=Em3AOOT+Q4QGivvQuYn5AsPRg@xxxxxxxxxxxxxx/
>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---
> tools/perf/builtin-inject.c | 2 +-
> tools/perf/util/annotate.c | 2 +-
> tools/perf/util/dso.c | 2 +-
> tools/perf/util/dsos.c | 2 +-
> tools/perf/util/namespaces.c | 132 ++++++++++++++++++++---------------
> tools/perf/util/namespaces.h | 3 +-
> tools/perf/util/symbol.c | 2 +-
> 7 files changed, 83 insertions(+), 62 deletions(-)
>
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index fd2b38458a5d..fe6ddcf7fb1e 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -632,7 +632,7 @@ static int dso__read_build_id(struct dso *dso)
> else if (dso->nsinfo) {
> char *new_name;
>
> - new_name = filename_with_chroot(dso->nsinfo->pid,
> + new_name = filename_with_chroot(RC_CHK_ACCESS(dso->nsinfo)->pid,
> dso->long_name);

To reduce these: