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]
Message-ID: <CAP-5=fUYfVDfi_+JGqU=o_TcPRNVboMwZewuhU6q+K3md6nUkA@mail.gmail.com>
Date:   Thu, 27 Apr 2023 17:27:50 -0700
From:   Ian Rogers <irogers@...gle.com>
To:     Namhyung Kim <namhyung@...nel.org>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Jiri Olsa <jolsa@...nel.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        linux-perf-users@...r.kernel.org
Subject: Re: [PATCH 1/2] perf list: Fix memory leaks in print_tracepoint_events()

On Thu, Apr 27, 2023 at 4:05 PM Namhyung Kim <namhyung@...nel.org> wrote:
>
> It should free entries (not only the array) filled by scandirat()
> after use.
>
> Signed-off-by: Namhyung Kim <namhyung@...nel.org>

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

Thanks,
Ian

> ---
>  tools/perf/util/print-events.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
> index d416c5484cd5..0a97912fd894 100644
> --- a/tools/perf/util/print-events.c
> +++ b/tools/perf/util/print-events.c
> @@ -83,11 +83,11 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
>                 if (sys_dirent->d_type != DT_DIR ||
>                     !strcmp(sys_dirent->d_name, ".") ||
>                     !strcmp(sys_dirent->d_name, ".."))
> -                       continue;
> +                       goto next_sys;
>
>                 dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH);
>                 if (dir_fd < 0)
> -                       continue;
> +                       goto next_sys;
>
>                 evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort);
>                 for (int j = 0; j < evt_items; j++) {
> @@ -98,12 +98,12 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
>                         if (evt_dirent->d_type != DT_DIR ||
>                             !strcmp(evt_dirent->d_name, ".") ||
>                             !strcmp(evt_dirent->d_name, ".."))
> -                               continue;
> +                               goto next_evt;
>
>                         snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name);
>                         evt_fd = openat(dir_fd, evt_path, O_RDONLY);
>                         if (evt_fd < 0)
> -                               continue;
> +                               goto next_evt;
>                         close(evt_fd);
>
>                         snprintf(evt_path, MAXPATHLEN, "%s:%s",
> @@ -119,9 +119,13 @@ void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unus
>                                         /*desc=*/NULL,
>                                         /*long_desc=*/NULL,
>                                         /*encoding_desc=*/NULL);
> +next_evt:
> +                       free(evt_namelist[j]);
>                 }
>                 close(dir_fd);
>                 free(evt_namelist);
> +next_sys:
> +               free(sys_namelist[i]);
>         }
>
>         free(sys_namelist);
> --
> 2.40.1.495.gc816e09b53d-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ