Merge #18415: scripts: add MACHO tests to test-security-check.py
7142d50ac3scripts: rename test_64bit_PE to test_PE (fanquake)edaca2dd12scripts: add MACHO NX check to security-check.py (fanquake)1a4e9f32efscripts: add MACHO tests to test-security-check.py (fanquake) Pull request description: Adds tests for the MACHO checks in security-check.py: https://github.com/bitcoin/bitcoin/blob/ac579ada7e83a1b8100d611412f9ede885a4e522/contrib/devtools/security-check.py#L212-L214 I'm planning on following up with more checks in security-check.py, and corresponding tests in test-security-check.py. Note that you'll probably have to be on macOS to run them. You can run just this suite with `python3 test-security-check.py TestSecurityChecks.test_MACHO`. ACKs for top commit: laanwj: ACK7142d50ac3Tree-SHA512: ace3ca9f6df5d4fedd5988938fb7dc7563ec7dc587aa275f780b5f51e9b8d7d6f7768e0a1e05ce438510a07b8640aba92c76847b30c2990f46c66b78a0acf960
This commit is contained in:
2 files changed
+34
-5
No files matched your search
@@ -197,6 +197,15 @@ def check_MACHO_NOUNDEFS(executable) -> bool:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def check_MACHO_NX(executable) -> bool:
|
||||||
|
'''
|
||||||
|
Check for no stack execution
|
||||||
|
'''
|
||||||
|
flags = get_MACHO_executable_flags(executable)
|
||||||
|
if 'ALLOW_STACK_EXECUTION' in flags:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
CHECKS = {
|
CHECKS = {
|
||||||
'ELF': [
|
'ELF': [
|
||||||
('PIE', check_ELF_PIE),
|
('PIE', check_ELF_PIE),
|
||||||
@@ -212,6 +221,7 @@ CHECKS = {
|
|||||||
'MACHO': [
|
'MACHO': [
|
||||||
('PIE', check_MACHO_PIE),
|
('PIE', check_MACHO_PIE),
|
||||||
('NOUNDEFS', check_MACHO_NOUNDEFS),
|
('NOUNDEFS', check_MACHO_NOUNDEFS),
|
||||||
|
('NX', check_MACHO_NX)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,16 +43,35 @@ class TestSecurityChecks(unittest.TestCase):
|
|||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-zrelro','-Wl,-z,now','-pie','-fPIE']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-zrelro','-Wl,-z,now','-pie','-fPIE']),
|
||||||
(0, ''))
|
(0, ''))
|
||||||
|
|
||||||
def test_64bit_PE(self):
|
def test_PE(self):
|
||||||
source = 'test1.c'
|
source = 'test1.c'
|
||||||
executable = 'test1.exe'
|
executable = 'test1.exe'
|
||||||
cc = 'x86_64-w64-mingw32-gcc'
|
cc = 'x86_64-w64-mingw32-gcc'
|
||||||
write_testcode(source)
|
write_testcode(source)
|
||||||
|
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--no-nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA NX'))
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--no-nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']),
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA'))
|
(1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA NX'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--no-high-entropy-va']), (1, executable+': failed HIGH_ENTROPY_VA'))
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--no-dynamicbase','-Wl,--no-high-entropy-va']),
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--high-entropy-va']), (0, ''))
|
(1, executable+': failed DYNAMIC_BASE HIGH_ENTROPY_VA'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--no-high-entropy-va']),
|
||||||
|
(1, executable+': failed HIGH_ENTROPY_VA'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--high-entropy-va']),
|
||||||
|
(0, ''))
|
||||||
|
|
||||||
|
def test_MACHO(self):
|
||||||
|
source = 'test1.c'
|
||||||
|
executable = 'test1'
|
||||||
|
cc = 'clang'
|
||||||
|
write_testcode(source)
|
||||||
|
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace', '-Wl,-allow_stack_execute']),
|
||||||
|
(1, executable+': failed PIE NOUNDEFS NX'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace']),
|
||||||
|
(1, executable+': failed PIE NOUNDEFS'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie']),
|
||||||
|
(1, executable+': failed PIE'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie']),
|
||||||
|
(0, ''))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in new issue
Block a user