Skip to content

Commit 7f96638

Browse files
committed
contrib: add macOS fixup_chains check to security-check
Followup to #27676.
1 parent 3dca683 commit 7f96638

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

contrib/devtools/security-check.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ def check_MACHO_NOUNDEFS(binary) -> bool:
158158
'''
159159
return binary.header.has(lief.MachO.HEADER_FLAGS.NOUNDEFS)
160160

161+
def check_MACHO_FIXUP_CHAINS(binary) -> bool:
162+
'''
163+
Check for use of chained fixups.
164+
'''
165+
return binary.has_dyld_chained_fixups
166+
161167
def check_MACHO_Canary(binary) -> bool:
162168
'''
163169
Check for use of stack canary
@@ -208,6 +214,7 @@ def check_MACHO_control_flow(binary) -> bool:
208214
BASE_MACHO = [
209215
('NOUNDEFS', check_MACHO_NOUNDEFS),
210216
('Canary', check_MACHO_Canary),
217+
('FIXUP_CHAINS', check_MACHO_FIXUP_CHAINS),
211218
]
212219

213220
CHECKS = {

contrib/devtools/test-security-check.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,31 @@ def test_MACHO(self):
119119
arch = get_arch(cc, source, executable)
120120

121121
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']),
122+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector', '-Wl,-no_fixup_chains']),
123+
(1, executable+': failed NOUNDEFS Canary FIXUP_CHAINS PIE NX CONTROL_FLOW'))
124+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector', '-Wl,-fixup_chains']),
123125
(1, executable+': failed NOUNDEFS 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']),
126+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all', '-Wl,-fixup_chains']),
125127
(1, executable+': failed NOUNDEFS PIE NX CONTROL_FLOW'))
126-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
128+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all', '-Wl,-fixup_chains']),
127129
(1, executable+': failed NOUNDEFS PIE CONTROL_FLOW'))
128-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
130+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all', '-Wl,-fixup_chains']),
129131
(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']),
132+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-Wl,-fixup_chains']),
131133
(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']),
134+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full', '-Wl,-fixup_chains']),
133135
(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']),
136+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full', '-Wl,-fixup_chains']),
135137
(0, ''))
136138
else:
137139
# 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']),
140+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fno-stack-protector', '-Wl,-no_fixup_chains']),
141+
(1, executable+': failed NOUNDEFS Canary FIXUP_CHAINS'))
142+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fno-stack-protector', '-Wl,-fixup_chains']),
139143
(1, executable+': failed NOUNDEFS Canary'))
140-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fstack-protector-all']),
144+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-flat_namespace','-fstack-protector-all', '-Wl,-fixup_chains']),
141145
(1, executable+': failed NOUNDEFS'))
142-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-bind_at_load','-fstack-protector-all']),
146+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-bind_at_load','-fstack-protector-all', '-Wl,-fixup_chains']),
143147
(0, ''))
144148

145149

0 commit comments

Comments
 (0)