-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle SIGBUS / SIGSEGV only when originating from YARA's memor…
…y blocks (#2020) * feat: prevent race conditions on signal handler If multiple threads were running in parallel (e.g. each using a YR_SCANNER), race conditions could cause the original signal handler to not be restored correctly. Add a mutex that controls access to the (process wide) signal handler to ensure that the YARA signal handler is only installed once and only removed when it is no longer needed. * feat: forward signal to old signal handler If a signal is received that does not originate from YARA (which is quite possible in multi-threaded applications using YARA), it is currently ignored. Especially for SIGSEGV, this may cause unexpected behaviour in the caller, even in threads that do not use YARA. Add logic to call the original signal handler to handle this case more cleanly. It is not perfect - with only a process wide signal handler, it's probably impossible to have a perfect solution - but it's better than the current behaviour. * fix: make exception test more verbose * fix: only handle signals in memory block data Some callbacks from YARA code are done from YR_TRYCATCH. Currently, YARA assumes that SIGBUS / SIGSEGV from these callbacks are due to the scanned memory range, but this is not necessarily true. Add logic to identify the currently scanned memory block and only catch the signal if the SIGBUS / SIGSEGV originated from it. * chore: simplify signal handler forwarding * feat: reduce caught signals to required for known OS
- Loading branch information
1 parent
cceb501
commit 19da77e
Showing
15 changed files
with
233 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.