Skip to content

Commit 1810e20

Browse files
committed
contrib: simplify PE test-security-check
1 parent 6c9746f commit 1810e20

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

contrib/devtools/security-check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def check_PE_RELOC_SECTION(binary) -> bool:
130130
'''Check for a reloc section. This is required for functional ASLR.'''
131131
return binary.has_relocations
132132

133-
def check_PE_control_flow(binary) -> bool:
133+
def check_PE_CONTROL_FLOW(binary) -> bool:
134134
'''
135135
Check for control flow instrumentation
136136
'''
@@ -145,7 +145,7 @@ def check_PE_control_flow(binary) -> bool:
145145
return True
146146
return False
147147

148-
def check_PE_Canary(binary) -> bool:
148+
def check_PE_CANARY(binary) -> bool:
149149
'''
150150
Check for use of stack canary
151151
'''
@@ -216,8 +216,8 @@ def check_MACHO_BRANCH_PROTECTION(binary) -> bool:
216216
('HIGH_ENTROPY_VA', check_PE_HIGH_ENTROPY_VA),
217217
('NX', check_NX),
218218
('RELOC_SECTION', check_PE_RELOC_SECTION),
219-
('CONTROL_FLOW', check_PE_control_flow),
220-
('Canary', check_PE_Canary),
219+
('CONTROL_FLOW', check_PE_CONTROL_FLOW),
220+
('CANARY', check_PE_CANARY),
221221
]
222222

223223
BASE_MACHO = [

contrib/devtools/test-security-check.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,16 @@ def test_PE(self):
9595
cxx = determine_wellknown_cmd('CXX', 'x86_64-w64-mingw32-g++')
9696
write_testcode(source)
9797

98-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--disable-nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fno-stack-protector']),
99-
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA NX RELOC_SECTION CONTROL_FLOW Canary'))
100-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fstack-protector-all', '-lssp']),
101-
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA RELOC_SECTION CONTROL_FLOW'))
102-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fstack-protector-all', '-lssp']),
103-
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA CONTROL_FLOW'))
104-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
105-
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA CONTROL_FLOW')) # -pie -fPIE does nothing unless --dynamicbase is also supplied
106-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
107-
(1, executable+': failed HIGH_ENTROPY_VA CONTROL_FLOW'))
108-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
109-
(1, executable+': failed CONTROL_FLOW'))
110-
self.assertEqual(call_security_check(cxx, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE', '-fcf-protection=full','-fstack-protector-all', '-lssp']),
111-
(0, ''))
98+
pass_flags = ['-Wl,--nxcompat', '-Wl,--enable-reloc-section', '-Wl,--dynamicbase', '-Wl,--high-entropy-va', '-pie', '-fPIE', '-fcf-protection=full', '-fstack-protector-all', '-lssp']
99+
100+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-fno-stack-protector']), (1, executable + ': failed CANARY'))
101+
# https://github.com/lief-project/LIEF/issues/1076 - in future, we could test this individually.
102+
# self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-Wl,--disable-reloc-section']), (1, executable + ': failed RELOC_SECTION'))
103+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-Wl,--disable-nxcompat']), (1, executable + ': failed NX'))
104+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-Wl,--disable-dynamicbase']), (1, executable + ': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA')) # -pie -fPIE does nothing without --dynamicbase
105+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-Wl,--disable-high-entropy-va']), (1, executable + ': failed HIGH_ENTROPY_VA'))
106+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags + ['-fcf-protection=none']), (1, executable + ': failed CONTROL_FLOW'))
107+
self.assertEqual(call_security_check(cxx, source, executable, pass_flags), (0, ''))
112108

113109
clean_files(source, executable)
114110

0 commit comments

Comments
 (0)