Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WiP): Afl gcc #417

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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 :=
Expand Down
45 changes: 44 additions & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion tenders/spt/spt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.";
}
Expand Down
1 change: 1 addition & 0 deletions tenders/spt/spt_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down