alfred: Drop capabilities when not needed
PATCH 1/1 alfred: Drop capabilities when not needed
The alfred process only requires the capability to bind to a raw socket (CAP_NET_RAW). It is enough to mark this capability as permitted on program startup and mark it again as effective whenever a new netsock is initialized. All other capabilities can be dropped completely.
--- Makefile | 24 ++++++++++++++++++ main.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- netsock.c | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-)
Makefile +24 -0
@@ -27,6 +27,9 @@ MANPAGE = man/alfred.8 CFLAGS += -pedantic -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP LDLIBS += -lrt +# B.A.T.M.A.N. debugging: +export CONFIG_ALFRED_CAPABILITIES=y + # disable verbose output ifneq ($(findstring $(MAKEFLAGS),s),s) ifndef V
@@ -70,6 +73,27 @@ ifneq ($(CONFIG_ALFRED_GPSD),n) GPSD_INSTALL=gpsd-install endif +ifneq ($(CONFIG_ALFRED_CAPABILITIES),n) + ifeq ($(origin PKG_CONFIG), undefined) + PKG_CONFIG = pkg-config + ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),) + $(error $(PKG_CONFIG) not found) + endif + endif + + ifeq ($(origin LIBCAP_CFLAGS) $(origin LIBCAP_LDLIBS), undefined undefined) + LIBCAP_NAME ?= libcap + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBCAP_NAME) 2>/dev/null),) + $(error No $(LIBCAP_NAME) development libraries found!) + endif + LIBCAP_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBCAP_NAME)) + LIBCAP_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBCAP_NAME)) + endif + CFLAGS += $(LIBCAP_CFLAGS) + CPPFLAGS += -DCONFIG_ALFRED_CAPABILITIES + LDLIBS += $(LIBCAP_LDLIBS) +endif + # default target all: $(BINARY_NAME) $(VIS_ALL) $(GPSD_ALL)
main.c +83 -1
104 lines not on this page · raw message
netsock.c +44 -0
67 lines not on this page · raw message
Signature · 1 line
2.1.4
Hi!
Thanks for the patch. Setup seems to be still working. How can I verify that privileges really dropped?
There are further questions:
Is _read_ access for the alfred user (resp. group) sufficient in /sys/kernel/debug/batman_adv/* ?
Or is write access on the socket file in this directory mandatory for full functionality?
Thanks
Martin
Quoted 11 lines · On Saturday 28 February 2015 21:04:19 MK wrote:
Hi!
Thanks for the patch. Setup seems to be still working. How can I verify that privileges really dropped?
There are further questions:
Is _read_ access for the alfred user (resp. group) sufficient in
/sys/kernel/debug/batman_adv/*?
Or is write access on the socket file in this directory mandatory for full functionality?
Read functionality should be enough. We are only reading the originator table and (global) translation table.
Cheers,
Simon
Hi,
Please Cc me when you want an answer from me (I am not subscribed to this mailing list). I just found this mail by pure luck.
Quoted 2 lines · On Saturday 28 February 2015 21:04:19 MK wrote:
Thanks for the patch. Setup seems to be still working. How can I verify that privileges really dropped?
The privileges of a process can be found in
$ cat /proc/`pidof alfred`/status
The active capabilities are CapEff. The capabilities the process can request can be found in CapPrm.
Quoted 6 lines
There are further questions:
Is _read_ access for the alfred user (resp. group) sufficient in
/sys/kernel/debug/batman_adv/*?
Or is write access on the socket file in this directory mandatory for full functionality?
The process needs to access the path and read the files. For example my system allows read of this files by default BUT disallows non-root access to /sys/kernel/debug
$ ls -ltrd /sys/kernel/debug drwx------ 27 root root 0 Mar 2 18:58 /sys/kernel/debug
I would have to allow other users o+rx access to this path before being able to access the batman-adv files:
$ cat /sys/kernel/debug/batman_adv/bat0/originators cat: /sys/kernel/debug/batman_adv/bat0/originators: Permission denied $ sudo chmod o+rx /sys/kernel/debug $ cat /sys/kernel/debug/batman_adv/bat0/originators [B.A.T.M.A.N. adv 2014.3.0, MainIF/MAC: eth0/XX:XX:XX:XX:XX:XX (bat0 BATMAN_IV)] Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ... No batman nodes in range ...
!!!! WARNING !!!!
I don't recommend to grant all users access to /sys/kernel/debug.
Kind regards,
Sven
Simon Wunderlich
AppliedQuoted 6 lines · On Monday 23 February 2015 20:18:50 Sven Eckelmann wrote:
The alfred process only requires the capability to bind to a raw socket (
CAP_NET_RAW). It is enough to mark this capability as permitted on program startup and mark it again as effective whenever a new netsock is initialized. All other capabilities can be dropped completely.Signed-off-by Sven Eckelmann <[email protected]>
Applied in revision b0877b3 (just replaced that "B.A.T.M.A.N. debugging comment).
Thanks!
Simon