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

Always allow linking AFL-instrumented modules #10107

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -269,6 +269,10 @@ OCaml 4.12.0
- #10062: set ARCH_INT64_PRINTF_FORMAT correctly for both modes of mingw-w64
(David Allsopp, review by Xavier Leroy)

- #10107: Ensure modules compiled with -afl-instrument can still link on
platforms without AFL support.
(David Allsopp, review by ???)

### Code generation and optimizations:

- #9551: ocamlc no longer loads DLLs at link time to check that
Expand Down
16 changes: 11 additions & 5 deletions runtime/afl.c
Expand Up @@ -15,6 +15,11 @@
/* Runtime support for afl-fuzz */
#include "caml/config.h"

/* Values used by the instrumentation logic (see cmmgen.ml) */
static unsigned char afl_area_initial[1 << 16];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, every OCaml program is 64 Kbytes bigger, just in case AFL is applied to it?

I know this is orthogonal to the issue at hand, but I'd really like to see on-demand allocation here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it wasn't just me bothered by this! I'll open an issue to track it...

unsigned char* caml_afl_area_ptr = afl_area_initial;
uintnat caml_afl_prev_loc;

#if !defined(HAS_SYS_SHM_H) || !defined(HAS_SHMAT)

#include "caml/mlvalues.h"
Expand All @@ -24,6 +29,12 @@ CAMLprim value caml_reset_afl_instrumentation(value full)
return Val_unit;
}

CAMLexport value caml_setup_afl(value unit)
{
/* AFL is not supported */
return Val_unit;
}

#else

#include <unistd.h>
Expand All @@ -45,11 +56,6 @@ static int afl_initialised = 0;
to count a testcase as "crashing" */
extern int caml_abort_on_uncaught_exn;

/* Values used by the instrumentation logic (see cmmgen.ml) */
static unsigned char afl_area_initial[1 << 16];
unsigned char* caml_afl_area_ptr = afl_area_initial;
uintnat caml_afl_prev_loc;

/* File descriptors used to synchronise with afl-fuzz */
#define FORKSRV_FD_READ 198
#define FORKSRV_FD_WRITE 199
Expand Down