Page MenuHomePhabricator

[asan] Intercept SetUnhandledExceptionFilter.
ClosedPublic

Authored by mpividori on Feb 2 2017, 10:45 AM.

Details

Summary

In this diff I update the code for asan on Windows, so we can intercept SetUnhandledExceptionFilter and catch some exceptions depending on the result of IsHandledDeadlyException() (which depends on asan flags).
This way we have the same behavior on Windows and Posix systems.
On Posix, we intercept signal and sigaction, so user's code can only register signal handlers for signals that are not handled by asan.
The same on Windows, after this diff, user's code can only register exception handlers for exceptions that are not handled by asan.

In particular, this is necessary for libFuzzer:

On Posix, libFuzzer registers signals handlers for SIGFPE, SIGSEGV, SIGILL, etc. If the code is compiled with -fsanitize=address, asan library will intercept sigaction and register its own signals handlers for SIGFPE, SIGSEGV, SIGILL (depending on asan flags). So, when the code being fuzzed generates a signal, like SIGFPE, it will be handled by asan, not by libFuzzer.

We want the same behavior for Windows. After this diff, libFuzzer registers exception handlers with SetUnhandledExceptionFilter. Asan library will intercept SetUnhandledExceptionFilter and register it own exception handler for exceptions like EXCEPTION_FLT_DIVIDE_BY_ZERO, etc (depending on asan flags). So, when the code being fuzzed generates an exception, like EXCEPTION_FLT_DIVIDE_BY_ZERO, it will be handled by asan, not by libFuzzer.

Diff Detail

Repository
rL LLVM

Event Timeline

mpividori created this revision.Feb 2 2017, 10:45 AM

Also, I realized on this difference after executing some tests for libFuzzer on Linux and Windows. On Linux the FPE error was handled by asan, and on Windows it was handled by libFuzzer. (After https://reviews.llvm.org/D29462)

rnk accepted this revision.Feb 2 2017, 10:50 AM

lgtm

This revision is now accepted and ready to land.Feb 2 2017, 10:50 AM
This revision was automatically updated to reflect the committed changes.