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] [day] [month] [year] [list]
Message-ID: <CAEf4BzbO=E0UTN0OzV9i7G_NsVOkCLJFdOFhRqaUBgTVyG0p3g@mail.gmail.com>
Date: Mon, 16 Jun 2025 14:19:12 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Yuan Chen <chenyuan_fl@....com>
Cc: qmo@...nel.org, ast@...nel.org, bpf@...r.kernel.org, 
	linux-kernel@...r.kernel.org, Yuan Chen <chenyuan@...inos.cn>
Subject: Re: [PATCH] bpftool: Fix JSON writer resource leak in version command

On Mon, Jun 16, 2025 at 8:30 AM Yuan Chen <chenyuan_fl@....com> wrote:
>
> From: Yuan Chen <chenyuan@...inos.cn>
>
> When using `bpftool --version -j/-p`, the JSON writer object
> created in do_version() was not properly destroyed after use.
> This caused a memory leak each time the version command was
> executed with JSON output.
>
> Fix: 004b45c0e51a (tools: bpftool: provide JSON output for all possible commands)
> Signed-off-by: Yuan Chen <chenyuan@...inos.cn>
> Suggested-by: Quentin Monnet <qmo@...nel.org>
> ---
>  tools/bpf/bpftool/main.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index cd5963cb6058..33c68eccd2c3 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -533,8 +533,12 @@ int main(int argc, char **argv)
>         if (argc < 0)
>                 usage();
>
> -       if (version_requested)
> -               return do_version(argc, argv);
> +       if (version_requested) {
> +               ret = do_version(argc, argv);
> +               if (json_output)
> +                       jsonw_destroy(&json_wtr);
> +               return ret;
> +       }

there is also btf__free(base_btf), so instead of jsonw_destroy copy,
let's maybe just do

if (version_requested)
    ret = do_version(...);
else
    ret = cmd_select(...);

jsonw_destroy, btf__free...

return ret;

pw-bot: cr


>
>         ret = cmd_select(commands, argc, argv, do_help);
>
> --
> 2.44.0
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ