PERFORCE change 174203 for review
Robert Watson
rwatson at FreeBSD.org
Wed Feb 3 00:54:05 UTC 2010
http://p4web.freebsd.org/chv.cgi?CH=174203
Change 174203 by rwatson at rwatson_vimage_client on 2010/02/03 00:53:49
First cut at a sandbox create/rpc/destroy benchmark, which appears
not to work.
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/Makefile#3 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#5 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/Makefile#3 (text+ko) ====
@@ -3,7 +3,8 @@
#
PROG= syscall_timing
-CFLAGS+= -static -O -Wall
+CFLAGS+= -static -O -Wall -rdynamic
NO_MAN=
+LDADD= -lcapsicum -lsbuf
.include <bsd.prog.mk>
==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#5 (text+ko) ====
@@ -38,8 +38,10 @@
#include <assert.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <libcapsicum.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -427,6 +429,100 @@
benchmark_stop();
}
+#define MYNAME "./syscall_timing" /* Binary to run in sandbox. */
+
+/*
+ * Unsandboxed host process with full user rights.
+ */
+void
+test_sandbox(int num)
+{
+ struct lc_sandbox *lcsp;
+ char *sandbox_argv[2] = { MYNAME, NULL };
+ struct iovec iov;
+ size_t len;
+ char ch;
+ int i;
+
+ if (lch_start(MYNAME, sandbox_argv, LCH_PERMIT_STDERR |
+ LCH_PERMIT_STDOUT, NULL, &lcsp) < 0)
+ err(-1, "lch_start %s", MYNAME);
+ ch = 'X';
+ iov.iov_base = &ch;
+ iov.iov_len = sizeof(ch);
+ printf("lch_rpc\n");
+ if (lch_rpc(lcsp, 0, &iov, 1, &iov, 1, &len) < 0)
+ err(-1, "lch_rpc");
+ if (len != sizeof(ch))
+ errx(-1, "lch_rpc returned size %zd not %zd", len, sizeof(ch));
+ if (ch != 'X')
+ errx(-1, "lch_recv: expected %d and got %d", 'X', ch);
+ lch_stop(lcsp);
+
+ benchmark_start();
+ for (i = 0; i < num; i++) {
+ if (lch_start(MYNAME, sandbox_argv, LCH_PERMIT_STDERR |
+ LCH_PERMIT_STDOUT, NULL, &lcsp) < 0)
+ err(-1, "lch_start %s", MYNAME);
+ ch = 'X';
+ iov.iov_base = &ch;
+ iov.iov_len = sizeof(ch);
+ if (lch_rpc(lcsp, 0, &iov, 1, &iov, 1, &len) < 0)
+ err(-1, "lch_rpc");
+ if (len != sizeof(ch))
+ errx(-1, "lch_rpc returned size %zd not %zd", len,
+ sizeof(ch));
+ if (ch != 'X')
+ errx(-1, "lch_recv: expected %d and got %d", 'X', ch);
+ lch_stop(lcsp);
+ }
+ benchmark_stop();
+}
+
+int
+cap_main(int argc, char *argv[])
+{
+ struct lc_host *lchp;
+ u_int32_t opno, seqno;
+ struct iovec iov;
+ u_char *buffer;
+ size_t len;
+
+ if (lcs_get(&lchp) < 0)
+ err(-1, "lcs_get");
+
+ /*
+ * Serve RPCs from the host until the sandbox is killed.
+ */
+ while (1) {
+ /*
+ * Receive a one-byte RPC from the host.
+ */
+ if (lcs_recvrpc(lchp, &opno, &seqno, &buffer, &len) < 0) {
+ if (errno != EPIPE)
+ err(-6, "lcs_recvrpc");
+ else
+ exit(-6);
+ }
+ if (len != 1)
+ errx(-7, "lcs_recvrpc len");
+
+ /*
+ * Reply with the same message. Remember to free the message
+ * when done.
+ */
+ iov.iov_base = buffer;
+ iov.iov_len = 1;
+ if (lcs_sendrpc(lchp, opno, seqno, &iov, 1) < 0) {
+ if (errno != EPIPE)
+ err(-8, "lcs_sendrpc");
+ else
+ exit(-8);
+ }
+ free(buffer);
+ }
+}
+
struct test {
const char *t_name;
void (*t_func)(int);
@@ -450,6 +546,7 @@
{ "cap_enter", test_cap_enter },
{ "fork", test_fork },
{ "pdfork", test_pdfork },
+ { "sandbox", test_sandbox },
};
static const int tests_count = sizeof(tests) / sizeof(tests[0]);
More information about the p4-projects
mailing list