* [PATCH] libbpf: don't preserve ownership during install
@ 2026-07-28 7:14 Martin Kaiser
2026-07-28 7:25 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Martin Kaiser @ 2026-07-28 7:14 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
Daniel Borkmann, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis
Cc: Martin Kaiser, Florian Schmaus, bpf, linux-kernel
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@geekplace.eu>
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: don't preserve ownership during install
2026-07-28 7:14 [PATCH] libbpf: don't preserve ownership during install Martin Kaiser
@ 2026-07-28 7:25 ` sashiko-bot
2026-07-28 8:22 ` Martin Kaiser
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-07-28 7:25 UTC (permalink / raw)
To: Martin Kaiser; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The use of the GNU-specific `cp --preserve` extension breaks `make install` on platforms with BSD or BusyBox `cp` implementations (e.g., macOS, FreeBSD, Alpine).
--
--- Patch [1]: [PATCH] libbpf: don't preserve ownership during install ---
commit 20b6f948388a1067581300a57d47fc33d1950c11
Author: Martin Kaiser <martin@kaiser.cx>
libbpf: don't preserve ownership during install
This commit modifies the libbpf install_lib target in the Makefile to
prevent leaking the source tree owner's UID into the root filesystem. It
replaces the cp -p flag with the --preserve=mode,timestamps flag to only
preserve specific file attributes during installation.
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> --- 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)
[Severity: Medium]
Will this break the installation process on platforms that do not use GNU
coreutils?
The --preserve argument is a GNU-specific extension. It appears this might
cause the make install target to fail with an unrecognized option error on
systems relying on BSD or BusyBox implementations of cp, such as macOS,
FreeBSD, or Alpine Linux.
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728071516.2706695-1-martin@kaiser.cx?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libbpf: don't preserve ownership during install
2026-07-28 7:25 ` sashiko-bot
@ 2026-07-28 8:22 ` Martin Kaiser
0 siblings, 0 replies; 3+ messages in thread
From: Martin Kaiser @ 2026-07-28 8:22 UTC (permalink / raw)
To: sashiko-reviews; +Cc: bpf
Thus wrote sashiko-bot@kernel.org (sashiko-bot@kernel.org):
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The use of the GNU-specific `cp --preserve` extension breaks `make install` on platforms with BSD or BusyBox `cp` implementations (e.g., macOS, FreeBSD, Alpine).
> --
> --- Patch [1]: [PATCH] libbpf: don't preserve ownership during install ---
> commit 20b6f948388a1067581300a57d47fc33d1950c11
> Author: Martin Kaiser <martin@kaiser.cx>
> libbpf: don't preserve ownership during install
> This commit modifies the libbpf install_lib target in the Makefile to
> prevent leaking the source tree owner's UID into the root filesystem. It
> replaces the cp -p flag with the --preserve=mode,timestamps flag to only
> preserve specific file attributes during installation.
> > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > --- 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)
> [Severity: Medium]
> Will this break the installation process on platforms that do not use GNU
> coreutils?
> The --preserve argument is a GNU-specific extension. It appears this might
> cause the make install target to fail with an unrecognized option error on
> systems relying on BSD or BusyBox implementations of cp, such as macOS,
> FreeBSD, or Alpine Linux.
commit 1375152bb02a ("tools: lib: thermal: don't preserve owner in install")
makes a similar change for tools/lib/thermal/Makefile.
I'd assume that it's reasonable to require coreutils for kernel compilation.
AFAICS, kernel builds on Alpine linux require the alpine-sdk package which
contains coreutils.
Thanks,
Martin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-28 8:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 7:14 [PATCH] libbpf: don't preserve ownership during install Martin Kaiser
2026-07-28 7:25 ` sashiko-bot
2026-07-28 8:22 ` Martin Kaiser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox