Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security: Running dhcpcd as non root ? #87

Open
ebanDev opened this issue Feb 10, 2022 · 7 comments
Open

Security: Running dhcpcd as non root ? #87

ebanDev opened this issue Feb 10, 2022 · 7 comments

Comments

@ebanDev
Copy link

ebanDev commented Feb 10, 2022

Hello,
I'd wondering, is it possible to run dhcpcd as a non-root user by setting the right caps ? This could be interesting in a security perspective... Thanks :)

@rsmarples
Copy link
Member

dhcpcd-9 already supports sandbox techniques for FreeBSD (capsicum), OpenBSD (pledge) and Linux (seccomp).

This means that the root owned process doesn't directly handle any input from anything other than non root owned dhcpcd processes. It also does the bare minimum - ie just carry out a pre-defined action from one of the non root processes.

You're welcome to try and patch the root process not to run as root though if you can set the right caps for it :)

https://github.com/NetworkConfiguration/dhcpcd/blob/master/src/privsep-root.c
https://github.com/NetworkConfiguration/dhcpcd/blob/master/src/privsep-linux.c

@ebanDev
Copy link
Author

ebanDev commented Feb 10, 2022

Thanks for your answer :D I don't code in C, so I'll not be able to patch anything unfortunately 😅

@dkwo
Copy link

dkwo commented Dec 6, 2024

I had a similar thought here #417 using setpriv.
The capabilities net_admin and net_raw seem to be enough for wpa_supplicant.
What about the dhcpcd? Are the required capabilities documented anywhere?
I can of course try and experiment, but I could use some guidance.

@dkwo
Copy link

dkwo commented Dec 6, 2024

As a raw, first experiment, I tried to run the dhcpcd daemon with a runit service that looks like

! [ -d /run/dhcpcd ] && install -m 700 -g _dhcpcd -o _dhcpcd -d /run/dhcpcd
exec setpriv --reuid _dhcpcd --regid _dhcpcd --clear-groups \
  --ambient-caps -all,+net_admin,+net_raw \
  --inh-caps -all,+net_admin,+net_raw \
  --bounding-set -all,+net_admin,+net_raw \
  --no-new-privs -- dhcpcd -B ${OPTS:=-M}

and it works, although it complains about a bunch of things in the logs:

dhcp6_openudp: Permission denied
ps_inet_startcb: dhcp6_open: Permission denied
ps_dropprivs: chroot: /var/db/dhcpcd: Operation not permitted
failed to drop privileges: Operation not permitted

@rsmarples
Copy link
Member

What about the dhcpcd? Are the required capabilities documented anywhere? I can of course try and experiment, but I could use some guidance.

No they are not documented anywhere. Once you have reduced the warnings emitted to zero for all IPv4 and IPv6 operations then I guess everything is covered :)

A quick look through a man page suggests these caps: CAP_BPF, CAP_LEASE (for the pidfile), CAP_NET_ADMIN, CAP_NET_BIND_SERVICE, CAP_NET_BROADCAST, CAP_NET_RAW (might not be needed in dhcpcd-11), CAP_SETGID, CAP_SETUID, CAP_SYS_CHROOT.

It will likely need CAP_SYS_ADMIN, CAP_SYS_RAWIO and CAP_SYS_RESOURCE as well, but that will require some testing.

Good luck!

@dkwo
Copy link

dkwo commented Dec 7, 2024

Thanks for pointing out the list.
If I don't use privsep, then in my tests +net_admin,+net_raw,+net_bind_service are enough to reduce warnings to zero.
Other more complex setups may require +cap_bpf as well.
Are you sure about CAP_NET_BROADCAST? its man page says (Unused).
Most of the rest of those capabilities are probably only needed for privsep to function (e.g it chroots..).

@dkwo
Copy link

dkwo commented Dec 8, 2024

We should be careful with CAP_SETGID, CAP_SETUID, CAP_SYS_CHROOT, CAP_SYS_ADMIN, CAP_SYS_RAWIO as they're considered root-equivalent. While CAP_BPF, CAP_LEASE, CAP_SYS_RESOURCE seem fine, I did not need to include them to reach zero warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants