Re: [PATCH] libbpf: don't preserve ownership during install
From: Andrii Nakryiko
Date: Tue Jul 28 2026 - 12:45:14 EST
On Tue, Jul 28, 2026 at 12:15 AM Martin Kaiser <martin@xxxxxxxxx> wrote:
>
> When a libbpf build is integrated into build systems like Yocto, the
Kernel tree libbpf is not meant to be packaged and used directly,
please use libbpf mirror version at [0]. And Github mirror has its own
Makefile, so this fix won't affect that one.
[0] https://github.com/libbpf/libbpf
> source tree might be owned by a non-root developer user.
>
> The install_lib target in libbpf's Makefile uses cp -p to copy libraries
> and preserve ownership. This leaks the UID of the source tree owner into
> the root filesystem where the libraries are installed.
>
> Update the cp command to preserve only mode and timestamps. The copied
> files will then be owned by the installing user.
>
> Suggested-by: Florian Schmaus <flo@xxxxxxxxxxxx>
> Signed-off-by: Martin Kaiser <martin@xxxxxxxxx>
> ---
> tools/lib/bpf/Makefile | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index eca584fb061e..0a344ca4e108 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -231,7 +231,7 @@ endef
> install_lib: all_cmd
> $(call QUIET_INSTALL, $(LIB_TARGET)) \
> $(call do_install_mkdir,$(libdir_SQ)); \
> - cp -fpR $(LIB_FILE) $(DESTDIR)$(libdir_SQ)
> + cp -fR --preserve=mode,timestamps $(LIB_FILE) $(DESTDIR)$(libdir_SQ)
>
> SRC_HDRS := bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h \
> bpf_helpers.h bpf_tracing.h bpf_endian.h bpf_core_read.h \
> --
> 2.43.7
>