From 72c59165f47190adcea7d5186e683bdc10fb8e60 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Sep 2019 04:20:37 +0200 Subject: [PATCH 1/3] configure.sh: enable building with afl-gcc --- Makefile.common | 2 +- configure.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Makefile.common b/Makefile.common index 5ccc2ea2..9ab48848 100644 --- a/Makefile.common +++ b/Makefile.common @@ -63,7 +63,7 @@ endef # The following variables and recpies apply to building tenders, i.e. # artifacts built to run on the (Solo5 tender's) *host*. # -HOSTCC := $(MAKECONF_CC) +HOSTCC := $(MAKECONF_HOSTCC) HOSTCFLAGS := -Wall -Werror -std=c11 -fstack-protector-strong -O2 -g HOSTCPPFLAGS := -I$(TOPDIR)/include/solo5 HOSTLDFLAGS := diff --git a/configure.sh b/configure.sh index d5afdab0..74e11138 100755 --- a/configure.sh +++ b/configure.sh @@ -116,6 +116,7 @@ EOM # Allow external override of CC. CC=${CC:-cc} LD=${LD:-ld} +HOSTCC=${HOSTCC:-$CC} CC_MACHINE=$(${CC} -dumpmachine) [ $? -ne 0 ] && @@ -292,6 +293,46 @@ case "${CONFIG_HOST}" in ;; esac +while [ $# -ne 0 ] +do + arg="$1" + case "$arg" in + --without-genode) + CONFIG_GENODE= + ;; + --without-hvt) + CONFIG_HVT= + ;; + --without-muen) + CONFIG_MUEN= + ;; + --without-spt) + CONFIG_SPT= + ;; + --without-virtio) + CONFIG_VIRTIO= + ;; + --with-afl-gcc) + # Build tenders with afl-gcc tooling. + HOSTCC=afl-gcc + # TODO before merge detect/check this + ;; + *) + printf '%s\n' 'Accepted flags for configure.sh:' + printf '%s\n' '--without-genode: Build without Genode support' + printf '%s\n' '--without-hvt: Build without HVT support' + printf '%s\n' '--without-muen: Build without Muen-SK support' + printf '%s\n' '--without-spt: Build without SPT (Linux Seccomp) support' + printf '%s\n' '--without-virtio: Build without Virtio support' + printf '%s\n' '--with-afl-gcc: Build tenders with afl-gcc instrumentation' + printf '%s\n' ' (equivalent to HOSTCC=afl-gcc ./configure.sh)' + exit 1 + ;; + esac + # Check next argument: + shift +done + # WARNING: # # The generated Makeconf is dual-use! It is both sourced by GNU make, and by @@ -323,10 +364,12 @@ CONFIG_HOST=${CONFIG_HOST} CONFIG_GUEST_PAGE_SIZE=${CONFIG_GUEST_PAGE_SIZE} MAKECONF_CC=${CC} MAKECONF_LD=${LD} +MAKECONF_HOSTCC=${HOSTCC} CONFIG_SPT_NO_PIE=${CONFIG_SPT_NO_PIE} EOM -echo "${prog_NAME}: Configured for ${CC_MACHINE}." +echo "${prog_NAME}: Configured for ${CC_MACHINE} using ${HOSTCC}." +[ "${CC}" = "${HOSTCC}" ] || printf '(tender) HOSTCC=%s (unikernel) CC=%s\n' "${HOSTCC}" "${CC}" echo -n "${prog_NAME}: Enabled targets:" [ -n "${CONFIG_HVT}" ] && echo -n " hvt" [ -n "${CONFIG_SPT}" ] && echo -n " spt" From 1828a9543261cae57f5829e3a18e3ec537daa557 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Sep 2019 04:27:11 +0200 Subject: [PATCH 2/3] SPT: add --dry-run option useful for fuzzing --- tenders/spt/spt_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tenders/spt/spt_core.c b/tenders/spt/spt_core.c index 60bda05c..7ad1ac3a 100644 --- a/tenders/spt/spt_core.c +++ b/tenders/spt/spt_core.c @@ -58,6 +58,8 @@ extern long __executable_start; static bool use_exec_heap = false; +static bool is_dry_run = false; + struct spt *spt_init(size_t mem_size) { struct spt *spt = malloc(sizeof (struct spt)); @@ -239,6 +241,10 @@ void spt_run(struct spt *spt, uint64_t p_entry) if (rc != 0) errx(1, "seccomp_load() failed: %s", strerror(-rc)); + if (is_dry_run) { + exit(EXIT_SUCCESS); + } + spt_launch(sp, start_fn, spt->mem + SPT_BOOT_INFO_BASE); abort(); /* spt_launch() does not return */ @@ -251,6 +257,9 @@ static int handle_cmdarg(char *cmdarg, struct mft *mft) " recommended as it makes the heap and stack executable."); use_exec_heap = true; return 0; + } else if (!strncmp("--dry-run", cmdarg, 9)) { + is_dry_run = true; + return 0; } return -1; } @@ -297,7 +306,8 @@ static int setup(struct spt *spt, struct mft *mft) static char *usage(void) { - return "--x-exec-heap (make the heap executable)." + return "--dry-run (load and validate, but do not actually execute).\n" + " --x-exec-heap (make the heap executable)." " WARNING: This option is dangerous and not recommended as it" " makes the heap and stack executable."; } From 8c54ca071a0e8b378501a589a33f0697f9ceecb6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 25 Sep 2019 04:27:36 +0200 Subject: [PATCH 3/3] spt arg handling: handle --mem more robustly --- tenders/spt/spt_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tenders/spt/spt_main.c b/tenders/spt/spt_main.c index 60e90025..375d16bf 100644 --- a/tenders/spt/spt_main.c +++ b/tenders/spt/spt_main.c @@ -222,6 +222,7 @@ int main(int argc, char **argv) matched = 1; argc--; argv++; + continue; } if (handle_cmdarg(*argv, mft) == 0) { /* Handled by module, consume and go on to next arg */