Skip to content

Commit edaca2d

Browse files
committed
scripts: add MACHO NX check to security-check.py
1 parent 1a4e9f3 commit edaca2d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

contrib/devtools/security-check.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ def check_MACHO_NOUNDEFS(executable) -> bool:
197197
return True
198198
return False
199199

200+
def check_MACHO_NX(executable) -> bool:
201+
'''
202+
Check for no stack execution
203+
'''
204+
flags = get_MACHO_executable_flags(executable)
205+
if 'ALLOW_STACK_EXECUTION' in flags:
206+
return False
207+
return True
208+
200209
CHECKS = {
201210
'ELF': [
202211
('PIE', check_ELF_PIE),
@@ -212,6 +221,7 @@ def check_MACHO_NOUNDEFS(executable) -> bool:
212221
'MACHO': [
213222
('PIE', check_MACHO_PIE),
214223
('NOUNDEFS', check_MACHO_NOUNDEFS),
224+
('NX', check_MACHO_NX)
215225
]
216226
}
217227

contrib/devtools/test-security-check.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def test_MACHO(self):
6060
cc = 'clang'
6161
write_testcode(source)
6262

63+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace', '-Wl,-allow_stack_execute']),
64+
(1, executable+': failed PIE NOUNDEFS NX'))
6365
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace']),
6466
(1, executable+': failed PIE NOUNDEFS'))
6567
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie']),

0 commit comments

Comments
 (0)