Exemplo n.º 1
0
#include "cheritest.h"

/*
 * XXXRW: Where are these initialised?
 */
int zero_fd = -1;
struct sandbox_object *sbop_stdin, *sbop_stdout, *sbop_zero;

static char read_string[128];

void
test_sandbox_fd_fstat(const struct cheri_test *ctp __unused)
{
	register_t v;

	v = invoke_fd_fstat_c(sandbox_object_getobject(sbop_zero));
	if (v != 0)
		cheritest_failure_errx("invoke returned %ld (expected 0)", v);
	cheritest_success();
}

void
test_sandbox_fd_lseek(const struct cheri_test *ctp __unused)
{
	register_t v;

	v = invoke_fd_lseek_c(sandbox_object_getobject(sbop_zero));
	if (v != 0)
		cheritest_failure_errx("invoke returned %ld (expected 0)", v);
	cheritest_success();
}
Exemplo n.º 2
0
/*
 * Sample sandboxed code.  Calculate an MD5 checksum of the data arriving via
 * c3, and place the checksum in c4.  a0 will hold input data length.  a1
 * indicates whether we should try a system call (abort()).  c4 must be (at
 * least) 33 bytes.
 */
int
invoke(register_t op, size_t len, struct cheri_object system_object,
    __capability char *data_input, __capability char *data_output,
    struct cheri_object fd_object)
{
	int i = 0;
	volatile int *ip = &i;

	cheri_system_setup(system_object);

	switch (op) {
	case CHERITEST_HELPER_OP_MD5:
		return (invoke_md5(len, data_input, data_output));

	case CHERITEST_HELPER_OP_ABORT:
		abort();

	case CHERITEST_HELPER_OP_SPIN:
		while (1);

	case CHERITEST_HELPER_OP_CP2_BOUND:
	case CHERITEST_HELPER_OP_CP2_PERM:
	case CHERITEST_HELPER_OP_CP2_TAG:
	case CHERITEST_HELPER_OP_CP2_SEAL:
		return (invoke_cap_fault(op));

	case CHERITEST_HELPER_OP_VM_RFAULT:
	case CHERITEST_HELPER_OP_VM_WFAULT:
	case CHERITEST_HELPER_OP_VM_XFAULT:
		return (invoke_vm_fault(op));

	case CHERITEST_HELPER_OP_SYSCALL:
		return (invoke_syscall());

	case CHERITEST_HELPER_OP_DIVZERO:
		return (1/(*ip));

	case CHERITEST_HELPER_OP_SYSCAP:
		return (invoke_syscap(system_object));

	case CHERITEST_HELPER_OP_CS_HELLOWORLD:
		return (cheri_system_helloworld());

	case CHERITEST_HELPER_OP_CS_PUTS:
		return (cheri_system_puts(
		    (__capability char *)"sandbox cs_puts\n"));

	case CHERITEST_HELPER_OP_CS_PUTCHAR:
		return (cheri_system_putchar('C'));	/* Is for cookie. */

	case CHERITEST_HELPER_OP_PRINTF:
		return (printf("%s: printf in sandbox test\n", __func__));

	case CHERITEST_HELPER_OP_MALLOC:
		return (invoke_malloc());

	case CHERITEST_HELPER_OP_FD_FSTAT_C:
		return (invoke_fd_fstat_c(fd_object));

	case CHERITEST_HELPER_OP_FD_LSEEK_C:
		return (invoke_fd_lseek_c(fd_object));

	case CHERITEST_HELPER_OP_FD_READ_C:
		return (invoke_fd_read_c(fd_object));

	case CHERITEST_HELPER_OP_FD_WRITE_C:
		return (invoke_fd_write_c(fd_object));

	}
	return (-1);
}