From 92c52530bb2f838e6c016a5d13bb6eac8ea5b70d Mon Sep 17 00:00:00 2001 From: Flatcar Buildbot Date: Mon, 11 Nov 2024 07:06:09 +0000 Subject: [PATCH] dev-util/bpftool: Sync with Gentoo It's from Gentoo commit 8ac76c7f1c0b17a74750c0129cbebaa8608ea5f1. --- .../portage-stable/dev-util/bpftool/Manifest | 2 + .../dev-util/bpftool/bpftool-7.4.0.ebuild | 130 +++++++++ .../dev-util/bpftool/bpftool-9999.ebuild | 119 ++++++++ ...n-provided-dir-instead-of-parent-dir.patch | 255 ++++++++++++++++++ ...ESTDIR-to-empty-when-building-libbpf.patch | 38 +++ .../7.4-003-fix-typo-in-usage-help.patch | 30 +++ ...4-004-fix-the-wrong-format-specifier.patch | 38 +++ ...caused-by-shifting-into-the-sign-bit.patch | 47 ++++ ...-006-fix-undefined-behavior-in-qsort.patch | 49 ++++ ...ld-time-when-trying-to-detect-libbfd.patch | 48 ++++ ...-arguments-warning-for-feature-probe.patch | 38 +++ .../dev-util/bpftool/metadata.xml | 3 + 12 files changed, 797 insertions(+) create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-7.4.0.ebuild create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-9999.ebuild create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-003-fix-typo-in-usage-help.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-004-fix-the-wrong-format-specifier.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-006-fix-undefined-behavior-in-qsort.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch create mode 100644 sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/Manifest b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/Manifest index 14591e4668..bd595253b0 100644 --- a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/Manifest +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/Manifest @@ -1,3 +1,5 @@ +DIST bpftool-7.4.0.tar.gz 472915 BLAKE2B ae7b6bc6cb742712981ba8972bcecccc63d440b2a77c5a14f91ba5106c013774313d65fd3f42b843ba4027ab17cf9d44d256270f7f8ad11907714f16f3149078 SHA512 08a3095b37a9b897400f2be7dbb9de10d129ae4eef193d03955fdf84017cd3a5d7419e856aa68a425e609419868e8b1dd5409b4f218cc24feeb059c1898cdff4 +DIST libbpf-1.4.7.tar.gz 1016441 BLAKE2B 10be52c7e97b2f08edd33cb263c4737bb52edfd2226f0c5b86d4f95b584b81f8f6b1ede469e9ad6c231e55b6d6b9a038160662606c3f30dc79b1336aaaa90e74 SHA512 f09ff28ac75b0d0c1bfe7d233aee6a00e5c21f185646b2afe11b7bd048d74962f893237437dd81a762768f9235b9f2a2a33cb297201b2aa3e98f7c6f58e5b365 DIST linux-6.10.tar.xz 145142812 BLAKE2B bb243ea7493b9d63aa2df2050a3f1ae2b89ee84a20015239cf157e3f4f51c7ac5efedc8a51132b2d7482f9276ac418de6624831c8a3b806130d9c2d2124c539b SHA512 baa2487954044f991d2ae254d77d14a1f0185dd62c9f0fcaff69f586c9f906823017b8db1c4588f27b076dfa3ebb606929fec859f60ea419e7974330b9289cc2 DIST linux-6.11.tar.xz 146900704 BLAKE2B e7750c0878d71a56a0ce52d4c4c912199dad5bf5e2e8f872585a6494afbb37cbd852e612a6858936d2dc9b7776a3933818f540db408d57e90d18ea5249bba7ab SHA512 329c1f94008742e3f0c2ce7e591a16316d1b2cb9ea4596d4f45604097e07b7aa2f64afa40630a07f321a858455c77aa32ba57b271932ddcf4dc27863f9081cea DIST linux-6.8.tar.xz 142502100 BLAKE2B c6f17f816cea16e629f63e9379b98888713f57b2c5173306926471f139a9d612a0c74e119341f8075390e55e203d787d9edeb4ad5a064b18870f6f0f7ffaafb2 SHA512 5c4eb4aa1d3f7d1ea01c0f7ddeadacdece6e144fd4bdfc16b2b925d3e10dc04de3a6db69320b79a96c3560052616f001d2c09e7a1bb4f7b731e2380a7ecce068 diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-7.4.0.ebuild b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-7.4.0.ebuild new file mode 100644 index 0000000000..b1481b3e2c --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-7.4.0.ebuild @@ -0,0 +1,130 @@ +# Copyright 2021-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +LLVM_COMPAT=( {15..19} ) +LLVM_OPTIONAL=1 +PYTHON_COMPAT=( python3_{10..13} ) + +inherit bash-completion-r1 linux-info llvm-r1 optfeature python-any-r1 toolchain-funcs + +DESCRIPTION="Tool for inspection and simple manipulation of eBPF programs and maps" +HOMEPAGE="https://github.com/libbpf/bpftool" + +if [[ ${PV} == *9999* ]] ; then + inherit git-r3 + EGIT_REPO_URI="https://github.com/libbpf/bpftool.git" + EGIT_SUBMODULES=(libbpf) +else + # bpftool typically vendors whatever libbpf is current at the time + # of a release, while libbpf publishes minor updates more frequently. + # Uncomment the following to bundle an updated libbpf e.g. in case of + # security or crasher bugs in libbpf and to keep the two synchronized. + # This allows us to quickly update the vendored lib with a revbump. + # Currently bpftool-x.y vendors libbpf-1.y; DO NOT mix different y versions. + # See the libbpf repo (https://github.com/libbpf/libbpf) for possible updates. + LIBBPF_VERSION=1.4.7 + + if [[ ! -z ${LIBBPF_VERSION} ]] ; then + SRC_URI="https://github.com/libbpf/bpftool/archive/refs/tags/v${PV}.tar.gz -> bpftool-${PV}.tar.gz + https://github.com/libbpf/libbpf/archive/refs/tags/v${LIBBPF_VERSION}.tar.gz + -> libbpf-${LIBBPF_VERSION}.tar.gz" + else + # use tarball with bundled libbpf + SRC_URI="https://github.com/libbpf/bpftool/releases/download/v${PV}/bpftool-libbpf-v${PV}-sources.tar.gz" + S="${WORKDIR}/bpftool-libbpf-v${PV}-sources" + fi + + KEYWORDS="amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86" +fi + +LICENSE="|| ( GPL-2 BSD-2 )" +SLOT="0" +IUSE="caps llvm" +REQUIRED_USE="llvm? ( ${LLVM_REQUIRED_USE} )" + +RDEPEND=" + caps? ( sys-libs/libcap:= ) + llvm? ( $(llvm_gen_dep 'sys-devel/llvm:${LLVM_SLOT}') ) + !llvm? ( sys-libs/binutils-libs:= ) + sys-libs/zlib:= + virtual/libelf:= +" +DEPEND=" + ${RDEPEND} + >=sys-kernel/linux-headers-5.8 +" +BDEPEND=" + ${PYTHON_DEPS} + app-arch/tar + dev-python/docutils + $(llvm_gen_dep 'sys-devel/clang:${LLVM_SLOT}[llvm_targets_BPF]') +" + +CONFIG_CHECK="~DEBUG_INFO_BTF" + +PATCHES=( + "${FILESDIR}"/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch + "${FILESDIR}"/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch + "${FILESDIR}"/7.4-003-fix-typo-in-usage-help.patch + "${FILESDIR}"/7.4-004-fix-the-wrong-format-specifier.patch + "${FILESDIR}"/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch + "${FILESDIR}"/7.4-006-fix-undefined-behavior-in-qsort.patch + "${FILESDIR}"/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch + "${FILESDIR}"/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch +) + +pkg_setup() { + python-any-r1_pkg_setup + use llvm && llvm-r1_pkg_setup +} + +src_prepare() { + default + + # prepare libbpf if necessary + if [[ ! -z ${LIBBPF_VERSION} ]] ; then + rm -rf libbpf || die + ln -s "${WORKDIR}/libbpf-${LIBBPF_VERSION}" libbpf || die + fi + + # remove -Werror from libbpf (bug 887981) + sed -i -e 's/\-Werror//g' libbpf/src/Makefile || die + + # remove -Werror from bpftool feature detection + sed -i -e 's/-Werror//g' src/Makefile.feature || die + + # remove hardcoded/unhelpful flags from bpftool + sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die + + # Use rst2man or rst2man.py depending on which one exists (#930076) + type -P rst2man >/dev/null || sed -i -e 's/rst2man/rst2man.py/g' docs/Makefile || die +} + +bpftool_make() { + tc-export AR CC LD + + emake \ + ARCH="$(tc-arch-kernel)" \ + CLANG="$(get_llvm_prefix -b)/bin/clang" \ + HOSTAR="$(tc-getBUILD_AR)" \ + HOSTCC="$(tc-getBUILD_CC)" \ + HOSTLD="$(tc-getBUILD_LD)" \ + bash_compdir="$(get_bashcompdir)" \ + feature-libcap="$(usex caps 1 0)" \ + feature-llvm="$(usex llvm 1 0)" \ + prefix="${EPREFIX}"/usr \ + V=1 \ + "$@" +} + +src_compile() { + bpftool_make -C src + bpftool_make -C docs +} + +src_install() { + bpftool_make DESTDIR="${D}" -C src install + bpftool_make mandir="${ED}"/usr/share/man -C docs install +} diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-9999.ebuild b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-9999.ebuild new file mode 100644 index 0000000000..4c6ef01a02 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/bpftool-9999.ebuild @@ -0,0 +1,119 @@ +# Copyright 2021-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +LLVM_COMPAT=( {15..19} ) +LLVM_OPTIONAL=1 +PYTHON_COMPAT=( python3_{10..13} ) + +inherit bash-completion-r1 linux-info llvm-r1 optfeature python-any-r1 toolchain-funcs + +DESCRIPTION="Tool for inspection and simple manipulation of eBPF programs and maps" +HOMEPAGE="https://github.com/libbpf/bpftool" + +if [[ ${PV} == *9999* ]] ; then + inherit git-r3 + EGIT_REPO_URI="https://github.com/libbpf/bpftool.git" + EGIT_SUBMODULES=(libbpf) +else + # bpftool typically vendors whatever libbpf is current at the time + # of a release, while libbpf publishes minor updates more frequently. + # Uncomment the following to bundle an updated libbpf e.g. in case of + # security or crasher bugs in libbpf and to keep the two synchronized. + # This allows us to quickly update the vendored lib with a revbump. + # Currently bpftool-x.y vendors libbpf-1.y; DO NOT mix different y versions. + # See the libbpf repo (https://github.com/libbpf/libbpf) for possible updates. + # LIBBPF_VERSION=1.5.0 + + if [[ ! -z ${LIBBPF_VERSION} ]] ; then + SRC_URI="https://github.com/libbpf/bpftool/archive/refs/tags/v${PV}.tar.gz -> bpftool-${PV}.tar.gz + https://github.com/libbpf/libbpf/archive/refs/tags/v${LIBBPF_VERSION}.tar.gz + -> libbpf-${LIBBPF_VERSION}.tar.gz" + else + # use tarball with bundled libbpf + SRC_URI="https://github.com/libbpf/bpftool/releases/download/v${PV}/bpftool-libbpf-v${PV}-sources.tar.gz" + S="${WORKDIR}/bpftool-libbpf-v${PV}-sources" + fi + + KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86" +fi + +LICENSE="|| ( GPL-2 BSD-2 )" +SLOT="0" +IUSE="caps llvm" +REQUIRED_USE="llvm? ( ${LLVM_REQUIRED_USE} )" + +RDEPEND=" + caps? ( sys-libs/libcap:= ) + llvm? ( $(llvm_gen_dep 'sys-devel/llvm:${LLVM_SLOT}') ) + !llvm? ( sys-libs/binutils-libs:= ) + sys-libs/zlib:= + virtual/libelf:= +" +DEPEND=" + ${RDEPEND} + >=sys-kernel/linux-headers-5.8 +" +BDEPEND=" + ${PYTHON_DEPS} + app-arch/tar + dev-python/docutils + $(llvm_gen_dep 'sys-devel/clang:${LLVM_SLOT}[llvm_targets_BPF]') +" + +CONFIG_CHECK="~DEBUG_INFO_BTF" + +pkg_setup() { + python-any-r1_pkg_setup + use llvm && llvm-r1_pkg_setup +} + +src_prepare() { + default + + # prepare libbpf if necessary + if [[ ! -z ${LIBBPF_VERSION} ]] ; then + rm -rf libbpf || die + ln -s "${WORKDIR}/libbpf-${LIBBPF_VERSION}" libbpf || die + fi + + # remove -Werror from libbpf (bug 887981) + sed -i -e 's/\-Werror//g' libbpf/src/Makefile || die + + # remove -Werror from bpftool feature detection + sed -i -e 's/-Werror//g' src/Makefile.feature || die + + # remove hardcoded/unhelpful flags from bpftool + sed -i -e '/CFLAGS += -O2/d' -e 's/-W //g' -e 's/-Wextra //g' src/Makefile || die + + # Use rst2man or rst2man.py depending on which one exists (#930076) + type -P rst2man >/dev/null || sed -i -e 's/rst2man/rst2man.py/g' docs/Makefile || die +} + +bpftool_make() { + tc-export AR CC LD + + emake \ + ARCH="$(tc-arch-kernel)" \ + CLANG="$(get_llvm_prefix -b)/bin/clang" \ + HOSTAR="$(tc-getBUILD_AR)" \ + HOSTCC="$(tc-getBUILD_CC)" \ + HOSTLD="$(tc-getBUILD_LD)" \ + bash_compdir="$(get_bashcompdir)" \ + feature-libcap="$(usex caps 1 0)" \ + feature-llvm="$(usex llvm 1 0)" \ + prefix="${EPREFIX}"/usr \ + V=1 \ + "$@" +} + +src_compile() { + bpftool_make -C src + bpftool_make -C docs +} + +src_install() { + bpftool_make DESTDIR="${D}" -C src install + bpftool_make mandir="${ED}"/usr/share/man -C docs install +} diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch new file mode 100644 index 0000000000..c874555d37 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-001-mount-bpffs-on-provided-dir-instead-of-parent-dir.patch @@ -0,0 +1,255 @@ +From 54bcb7c7fecb33d40266223d4bba49ad38e59ee3 Mon Sep 17 00:00:00 2001 +From: Sahil Siddiq +Date: Fri, 5 Apr 2024 00:52:19 +0530 +Subject: [PATCH] bpftool: Mount bpffs on provided dir instead of parent dir + +When pinning programs/objects under PATH (eg: during "bpftool prog +loadall") the bpffs is mounted on the parent dir of PATH in the +following situations: +- the given dir exists but it is not bpffs. +- the given dir doesn't exist and the parent dir is not bpffs. + +Mounting on the parent dir can also have the unintentional side- +effect of hiding other files located under the parent dir. + +If the given dir exists but is not bpffs, then the bpffs should +be mounted on the given dir and not its parent dir. + +Similarly, if the given dir doesn't exist and its parent dir is not +bpffs, then the given dir should be created and the bpffs should be +mounted on this new dir. + +Fixes: 2a36c26fe3b8 ("bpftool: Support bpffs mountpoint as pin path for prog loadall") +Signed-off-by: Sahil Siddiq +Signed-off-by: Andrii Nakryiko +Link: https://lore.kernel.org/bpf/2da44d24-74ae-a564-1764-afccf395eeec@isovalent.com/T/#t +Link: https://lore.kernel.org/bpf/20240404192219.52373-1-icegambit91@gmail.com + +Closes: https://github.com/libbpf/bpftool/issues/100 + +Changes since v1: + - Split "mount_bpffs_for_pin" into two functions. + This is done to improve maintainability and readability. + +Changes since v2: +- mount_bpffs_for_pin: rename to "create_and_mount_bpffs_dir". +- mount_bpffs_given_file: rename to "mount_bpffs_given_file". +- create_and_mount_bpffs_dir: + - introduce "dir_exists" boolean. + - remove new dir if "mnt_fs" fails. +- improve error handling and error messages. + +Changes since v3: +- Rectify function name. +- Improve error messages and formatting. +- mount_bpffs_for_file: + - Check if dir exists before block_mount check. + +Changes since v4: +- Use strdup instead of strcpy. +- create_and_mount_bpffs_dir: + - Use S_IRWXU instead of 0700. +- Improve error handling and formatting. +--- + src/common.c | 96 ++++++++++++++++++++++++++++++++++++++++++------ + src/iter.c | 2 +- + src/main.h | 3 +- + src/prog.c | 5 ++- + src/struct_ops.c | 2 +- + 5 files changed, 92 insertions(+), 16 deletions(-) + +diff --git a/src/common.c b/src/common.c +index cc6e6aae..958e92ac 100644 +--- a/src/common.c ++++ b/src/common.c +@@ -244,29 +244,101 @@ int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type) + return fd; + } + +-int mount_bpffs_for_pin(const char *name, bool is_dir) ++int create_and_mount_bpffs_dir(const char *dir_name) + { + char err_str[ERR_MAX_LEN]; +- char *file; +- char *dir; ++ bool dir_exists; + int err = 0; + +- if (is_dir && is_bpffs(name)) ++ if (is_bpffs(dir_name)) + return err; + +- file = malloc(strlen(name) + 1); +- if (!file) { ++ dir_exists = access(dir_name, F_OK) == 0; ++ ++ if (!dir_exists) { ++ char *temp_name; ++ char *parent_name; ++ ++ temp_name = strdup(dir_name); ++ if (!temp_name) { ++ p_err("mem alloc failed"); ++ return -1; ++ } ++ ++ parent_name = dirname(temp_name); ++ ++ if (is_bpffs(parent_name)) { ++ /* nothing to do if already mounted */ ++ free(temp_name); ++ return err; ++ } ++ ++ if (access(parent_name, F_OK) == -1) { ++ p_err("can't create dir '%s' to pin BPF object: parent dir '%s' doesn't exist", ++ dir_name, parent_name); ++ free(temp_name); ++ return -1; ++ } ++ ++ free(temp_name); ++ } ++ ++ if (block_mount) { ++ p_err("no BPF file system found, not mounting it due to --nomount option"); ++ return -1; ++ } ++ ++ if (!dir_exists) { ++ err = mkdir(dir_name, S_IRWXU); ++ if (err) { ++ p_err("failed to create dir '%s': %s", dir_name, strerror(errno)); ++ return err; ++ } ++ } ++ ++ err = mnt_fs(dir_name, "bpf", err_str, ERR_MAX_LEN); ++ if (err) { ++ err_str[ERR_MAX_LEN - 1] = '\0'; ++ p_err("can't mount BPF file system on given dir '%s': %s", ++ dir_name, err_str); ++ ++ if (!dir_exists) ++ rmdir(dir_name); ++ } ++ ++ return err; ++} ++ ++int mount_bpffs_for_file(const char *file_name) ++{ ++ char err_str[ERR_MAX_LEN]; ++ char *temp_name; ++ char *dir; ++ int err = 0; ++ ++ if (access(file_name, F_OK) != -1) { ++ p_err("can't pin BPF object: path '%s' already exists", file_name); ++ return -1; ++ } ++ ++ temp_name = strdup(file_name); ++ if (!temp_name) { + p_err("mem alloc failed"); + return -1; + } + +- strcpy(file, name); +- dir = dirname(file); ++ dir = dirname(temp_name); + + if (is_bpffs(dir)) + /* nothing to do if already mounted */ + goto out_free; + ++ if (access(dir, F_OK) == -1) { ++ p_err("can't pin BPF object: dir '%s' doesn't exist", dir); ++ err = -1; ++ goto out_free; ++ } ++ + if (block_mount) { + p_err("no BPF file system found, not mounting it due to --nomount option"); + err = -1; +@@ -276,12 +348,12 @@ int mount_bpffs_for_pin(const char *name, bool is_dir) + err = mnt_fs(dir, "bpf", err_str, ERR_MAX_LEN); + if (err) { + err_str[ERR_MAX_LEN - 1] = '\0'; +- p_err("can't mount BPF file system to pin the object (%s): %s", +- name, err_str); ++ p_err("can't mount BPF file system to pin the object '%s': %s", ++ file_name, err_str); + } + + out_free: +- free(file); ++ free(temp_name); + return err; + } + +@@ -289,7 +361,7 @@ int do_pin_fd(int fd, const char *name) + { + int err; + +- err = mount_bpffs_for_pin(name, false); ++ err = mount_bpffs_for_file(name); + if (err) + return err; + +diff --git a/src/iter.c b/src/iter.c +index 6b0e5202..5c39c2ed 100644 +--- a/src/iter.c ++++ b/src/iter.c +@@ -76,7 +76,7 @@ static int do_pin(int argc, char **argv) + goto close_obj; + } + +- err = mount_bpffs_for_pin(path, false); ++ err = mount_bpffs_for_file(path); + if (err) + goto close_link; + +diff --git a/src/main.h b/src/main.h +index b8bb08d1..9eb764fe 100644 +--- a/src/main.h ++++ b/src/main.h +@@ -142,7 +142,8 @@ const char *get_fd_type_name(enum bpf_obj_type type); + char *get_fdinfo(int fd, const char *key); + int open_obj_pinned(const char *path, bool quiet); + int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type); +-int mount_bpffs_for_pin(const char *name, bool is_dir); ++int mount_bpffs_for_file(const char *file_name); ++int create_and_mount_bpffs_dir(const char *dir_name); + int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(int *, char ***)); + int do_pin_fd(int fd, const char *name); + +diff --git a/src/prog.c b/src/prog.c +index 9cb42a33..4c4cf16a 100644 +--- a/src/prog.c ++++ b/src/prog.c +@@ -1778,7 +1778,10 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) + goto err_close_obj; + } + +- err = mount_bpffs_for_pin(pinfile, !first_prog_only); ++ if (first_prog_only) ++ err = mount_bpffs_for_file(pinfile); ++ else ++ err = create_and_mount_bpffs_dir(pinfile); + if (err) + goto err_close_obj; + +diff --git a/src/struct_ops.c b/src/struct_ops.c +index d573f264..aa43dead 100644 +--- a/src/struct_ops.c ++++ b/src/struct_ops.c +@@ -515,7 +515,7 @@ static int do_register(int argc, char **argv) + if (argc == 1) + linkdir = GET_ARG(); + +- if (linkdir && mount_bpffs_for_pin(linkdir, true)) { ++ if (linkdir && create_and_mount_bpffs_dir(linkdir)) { + p_err("can't mount bpffs for pinning"); + return -1; + } diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch new file mode 100644 index 0000000000..2eb6e72d02 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-002-set-DESTDIR-to-empty-when-building-libbpf.patch @@ -0,0 +1,38 @@ +From 06c61eccd3b8a6ff3df3e451a2a93058913124fc Mon Sep 17 00:00:00 2001 +From: jinzhiguang +Date: Sun, 7 Apr 2024 16:54:33 +0800 +Subject: [PATCH] mirror: Set DESTDIR to empty when building libbpf + +If a value is assigned to the variable DESTDIR when compiling bpftool, +this variable will be passed to libbpf's Makefile. + +In this case, libbpf's header files will be installed in an unexpected +directory, causing bpftool to be unable to find the header files. + +Signed-off-by: jinzhiguang +--- + src/Makefile | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/Makefile b/src/Makefile +index a3bc6a0..d48d22f 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -42,7 +42,7 @@ $(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DI + + $(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_OUTPUT) + $(Q)$(MAKE) -C $(BPF_DIR) OBJDIR=$(patsubst %/,%,$(LIBBPF_OUTPUT)) \ +- PREFIX=$(LIBBPF_DESTDIR:/=) $(LIBBPF) install_headers ++ DESTDIR="" PREFIX=$(LIBBPF_DESTDIR:/=) $(LIBBPF) install_headers + + $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_DIR) + $(call QUIET_INSTALL, $@) +@@ -50,7 +50,7 @@ $(LIBBPF_INTERNAL_HDRS): $(LIBBPF_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_HDRS_ + + $(LIBBPF_BOOTSTRAP): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_BOOTSTRAP_OUTPUT) + $(Q)$(MAKE) -C $(BPF_DIR) OBJDIR=$(patsubst %/,%,$(LIBBPF_BOOTSTRAP_OUTPUT)) \ +- PREFIX=$(LIBBPF_BOOTSTRAP_DESTDIR:/=) \ ++ DESTDIR="" PREFIX=$(LIBBPF_BOOTSTRAP_DESTDIR:/=) \ + ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" $@ install_headers + + $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR) diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-003-fix-typo-in-usage-help.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-003-fix-typo-in-usage-help.patch new file mode 100644 index 0000000000..fc488aca5b --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-003-fix-typo-in-usage-help.patch @@ -0,0 +1,30 @@ +From a44a93bb7ed0d8e62220b534df92ea2a678fb4b7 Mon Sep 17 00:00:00 2001 +From: Donald Hunter +Date: Wed, 17 Jul 2024 14:45:08 +0100 +Subject: [PATCH] bpftool: Fix typo in usage help + +The usage help for "bpftool prog help" contains a ° instead of the _ +symbol for cgroup/sendmsg_unix. Fix the typo. + +Fixes: 8b3cba987e6d ("bpftool: Add support for cgroup unix socket address hooks") +Signed-off-by: Donald Hunter +Signed-off-by: Daniel Borkmann +Acked-by: Quentin Monnet +Link: https://lore.kernel.org/bpf/20240717134508.77488-1-donald.hunter@gmail.com +--- + src/prog.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/prog.c b/src/prog.c +index 40ea743..2ff949e 100644 +--- a/src/prog.c ++++ b/src/prog.c +@@ -2489,7 +2489,7 @@ static int do_help(int argc, char **argv) + " cgroup/connect_unix | cgroup/getpeername4 | cgroup/getpeername6 |\n" + " cgroup/getpeername_unix | cgroup/getsockname4 | cgroup/getsockname6 |\n" + " cgroup/getsockname_unix | cgroup/sendmsg4 | cgroup/sendmsg6 |\n" +- " cgroup/sendmsg°unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n" ++ " cgroup/sendmsg_unix | cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/recvmsg_unix |\n" + " cgroup/getsockopt | cgroup/setsockopt | cgroup/sock_release |\n" + " struct_ops | fentry | fexit | freplace | sk_lookup }\n" + " ATTACH_TYPE := { sk_msg_verdict | sk_skb_verdict | sk_skb_stream_verdict |\n" diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-004-fix-the-wrong-format-specifier.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-004-fix-the-wrong-format-specifier.patch new file mode 100644 index 0000000000..19dfa0c007 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-004-fix-the-wrong-format-specifier.patch @@ -0,0 +1,38 @@ +From cb035aad23cf92254d8d3c7631e5b642e6805bd1 Mon Sep 17 00:00:00 2001 +From: Zhu Jun +Date: Wed, 24 Jul 2024 04:11:20 -0700 +Subject: [PATCH] tools/bpf: Fix the wrong format specifier + +The format specifier of "unsigned int" in printf() should be "%u", not +"%d". + +Signed-off-by: Zhu Jun +Signed-off-by: Andrii Nakryiko +Acked-by: Quentin Monnet +Link: https://lore.kernel.org/bpf/20240724111120.11625-1-zhujun2@cmss.chinamobile.com +--- + src/xlated_dumper.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/xlated_dumper.c b/src/xlated_dumper.c +index 567f56d..d009434 100644 +--- a/src/xlated_dumper.c ++++ b/src/xlated_dumper.c +@@ -349,7 +349,7 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len, + + double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW); + +- printf("% 4d: ", i); ++ printf("%4u: ", i); + print_bpf_insn(&cbs, insn + i, true); + + if (opcodes) { +@@ -415,7 +415,7 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, + } + } + +- printf("%d: ", insn_off); ++ printf("%u: ", insn_off); + print_bpf_insn(&cbs, cur, true); + + if (opcodes) { diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch new file mode 100644 index 0000000000..90c3499ec0 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-005-fix-undefined-behavior-caused-by-shifting-into-the-sign-bit.patch @@ -0,0 +1,47 @@ +From a0f887bbdc525006f7662f4a83e240f2c46d3418 Mon Sep 17 00:00:00 2001 +From: Kuan-Wei Chiu +Date: Sun, 8 Sep 2024 22:00:09 +0800 +Subject: [PATCH] bpftool: Fix undefined behavior caused by shifting into the sign bit + +Replace shifts of '1' with '1U' in bitwise operations within +__show_dev_tc_bpf() to prevent undefined behavior caused by shifting +into the sign bit of a signed integer. By using '1U', the operations +are explicitly performed on unsigned integers, avoiding potential +integer overflow or sign-related issues. + +Signed-off-by: Kuan-Wei Chiu +Signed-off-by: Andrii Nakryiko +Acked-by: Quentin Monnet +Link: https://lore.kernel.org/bpf/20240908140009.3149781-1-visitorckw@gmail.com +--- + src/net.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/net.c b/src/net.c +index 2a51f1c..3c50fc6 100644 +--- a/src/net.c ++++ b/src/net.c +@@ -486,9 +486,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev, + if (prog_flags[i] || json_output) { + NET_START_ARRAY("prog_flags", "%s "); + for (j = 0; prog_flags[i] && j < 32; j++) { +- if (!(prog_flags[i] & (1 << j))) ++ if (!(prog_flags[i] & (1U << j))) + continue; +- NET_DUMP_UINT_ONLY(1 << j); ++ NET_DUMP_UINT_ONLY(1U << j); + } + NET_END_ARRAY(""); + } +@@ -497,9 +497,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev, + if (link_flags[i] || json_output) { + NET_START_ARRAY("link_flags", "%s "); + for (j = 0; link_flags[i] && j < 32; j++) { +- if (!(link_flags[i] & (1 << j))) ++ if (!(link_flags[i] & (1U << j))) + continue; +- NET_DUMP_UINT_ONLY(1 << j); ++ NET_DUMP_UINT_ONLY(1U << j); + } + NET_END_ARRAY(""); + } diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-006-fix-undefined-behavior-in-qsort.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-006-fix-undefined-behavior-in-qsort.patch new file mode 100644 index 0000000000..466258112b --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-006-fix-undefined-behavior-in-qsort.patch @@ -0,0 +1,49 @@ +From 37e304df400c69347189449b38864705cc88b987 Mon Sep 17 00:00:00 2001 +From: Kuan-Wei Chiu +Date: Tue, 10 Sep 2024 23:02:07 +0800 +Subject: [PATCH] bpftool: Fix undefined behavior in qsort(NULL, 0, ...) + +When netfilter has no entry to display, qsort is called with +qsort(NULL, 0, ...). This results in undefined behavior, as UBSan +reports: + +net.c:827:2: runtime error: null pointer passed as argument 1, which is declared to never be null + +Although the C standard does not explicitly state whether calling qsort +with a NULL pointer when the size is 0 constitutes undefined behavior, +Section 7.1.4 of the C standard (Use of library functions) mentions: + +"Each of the following statements applies unless explicitly stated +otherwise in the detailed descriptions that follow: If an argument to a +function has an invalid value (such as a value outside the domain of +the function, or a pointer outside the address space of the program, or +a null pointer, or a pointer to non-modifiable storage when the +corresponding parameter is not const-qualified) or a type (after +promotion) not expected by a function with variable number of +arguments, the behavior is undefined." + +To avoid this, add an early return when nf_link_info is NULL to prevent +calling qsort with a NULL pointer. + +Signed-off-by: Kuan-Wei Chiu +Signed-off-by: Andrii Nakryiko +Reviewed-by: Quentin Monnet +Link: https://lore.kernel.org/bpf/20240910150207.3179306-1-visitorckw@gmail.com +--- + src/net.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/src/net.c b/src/net.c +index 3c50fc6..d2242d9 100644 +--- a/src/net.c ++++ b/src/net.c +@@ -880,6 +880,9 @@ static void show_link_netfilter(void) + nf_link_count++; + } + ++ if (!nf_link_info) ++ return; ++ + qsort(nf_link_info, nf_link_count, sizeof(*nf_link_info), netfilter_link_compar); + + for (id = 0; id < nf_link_count; id++) { diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch new file mode 100644 index 0000000000..c88cbdf367 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-007-define-PACKAGE-at-build-time-when-trying-to-detect-libbfd.patch @@ -0,0 +1,48 @@ +From bf9e0609acb97d73a7ebf3e8910b0119cd943dfb Mon Sep 17 00:00:00 2001 +From: Quentin Monnet +Date: Mon, 14 Oct 2024 17:43:25 +0100 +Subject: [PATCH] mirror: Define PACKAGE at build time when trying to detect libbfd + +Feature detection from the Makefile.feature for libbfd (with the +different variants of the probe) may fail on some systems where the +bfd.h and dis-asm.h headers expect the PACKAGE or PACKAGE_VERSION macros +to be defined [0]. In the kernel tree, feature detection addresses it by +defining the PACKAGE macro when invoking the compiler [1]. Add a similar +definition for the mirror repository. + +Note that this issue has remained undetected for a while. This is +because the bfd.h included in some distributions (Debian/Ubuntu, for +example) does not contain the inclusion guard [2]. + +[0] https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/bfd-in.h;h=04e65aad5f0c235a5013513c545e57a01e96541f;hb=binutils-2_43_1#l27 +[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/build/feature/Makefile?h=v6.11#n114 +[2] https://git.launchpad.net/ubuntu/+source/binutils/tree/debian/rules?h=applied/2.43.1-5#n1031 + +Reported-by: Holger Hoffstätte +Signed-off-by: Quentin Monnet +--- + src/Makefile.feature | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/Makefile.feature b/src/Makefile.feature +index 131c67e..90f9e7c 100644 +--- a/src/Makefile.feature ++++ b/src/Makefile.feature +@@ -45,7 +45,7 @@ LIBBFD_PROBE += ' bfd_demangle(0, 0, 0);' + LIBBFD_PROBE += ' return 0;' + LIBBFD_PROBE += '}' + LIBBFD_PROBE_CMD = printf '%b\n' $(LIBBFD_PROBE) | \ +- $(CC) $(CFLAGS) -Wall -Werror -x c - $(1) -o /dev/null >/dev/null ++ $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - $(1) -o /dev/null >/dev/null + + define libbfd_build + $(call detect,$(LIBBFD_PROBE_CMD)) +@@ -78,7 +78,7 @@ DISASSEMBLER_PROBE += ' return 0;' + DISASSEMBLER_PROBE += '}' + + DISASSEMBLER_PROBE_CMD = printf '%b\n' $(1) | \ +- $(CC) $(CFLAGS) -Wall -Werror -x c - -lbfd -lopcodes -S -o - >/dev/null ++ $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - -lbfd -lopcodes -S -o - >/dev/null + define disassembler_build + $(call detect,$(DISASSEMBLER_PROBE_CMD)) + endef diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch new file mode 100644 index 0000000000..399b824ce0 --- /dev/null +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/files/7.4-008-always-disable-unused-CLI-arguments-warning-for-feature-probe.patch @@ -0,0 +1,38 @@ +From 3be8ac358900c5f57028b2b6501407a14167a9bb Mon Sep 17 00:00:00 2001 +From: Quentin Monnet +Date: Thu, 17 Oct 2024 11:22:14 +0100 +Subject: [PATCH] mirror: Always disable unused CLI arguments warning for feature probe + +In commit 8a2d7d510ccd ("mirror: Fix features detection for building +with clang") we prevented clang to error out when encountering unused +command-line arguments in the feature probes, because we do add unused +arguments for some of the probes when retrieving arguments from +llvm-config, and we don't want probes to fail because of that. + +At the time, the issue was apparent for the LLVM-based disassembler, so +we added -Wno-unused-command-line-argument when $(LLVM) was enabled, +only. We missed the case when we're building bpftool with clang instead +of gcc, without building the LLVM disassembler. Let's disable the +warning unconditionally instead to fix this case. + +Reported-by: Holger Hoffstätte +Signed-off-by: Quentin Monnet +--- + src/Makefile.feature | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/src/Makefile.feature b/src/Makefile.feature +index 90f9e7c..b08e7b9 100644 +--- a/src/Makefile.feature ++++ b/src/Makefile.feature +@@ -4,9 +4,7 @@ pound := \# + + CFLAGS_BACKUP := $(CFLAGS) + CFLAGS := $(EXTRA_CFLAGS) +-ifneq ($(LLVM),) +- CFLAGS += -Wno-unused-command-line-argument +-endif ++CFLAGS += -Wno-unused-command-line-argument + + ifeq ($(V),1) + LOG=$(warning $(1)) diff --git a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/metadata.xml b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/metadata.xml index a09ffc7b94..1e8c354ad0 100644 --- a/sdk_container/src/third_party/portage-stable/dev-util/bpftool/metadata.xml +++ b/sdk_container/src/third_party/portage-stable/dev-util/bpftool/metadata.xml @@ -13,4 +13,7 @@ Use sys-libs/libcap to enable unprivileged run support Use sys-devel/llvm instead of libbfd (sys-libs/binutils-libs) for JIT disassembly + + libbpf/bpftool +