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

Allow custom SIGSEGV handler on top of ASan's handler #180

Closed
ramosian-glider opened this issue Aug 31, 2015 · 13 comments
Closed

Allow custom SIGSEGV handler on top of ASan's handler #180

ramosian-glider opened this issue Aug 31, 2015 · 13 comments

Comments

@ramosian-glider
Copy link
Member

Originally reported on Google Code with ID 180

In Mozilla's ASM.js code, the developers are using a custom SIGSEGV handler and guard
pages to detect certain conditions and handle them (I think it's related to out of
bounds). I'm not exactly aware of the details why they need to do this, but they expect
certain SIGSEGVs to happen and want to detect and handle these. In their handler, they
check if the SIGSEGV is supposed to be handled by them (by checking if it occurred
on their guard pages) and if not, they pass the SIGSEGV on to the next signal handler.

Now it seems that ASan intercepts and silently ignores sigaction on Linux and therefore,
this all doesn't work and for every internal SIGSEGV, ASan aborts the program.

Is there a reason why this isn't possible/allowed? From the source code it seems, that
on Android, this is not intercepted.

If it's possible somehow, then I'd appreciate if we could fix this, or at least add
an option to allow it, otherwise I will have to entirely disable the ASan SIGSEGV handler
which would be a large drawback for our automated testing.

Reported by decoder.oh on 2013-04-24 12:03:25

@ramosian-glider
Copy link
Member Author

Does setting ASAN_OPTIONS=handle_segv=0 work for you? 

Reported by konstantin.s.serebryany on 2013-04-24 12:20:09

@ramosian-glider
Copy link
Member Author

Yes, that works. But I don't want to use this option because we won't get ASan traces
then for real crashes (I have a patch in the bugzilla bug to disable the ASan SIGSEGV
handler in our JS engine, but we really don't want to take it if there are better options).

If we wouldn't have crash traces from ASan anymore, then automation for getting crash
information gets really hard with ASan because core dumps are also not an option.

Reported by decoder.oh on 2013-04-24 12:22:37

@ramosian-glider
Copy link
Member Author

FYI,
https://code.google.com/p/address-sanitizer/issues/detail?id=65

Android has some platform magic that handles SEGV and prints stack trace to logcat.

Reported by eugenis@google.com on 2013-04-24 12:52:01

@ramosian-glider
Copy link
Member Author

I read through the bug you linked. The main difference to me seems that in the bug,
we're always talking about real crashes, just that they're handled differently.

In our case, the developers are explicitly expecting SIGSEGV as part of the correct
program execution, it isn't meant to be handled as a crash (the ASM.js SIGSEGV handler
will handle it's own SIGSEGVs and proceed with execution).

Reported by decoder.oh on 2013-04-24 12:55:56

@ramosian-glider
Copy link
Member Author

I think we can allow signal handler chaining under a flag.
We can make handle_segv accept one of the three string options: "0", "1" and "chain".
0 and 1 are for backwards compatibility, for generality we can also parse "yes" and
"no".

Reported by ramosian.glider on 2013-04-24 16:10:52

@ramosian-glider
Copy link
Member Author

That would be very nice to have and sufficient for us (I can make the flag even default
to "chain" for us in our code, so that would be fine).

Reported by decoder.oh on 2013-04-24 16:23:18

@ramosian-glider
Copy link
Member Author

I really don't want to get into signal handler chaining business -- that's too complex
to my taste.
Asan's reports on SEGV contain only one bit of useful information - the stack trace.

If the user's SEGV handler can distinguish between good and bad segv, it can 
print an error message with a stack trace for a bad SEGV. 
Alternatively, it can call __asan_report_error from the asan public API 
(include/sanitizer/asan_interface.h). 


Reported by konstantin.s.serebryany on 2013-04-24 16:27:58

  • Labels added: Type-Enhancement
  • Labels removed: Type-Defect

@ramosian-glider
Copy link
Member Author

Our user SEGV handler is not installed all of the time. It is only installed when ASM.js
is actually used (otherwise it doesn't make sense to have that handler).

Regarding the chaining complexity, I think the complexity would be in the code that
wants to chain, not in ASan, since ASan can always be the last handler in the chain.
It doesn't have to bother with calling other handlers.

Reported by decoder.oh on 2013-04-24 16:32:46

@ramosian-glider
Copy link
Member Author

Yeah, we may not modify existing runtime options, but add another one - smth. like "allow_user_segv"
(off by default), that would unconditionally call REAL(sigaction) in sigaction interceptor.
If the user turns this flag on, he is responsible for proper handling of "oldact" output
parameter of sigaction and calling ASan segv handler if necessary.

Reported by vonosmas on 2013-04-24 19:57:41

@ramosian-glider
Copy link
Member Author

#8: I see. 
#9: sounds reasonable, go for it. Thanks! 

Reported by konstantin.s.serebryany on 2013-04-25 02:10:45

@ramosian-glider
Copy link
Member Author

Should be implemented in r180255.

Reported by samsonov@google.com on 2013-04-25 10:56:38

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Thanks, we'll test and let you know if it works :)

Reported by decoder.oh on 2013-04-25 10:57:56

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:13:41

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant