diff options
author | pjd <pjd@FreeBSD.org> | 2013-07-03 22:16:02 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2013-07-03 22:16:02 +0000 |
commit | 11d993e6946901df0579895d876a7aa1d4cc9b98 (patch) | |
tree | 3ec789661358268e153d7a21311897d9656773e6 /sbin/dhclient | |
parent | d5113e2f2801e517733035a8d22216b334385537 (diff) | |
download | FreeBSD-src-11d993e6946901df0579895d876a7aa1d4cc9b98.zip FreeBSD-src-11d993e6946901df0579895d876a7aa1d4cc9b98.tar.gz |
MFp4 @229482:
- Limit bpf descriptor in unprivileged process to CAP_POLL_EVENT, CAP_READ and
allow for SIOCGIFFLAGS, SIOCGIFMEDIA ioctls.
- While here limit bpf descriptor in privileged process to only CAP_WRITE.
Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/bpf.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 8964279..f435028 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include "dhcpd.h" #include "privsep.h" +#include <sys/capability.h> #include <sys/ioctl.h> #include <sys/uio.h> @@ -159,6 +160,9 @@ if_register_send(struct interface_info *info) if (ioctl(info->wfdesc, BIOCLOCK, NULL) < 0) error("Cannot lock bpf"); + if (cap_rights_limit(info->wfdesc, CAP_WRITE) < 0 && errno != ENOSYS) + error("Can't limit bpf descriptor: %m"); + /* * Use raw socket for unicast send. */ @@ -208,6 +212,7 @@ int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn); void if_register_receive(struct interface_info *info) { + static const unsigned long cmds[2] = { SIOCGIFFLAGS, SIOCGIFMEDIA }; struct bpf_version v; struct bpf_program p; int flag = 1, sz; @@ -258,6 +263,13 @@ if_register_receive(struct interface_info *info) if (ioctl(info->rfdesc, BIOCLOCK, NULL) < 0) error("Cannot lock bpf"); + + if (cap_rights_limit(info->rfdesc, + CAP_IOCTL | CAP_POLL_EVENT | CAP_READ) < 0 && errno != ENOSYS) { + error("Can't limit bpf descriptor: %m"); + } + if (cap_ioctls_limit(info->rfdesc, cmds, 2) < 0 && errno != ENOSYS) + error("Can't limit ioctls for bpf descriptor: %m"); } void |