AFL icon indicating copy to clipboard operation
AFL copied to clipboard

Issue #110 - Fix afl-clang-fast -E and -shared regressions.

Open choller opened this issue 4 years ago • 18 comments

choller avatar Aug 04 '20 12:08 choller

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

googlebot avatar Aug 04 '20 12:08 googlebot

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] avatar Aug 04 '20 12:08 google-cla[bot]

CLA is signed by Mozilla.

choller avatar Aug 04 '20 12:08 choller

@Dor1s Hello I haven't heard of a Mozilla/Google github group for this. However, we have corporate agreement between our companies.

sylvestre avatar Aug 04 '20 20:08 sylvestre

@sylvestre Hello! Yeah, I'm able to see Mozilla among the corporate signers, and in the worst case can just ignore the CLA check here.

However, there is definitely a way to make the check pass. It might be nice to achieve that to avoid any confusion with future: https://cla.developers.google.com/about#add-contributors

As I understand, there must be some Google Group that was submitted with the corporate CLA.

Dor1s avatar Aug 04 '20 20:08 Dor1s

Sure, I will see on our side what we can do to do the right thing :) thanks for the quick answer and pointer!

sylvestre avatar Aug 04 '20 21:08 sylvestre

thank you @sylvestre !

and in the meantime we're waiting for @@andreafioraldi to take a look

Dor1s avatar Aug 04 '20 21:08 Dor1s

LGTM, I will test it tomorrow morning (I'm in EU) but it should be ok, it doesn't revert my patch. Btw my use case is openssl on Fuzzbench, so if you want to test it now in order to merge ASAP just try to compile it using afl-clang-fast.

andreafioraldi avatar Aug 04 '20 22:08 andreafioraldi

-shared reintroduces the https://github.com/google/fuzzbench/issues/110 bug. IMO -E is really needed, and fix the @choller compilation failures, -shared instead breaks the linking with errors about undefined references to afl-llvm-rt.

It is true that if we compile afl-llvm-rt into all the shared objects they will have duplicated code, however that code will be not used. In classic mode, __afl_area_ptr is loaded from the .got section and so the loader will resolve the reference to a single shared object. Same for pcguard mode, __sanitizer_cov_trace_pc_guard and __sanitizer_cov_trace_pc_guard_init are compiled into each shared objects, but only one from the first shared object is resolved by the loader so there are no conflicts.

We should keep the -E case and drop -shared.

andreafioraldi avatar Aug 05 '20 08:08 andreafioraldi

-shared reintroduces the google/fuzzbench#110 bug. IMO -E is really needed, and fix the @choller compilation failures, -shared instead breaks the linking with errors about undefined references to afl-llvm-rt.

This indicates that the project is linking an executable without attaching the runtime, and I would consider that a bug. It would mean that the runtime is only present because a shared object with the runtime is loaded into the executable and that needs fixing.

It is true that if we compile afl-llvm-rt into all the shared objects they will have duplicated code, however that code will be not used. In classic mode, __afl_area_ptr is loaded from the .got section and so the loader will resolve the reference to a single shared object.

I'm not talking about multiple shared objects, but shared object vs. the binary loading it. If both have the runtime, then I think there is no way for the loader to resolve this properly.

I also just looked up why this was added initially:

+--------------
+Version 2.06b:
+--------------
+
+  - Worked around LLVM persistent mode hiccups with -shared code.
+    Contributed by Christian Holler.

So this was causing real malfunctions with persistent mode.

I also think it's not useful to argue that this breaks one project in fuzzbench, because the change you introduced broke another project even before. I think we should stick to the way sanitizers solve this, because they face similar problems with runtime duplication (attaching for example the ASan runtime to shared objects will crash your process).

choller avatar Aug 05 '20 09:08 choller

I think an intermediate solution would be to add an environment variable that allows overriding this behavior. Something like AFL_ATTACH_RT_SHARED to force attaching the runtime even to shared objects. It should be clearly documented though that this can have severe side effects and might indicate a problem in the build system.

choller avatar Aug 05 '20 09:08 choller

+1 for AFL_ATTACH_RT_SHARED

andreafioraldi avatar Aug 05 '20 09:08 andreafioraldi

+1 for AFL_ATTACH_RT_SHARED

Great, I'll change the PR accordingly. We should still investigate long-term why the OpenSSL build fails in this way, because that might be a bug.

choller avatar Aug 05 '20 09:08 choller

@andreafioraldi suggested to use -Wl,--dynamic-list to make sure the AFL symbols are always exported from the main binary. According to both of our tests, this seems to solve the problems with shared libraries (which only occurs btw when the library is loaded with dlopen()).

choller avatar Aug 05 '20 18:08 choller

I forgot to put sancov in the list when I wrote it on Discord, push this updated list:

{
  "__afl_area_ptr";
  "__afl_manual_init";
  "__afl_persistent_loop";
  "__afl_auto_init";
  "__afl_area_initial";
  "__afl_prev_loc";
  "__sanitizer_cov_trace_pc_guard";
  "__sanitizer_cov_trace_pc_guard_init";
};

andreafioraldi avatar Aug 05 '20 18:08 andreafioraldi

Thanks @choller and @andreafioraldi for updating the PR! LGTM.

@sylvestre, let us know if there's any update re the CLA, thanks!

lszekeres avatar Aug 08 '20 23:08 lszekeres

The CLA check here should be fixed.

choller avatar Nov 11 '21 13:11 choller

@googlebot ping

Dor1s avatar Nov 11 '21 18:11 Dor1s