Skip to content

Commit b856b51

Browse files
committed
Merge commit 'd0e943077d94e6266ece9856789c5d5313676e38'
2 parents 8d5719a + d0e9430 commit b856b51

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

contrib/capsicum-test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object-capabilities. The tests exercise the syscall interface to a Capsicum-enab
55
currently either [FreeBSD >=10.x](http://www.freebsd.org) or a modified Linux kernel (the
66
[capsicum-linux](http://github.com/google/capsicum-linux) project).
77

8-
The tests are written in C++98, and use the [Google Test](https://code.google.com/p/googletest/)
8+
The tests are written in C++11 and use the [Google Test](https://code.google.com/p/googletest/)
99
framework, with some additions to fork off particular tests (because a process that enters capability
1010
mode cannot leave it again).
1111

contrib/capsicum-test/capmode.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// whether or not they return the expected ECAPMODE.
44
#include <sys/types.h>
55
#include <sys/socket.h>
6+
#ifdef __FreeBSD__
7+
#include <sys/sockio.h>
8+
#endif
69
#include <sys/stat.h>
710
#include <sys/mount.h>
811
#include <sys/mman.h>
@@ -11,6 +14,7 @@
1114
#include <sys/resource.h>
1215
#include <sys/ptrace.h>
1316
#include <dirent.h>
17+
#include <net/if.h>
1418
#include <netinet/in.h>
1519
#include <fcntl.h>
1620
#include <sched.h>
@@ -203,6 +207,39 @@ FORK_TEST_F(WithFiles, AllowedSocketSyscalls) {
203207
if (fd_pair[1] >= 0) close(fd_pair[1]);
204208
}
205209

210+
FORK_TEST_F(WithFiles, AllowedSocketSyscallsIfRoot) {
211+
GTEST_SKIP_IF_NOT_ROOT();
212+
213+
EXPECT_OK(cap_enter()); // Enter capability mode.
214+
215+
// Creation of raw sockets is not permitted in capability mode.
216+
EXPECT_CAPMODE(socket(AF_INET, SOCK_RAW, 0));
217+
EXPECT_CAPMODE(socket(AF_INET, SOCK_RAW, IPPROTO_ICMP));
218+
EXPECT_CAPMODE(socket(AF_INET, SOCK_RAW, IPPROTO_TCP));
219+
EXPECT_CAPMODE(socket(AF_INET, SOCK_RAW, IPPROTO_UDP));
220+
221+
EXPECT_CAPMODE(socket(AF_INET6, SOCK_RAW, IPPROTO_ICMP));
222+
EXPECT_CAPMODE(socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6));
223+
EXPECT_CAPMODE(socket(AF_INET6, SOCK_RAW, IPPROTO_TCP));
224+
EXPECT_CAPMODE(socket(AF_INET6, SOCK_RAW, IPPROTO_UDP));
225+
226+
EXPECT_CAPMODE(socket(AF_ROUTE, SOCK_RAW, 0));
227+
228+
// Interface configuration ioctls are not permitted in capability
229+
// mode.
230+
#ifdef __FreeBSD__
231+
struct if_clonereq req;
232+
233+
req.ifcr_total = 0;
234+
req.ifcr_count = 1;
235+
req.ifcr_buffer = static_cast<char *>(malloc(IFNAMSIZ));
236+
237+
EXPECT_CAPMODE(ioctl(fd_socket_, SIOCIFGCLONERS, &req));
238+
239+
free(req.ifcr_buffer);
240+
#endif
241+
}
242+
206243
#ifdef HAVE_SEND_RECV_MMSG
207244
FORK_TEST(Capmode, AllowedMmsgSendRecv) {
208245
int fd_socket = socket(PF_INET, SOCK_DGRAM, 0);

contrib/capsicum-test/capsicum-test.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ char ProcessState(int pid) {
7676
errno = 0;
7777
struct kinfo_proc *p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &count);
7878
if (p == NULL || count == 0) {
79-
if (verbose) fprintf(stderr, "procstat_getprocs failed with %p/%d: %s\n", p, count, strerror(errno));
79+
if (verbose) {
80+
fprintf(stderr, "procstat_getprocs failed with %p/%d: %s\n", (void *)p,
81+
count, strerror(errno));
82+
}
8083
procstat_close(prstat);
8184
return '\0';
8285
}

0 commit comments

Comments
 (0)