lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 12 Jun 2023 09:32:30 -0700
From:   Ian Rogers <irogers@...gle.com>
To:     James Clark <james.clark@....com>
Cc:     linux-perf-users@...r.kernel.org,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf map: Fix refcount errors on Arm with -DREFCNT_CHECKING=1

On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@....com> wrote:
>
> When quitting after running a perf report, the refcount checker finds
> some double frees. The issue is that map__put() is called on a function
> argument so it removes the refcount wrapper that someone else was using.
>
> Fix it by only calling map__put() on a reference that is owned by this
> function.
>
> Signed-off-by: James Clark <james.clark@....com>

Acked-by: Ian Rogers <irogers@...gle.com>

> ---
>  tools/perf/util/symbol-elf.c | 9 +++++----
>  tools/perf/util/symbol.c     | 9 +++++----
>  2 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index 63882a4db5c7..ec0d7810bbb0 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -1365,6 +1365,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
>         struct dso *curr_dso = *curr_dsop;
>         struct map *curr_map;
>         char dso_name[PATH_MAX];
> +       struct map *map_ref;

nit: can we narrow the scope of this by moving it to the scope where it is used.

>
>         /* Adjust symbol to map to file offset */
>         if (adjust_kernel_syms)
> @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
>                         if (kmaps) {
>                                 int err;
>
> -                               map__get(map);
> -                               maps__remove(kmaps, map);
> -                               err = maps__insert(kmaps, map);
> -                               map__put(map);
> +                               map_ref = map__get(map);
> +                               maps__remove(kmaps, map_ref);
> +                               err = maps__insert(kmaps, map_ref);
> +                               map__put(map_ref);
>                                 if (err)
>                                         return err;
>                         }
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 6b9c55784b56..b3034fd5c0af 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1368,6 +1368,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
>         int err, fd;
>         char kcore_filename[PATH_MAX];
>         u64 stext;
> +       struct map *map_ref;

nit: can we narrow the scope of this by moving it to the scope where it is used.

Thanks,
Ian

>
>         if (!kmaps)
>                 return -EINVAL;
> @@ -1464,10 +1465,10 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
>                         map__set_map_ip(map, map__map_ip_ptr(new_map));
>                         map__set_unmap_ip(map, map__unmap_ip_ptr(new_map));
>                         /* Ensure maps are correctly ordered */
> -                       map__get(map);
> -                       maps__remove(kmaps, map);
> -                       err = maps__insert(kmaps, map);
> -                       map__put(map);
> +                       map_ref = map__get(map);
> +                       maps__remove(kmaps, map_ref);
> +                       err = maps__insert(kmaps, map_ref);
> +                       map__put(map_ref);
>                         map__put(new_map);
>                         if (err)
>                                 goto out_err;
> --
> 2.34.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ