[PATCH] setpriv: remove dependency on libcap headers

Patrick Steinhardt ps at pks.im
Fri Jul 7 13:40:03 UTC 2017


The setpriv applet is including <sys/capability.h> for the capget(2) and
capset(2) functions. Unfortunately, this header is not provided by
linux-headers, but by libcap instead, which requires users to have them
installed. As these functions are not actually implemented by libcap
itself but instead provided by the libc, no additional linking is
required and as such the depenency went by unnoticed.

To get rid of this requirement, we can instead use a direct syscall.
Taking a look at musl libc's implementation of these funcitions, they
are direct wrappers to `syscall(SYS_capset, ...)` and
`syscall(SYS_capget, ...)`. As such, it is trivial to reimplement them
ourselves via syscall(2).

function                                             old     new   delta
getcaps                                              230     246     +16
setpriv_main                                        1260    1266      +6

Signed-off-by: Patrick Steinhardt <ps at pks.im>
---
 util-linux/setpriv.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c
index 8d9c218a3..123dafb2f 100644
--- a/util-linux/setpriv.c
+++ b/util-linux/setpriv.c
@@ -81,11 +81,16 @@
 
 #if ENABLE_FEATURE_SETPRIV_CAPABILITIES
 #include <linux/capability.h>
-#include <sys/capability.h>
+#include <sys/syscall.h>
 #endif
 #include <sys/prctl.h>
 #include "libbb.h"
 
+#if ENABLE_FEATURE_SETPRIV_CAPABILITIES
+#define capget(header, data) syscall(SYS_capget, (header), (data))
+#define capset(header, data) syscall(SYS_capset, (header), (data))
+#endif
+
 #ifndef PR_CAPBSET_READ
 #define PR_CAPBSET_READ 23
 #endif
-- 
2.13.2



More information about the busybox mailing list