-
Notifications
You must be signed in to change notification settings - Fork 39k
security-check: test for _FORTIFY_SOURCE usage in release binaries
#27038
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| Exit status will be 0 if successful, and the program will be silent. | ||
| Otherwise the exit status will be 1 and it will log which executables failed which checks. | ||
| ''' | ||
| import re | ||
| import sys | ||
|
|
||
| import lief | ||
|
|
@@ -116,6 +117,25 @@ def check_ELF_CONTROL_FLOW(binary) -> bool: | |
| return True | ||
| return False | ||
|
|
||
| def check_ELF_FORTIFY(binary) -> bool: | ||
|
|
||
| # bitcoin-util does not currently contain any fortified functions | ||
| if 'Bitcoin Core bitcoin-util utility version ' in binary.strings: | ||
| return True | ||
|
|
||
| chk_funcs = set() | ||
|
|
||
| for sym in binary.imported_symbols: | ||
| match = re.search(r'__[a-z]*_chk', sym.name) | ||
| if match: | ||
| chk_funcs.add(match.group(0)) | ||
|
|
||
| # ignore stack-protector and bdb | ||
| chk_funcs.discard('__stack_chk') | ||
| chk_funcs.discard('__db_chk') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bit unfortunate that this list has to be maintained, but I can't think of a better way either.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, it's a bit annoying. At least post-BDB, it'll just be "ignore the stack protector". |
||
|
|
||
| return len(chk_funcs) >= 1 | ||
|
|
||
| def check_PE_DYNAMIC_BASE(binary) -> bool: | ||
| '''PIE: DllCharacteristics bit 0x40 signifies dynamicbase (ASLR)''' | ||
| return lief.PE.DLL_CHARACTERISTICS.DYNAMIC_BASE in binary.optional_header.dll_characteristics_lists | ||
|
|
@@ -228,11 +248,11 @@ def check_MACHO_BRANCH_PROTECTION(binary) -> bool: | |
|
|
||
| CHECKS = { | ||
| lief.EXE_FORMATS.ELF: { | ||
| lief.ARCHITECTURES.X86: BASE_ELF + [('CONTROL_FLOW', check_ELF_CONTROL_FLOW)], | ||
| lief.ARCHITECTURES.ARM: BASE_ELF, | ||
| lief.ARCHITECTURES.ARM64: BASE_ELF, | ||
| lief.ARCHITECTURES.PPC: BASE_ELF, | ||
| lief.ARCHITECTURES.RISCV: BASE_ELF, | ||
| lief.ARCHITECTURES.X86: BASE_ELF + [('CONTROL_FLOW', check_ELF_CONTROL_FLOW), ('FORTIFY', check_ELF_FORTIFY)], | ||
| lief.ARCHITECTURES.ARM: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)], | ||
| lief.ARCHITECTURES.ARM64: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)], | ||
| lief.ARCHITECTURES.PPC: BASE_ELF + [('FORTIFY', check_ELF_FORTIFY)], | ||
| lief.ARCHITECTURES.RISCV: BASE_ELF, # Skip FORTIFY. See https://github.com/lief-project/LIEF/issues/1082. | ||
| }, | ||
| lief.EXE_FORMATS.PE: { | ||
| lief.ARCHITECTURES.X86: BASE_PE, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.