[PATCH] libbpf: don't preserve ownership during install

From: Martin Kaiser

Date: Tue Jul 28 2026 - 03:24:42 EST


When a libbpf build is integrated into build systems like Yocto, the
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