mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-07 17:00:32 +02:00
contrib: support arm64 darwin in security checks
This commit is contained in:
@ -211,12 +211,9 @@ BASE_PE = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
BASE_MACHO = [
|
BASE_MACHO = [
|
||||||
('PIE', check_PIE),
|
|
||||||
('NOUNDEFS', check_MACHO_NOUNDEFS),
|
('NOUNDEFS', check_MACHO_NOUNDEFS),
|
||||||
('NX', check_NX),
|
|
||||||
('LAZY_BINDINGS', check_MACHO_LAZY_BINDINGS),
|
('LAZY_BINDINGS', check_MACHO_LAZY_BINDINGS),
|
||||||
('Canary', check_MACHO_Canary),
|
('Canary', check_MACHO_Canary),
|
||||||
('CONTROL_FLOW', check_MACHO_control_flow),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
CHECKS = {
|
CHECKS = {
|
||||||
@ -231,7 +228,10 @@ CHECKS = {
|
|||||||
lief.ARCHITECTURES.X86: BASE_PE,
|
lief.ARCHITECTURES.X86: BASE_PE,
|
||||||
},
|
},
|
||||||
lief.EXE_FORMATS.MACHO: {
|
lief.EXE_FORMATS.MACHO: {
|
||||||
lief.ARCHITECTURES.X86: BASE_MACHO,
|
lief.ARCHITECTURES.X86: BASE_MACHO + [('PIE', check_PIE),
|
||||||
|
('NX', check_NX),
|
||||||
|
('CONTROL_FLOW', check_MACHO_control_flow)],
|
||||||
|
lief.ARCHITECTURES.ARM64: BASE_MACHO,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,21 +116,34 @@ class TestSecurityChecks(unittest.TestCase):
|
|||||||
executable = 'test1'
|
executable = 'test1'
|
||||||
cc = determine_wellknown_cmd('CC', 'clang')
|
cc = determine_wellknown_cmd('CC', 'clang')
|
||||||
write_testcode(source)
|
write_testcode(source)
|
||||||
|
arch = get_arch(cc, source, executable)
|
||||||
|
|
||||||
|
if arch == lief.ARCHITECTURES.X86:
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector']),
|
||||||
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS Canary CONTROL_FLOW'))
|
(1, executable+': failed NOUNDEFS LAZY_BINDINGS Canary PIE NX CONTROL_FLOW'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all']),
|
||||||
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS CONTROL_FLOW'))
|
(1, executable+': failed NOUNDEFS LAZY_BINDINGS PIE NX CONTROL_FLOW'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
|
||||||
(1, executable+': failed PIE NOUNDEFS LAZY_BINDINGS CONTROL_FLOW'))
|
(1, executable+': failed NOUNDEFS LAZY_BINDINGS PIE CONTROL_FLOW'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
|
||||||
(1, executable+': failed PIE LAZY_BINDINGS CONTROL_FLOW'))
|
(1, executable+': failed LAZY_BINDINGS PIE CONTROL_FLOW'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all']),
|
||||||
(1, executable+': failed PIE CONTROL_FLOW'))
|
(1, executable+': failed PIE CONTROL_FLOW'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
|
||||||
(1, executable+': failed PIE'))
|
(1, executable+': failed PIE'))
|
||||||
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
|
||||||
(0, ''))
|
(0, ''))
|
||||||
|
else:
|
||||||
|
# arm64 darwin doesn't support non-PIE binaries, control flow or executable stacks
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fno-stack-protector']),
|
||||||
|
(1, executable+': failed NOUNDEFS LAZY_BINDINGS Canary'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fstack-protector-all']),
|
||||||
|
(1, executable+': failed NOUNDEFS LAZY_BINDINGS'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-fstack-protector-all']),
|
||||||
|
(1, executable+': failed LAZY_BINDINGS'))
|
||||||
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-bind_at_load','-fstack-protector-all']),
|
||||||
|
(0, ''))
|
||||||
|
|
||||||
|
|
||||||
clean_files(source, executable)
|
clean_files(source, executable)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user