From owner-p4-projects@FreeBSD.ORG Wed Feb 3 00:54:05 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 410FA1065694; Wed, 3 Feb 2010 00:54:05 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E16E7106568B for ; Wed, 3 Feb 2010 00:54:04 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CE57E8FC1C for ; Wed, 3 Feb 2010 00:54:04 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o130s4sv056257 for ; Wed, 3 Feb 2010 00:54:04 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o130s4f5056255 for perforce@freebsd.org; Wed, 3 Feb 2010 00:54:04 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 3 Feb 2010 00:54:04 GMT Message-Id: <201002030054.o130s4f5056255@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 174203 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 00:54:05 -0000 http://p4web.freebsd.org/chv.cgi?CH=174203 Change 174203 by rwatson@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 ==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#5 (text+ko) ==== @@ -38,8 +38,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -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]);