]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpftool: Avoid leaking the JSON writer prepared for program metadata
authorQuentin Monnet <quentin@isovalent.com>
Fri, 22 Oct 2021 09:47:43 +0000 (10:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Nov 2021 10:04:13 +0000 (11:04 +0100)
commita526d92e239cc1162f8a176735ccae8d28b85cd0
tree36031eaad7b1f30080e969add60f2107e135cf28
parentf1890b3e95ae4cdf79fe0e257e202fc259288421
bpftool: Avoid leaking the JSON writer prepared for program metadata

[ Upstream commit e89ef634f81c9d90e1824ab183721f3b361472e6 ]

Bpftool creates a new JSON object for writing program metadata in plain
text mode, regardless of metadata being present or not. Then this writer
is freed if any metadata has been found and printed, but it leaks
otherwise. We cannot destroy the object unconditionally, because the
destructor prints an undesirable line break. Instead, make sure the
writer is created only after we have found program metadata to print.

Found with valgrind.

Fixes: aff52e685eb3 ("bpftool: Support dumping metadata")
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211022094743.11052-1-quentin@isovalent.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/bpf/bpftool/prog.c