Skip to content

Commit 6fe5516

Browse files
committed
contrib: support arm64 darwin in security checks
1 parent 446e73c commit 6fe5516

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

contrib/devtools/security-check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,9 @@ def check_MACHO_control_flow(binary) -> bool:
211211
]
212212

213213
BASE_MACHO = [
214-
('PIE', check_PIE),
215214
('NOUNDEFS', check_MACHO_NOUNDEFS),
216-
('NX', check_NX),
217215
('LAZY_BINDINGS', check_MACHO_LAZY_BINDINGS),
218216
('Canary', check_MACHO_Canary),
219-
('CONTROL_FLOW', check_MACHO_control_flow),
220217
]
221218

222219
CHECKS = {
@@ -231,7 +228,10 @@ def check_MACHO_control_flow(binary) -> bool:
231228
lief.ARCHITECTURES.X86: BASE_PE,
232229
},
233230
lief.EXE_FORMATS.MACHO: {
234-
lief.ARCHITECTURES.X86: BASE_MACHO,
231+
lief.ARCHITECTURES.X86: BASE_MACHO + [('PIE', check_PIE),
232+
('NX', check_NX),
233+
('CONTROL_FLOW', check_MACHO_control_flow)],
234+
lief.ARCHITECTURES.ARM64: BASE_MACHO,
235235
}
236236
}
237237

contrib/devtools/test-security-check.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,34 @@ def test_MACHO(self):
116116
executable = 'test1'
117117
cc = determine_wellknown_cmd('CC', 'clang')
118118
write_testcode(source)
119+
arch = get_arch(cc, source, executable)
120+
121+
if arch == lief.ARCHITECTURES.X86:
122+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector']),
123+
(1, executable+': failed NOUNDEFS LAZY_BINDINGS Canary PIE NX CONTROL_FLOW'))
124+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all']),
125+
(1, executable+': failed NOUNDEFS LAZY_BINDINGS PIE NX CONTROL_FLOW'))
126+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
127+
(1, executable+': failed NOUNDEFS LAZY_BINDINGS PIE CONTROL_FLOW'))
128+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
129+
(1, executable+': failed LAZY_BINDINGS PIE CONTROL_FLOW'))
130+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all']),
131+
(1, executable+': failed PIE CONTROL_FLOW'))
132+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
133+
(1, executable+': failed PIE'))
134+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
135+
(0, ''))
136+
else:
137+
# arm64 darwin doesn't support non-PIE binaries, control flow or executable stacks
138+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fno-stack-protector']),
139+
(1, executable+': failed NOUNDEFS LAZY_BINDINGS Canary'))
140+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fstack-protector-all']),
141+
(1, executable+': failed NOUNDEFS LAZY_BINDINGS'))
142+
self.assertEqual(call_security_check(cc, source, executable, ['-fstack-protector-all']),
143+
(1, executable+': failed LAZY_BINDINGS'))
144+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-bind_at_load','-fstack-protector-all']),
145+
(0, ''))
119146

120-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector']),
121-
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS Canary CONTROL_FLOW'))
122-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all']),
123-
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS CONTROL_FLOW'))
124-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
125-
(1, executable+': failed PIE NOUNDEFS LAZY_BINDINGS CONTROL_FLOW'))
126-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
127-
(1, executable+': failed PIE LAZY_BINDINGS CONTROL_FLOW'))
128-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all']),
129-
(1, executable+': failed PIE CONTROL_FLOW'))
130-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
131-
(1, executable+': failed PIE'))
132-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
133-
(0, ''))
134147

135148
clean_files(source, executable)
136149

0 commit comments

Comments
 (0)