commit: e6f6223943aefc793e2baf8e7e5d5982038ace8a Author: Holger Hoffstätte <holger <AT> applied-asynchrony <DOT> com> AuthorDate: Thu May 1 20:37:49 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Fri May 2 04:37:28 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e6f62239
dev-util/bpftool: set error code in do_loader() Patch from -stable kernel tree to correctly return error code when loading a BPF program fails. Bug: https://github.com/libbpf/bpftool/issues/156 Signed-off-by: Holger Hoffstätte <holger <AT> applied-asynchrony.com> Part-of: https://github.com/gentoo/gentoo/pull/41884 Signed-off-by: Sam James <sam <AT> gentoo.org> ...pftool-7.5.0.ebuild => bpftool-7.5.0-r1.ebuild} | 2 + .../7.5.0-setting-error-code-in-do_loader.patch | 45 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/dev-util/bpftool/bpftool-7.5.0.ebuild b/dev-util/bpftool/bpftool-7.5.0-r1.ebuild similarity index 98% rename from dev-util/bpftool/bpftool-7.5.0.ebuild rename to dev-util/bpftool/bpftool-7.5.0-r1.ebuild index 5100e685f01d..45d7eba2f7a7 100644 --- a/dev-util/bpftool/bpftool-7.5.0.ebuild +++ b/dev-util/bpftool/bpftool-7.5.0-r1.ebuild @@ -65,6 +65,8 @@ BDEPEND=" CONFIG_CHECK="~DEBUG_INFO_BTF" +PATCHES=( "${FILESDIR}/7.5.0-setting-error-code-in-do_loader.patch" ) + pkg_setup() { python-any-r1_pkg_setup use llvm && llvm-r1_pkg_setup diff --git a/dev-util/bpftool/files/7.5.0-setting-error-code-in-do_loader.patch b/dev-util/bpftool/files/7.5.0-setting-error-code-in-do_loader.patch new file mode 100644 index 000000000000..8b77603e13ba --- /dev/null +++ b/dev-util/bpftool/files/7.5.0-setting-error-code-in-do_loader.patch @@ -0,0 +1,45 @@ +Patch from: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=02a4694107b4c830d4bd6d194e98b3ac0bc86f29 +Adapted patch prefix to match the GH mirror sources. + +From 91588da58ed38e4ec870d479ab2d9467288893d2 Mon Sep 17 00:00:00 2001 +From: Sasha Levin <[email protected]> +Date: Tue, 11 Mar 2025 12:12:37 +0900 +Subject: bpf: bpftool: Setting error code in do_loader() + +From: Sewon Nam <[email protected]> + +[ Upstream commit 02a4694107b4c830d4bd6d194e98b3ac0bc86f29 ] + +We are missing setting error code in do_loader() when +bpf_object__open_file() fails. This means the command's exit status code +will be successful, even though the operation failed. So make sure to +return the correct error code. To maintain consistency with other +locations where bpf_object__open_file() is called, return -1. + + [0] Closes: https://github.com/libbpf/bpftool/issues/156 + +Reported-by: Dan Carpenter <[email protected]> +Signed-off-by: Sewon Nam <[email protected]> +Signed-off-by: Andrii Nakryiko <[email protected]> +Tested-by: Quentin Monnet <[email protected]> +Reviewed-by: Quentin Monnet <[email protected]> +Link: https://lore.kernel.org/bpf/[email protected]/t/#u +Link: https://lore.kernel.org/bpf/[email protected] +Signed-off-by: Alexei Starovoitov <[email protected]> +Signed-off-by: Sasha Levin <[email protected]> +--- + tools/bpf/bpftool/prog.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c +index e71be67f1d865..52ffb74ae4e89 100644 +--- a/src/prog.c ++++ b/src/prog.c +@@ -1928,6 +1928,7 @@ static int do_loader(int argc, char **argv) + + obj = bpf_object__open_file(file, &open_opts); + if (!obj) { ++ err = -1; + p_err("failed to open object file"); + goto err_close_obj; + }
