Skip to content

Commit 0c2a128

Browse files
committed
Merge bitcoin/bitcoin#26835: contrib: add PE Canary check to security-check
6ba17d4 scripts: add PE Canary check to security-check (fanquake) Pull request description: We should be checking this, same as ELF & MACHO. Guix Build: ```bash 6334c001b276ca5f0278092be68bf6d49d9b755bcac893bbd4aa58df57356e40 guix-build-6ba17d4955b7/output/dist-archive/bitcoin-6ba17d4955b7.tar.gz e27ad7fffb377bc6264477933859ab47c7283a68fbf86124d3801bc4c8b790dd guix-build-6ba17d4955b7/output/x86_64-w64-mingw32/SHA256SUMS.part ef7b61bd854f0d3c39f356ef85ac18d37c5740874111f5ce46f7ce3381e714ca guix-build-6ba17d4955b7/output/x86_64-w64-mingw32/bitcoin-6ba17d4955b7-win64-debug.zip c419324597487f248143a076d6eb2a56b0dbf5ce690ca89afaaee5c6b352e1a1 guix-build-6ba17d4955b7/output/x86_64-w64-mingw32/bitcoin-6ba17d4955b7-win64-setup-unsigned.exe a18ff1e3026cd9fc08dd7b500c06a343462aef4a37538608d940d1845bcdb94a guix-build-6ba17d4955b7/output/x86_64-w64-mingw32/bitcoin-6ba17d4955b7-win64-unsigned.tar.gz 7e4ee0669940f4b8c1a12dab836898511a60f06a62057ac03beaca8bb693bfb4 guix-build-6ba17d4955b7/output/x86_64-w64-mingw32/bitcoin-6ba17d4955b7-win64.zip ``` ACKs for top commit: sipsorcery: ACK 6ba17d4. Tree-SHA512: 1acc24c0cb36dbc30311f4eee64e3d4737c828b97039be0f72cfe061bcb8c4d5c830d7792f503e711e219a62d85b7e07cdff3510cbd4f8d46895a7cb66b88219
2 parents 8915e4d + 6ba17d4 commit 0c2a128

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

contrib/devtools/security-check.py

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ def check_PE_control_flow(binary) -> bool:
146146
return True
147147
return False
148148

149+
def check_PE_Canary(binary) -> bool:
150+
'''
151+
Check for use of stack canary
152+
'''
153+
return binary.has_symbol('__stack_chk_fail')
154+
149155
def check_MACHO_NOUNDEFS(binary) -> bool:
150156
'''
151157
Check for no undefined references.
@@ -203,6 +209,7 @@ def check_MACHO_control_flow(binary) -> bool:
203209
('NX', check_NX),
204210
('RELOC_SECTION', check_PE_RELOC_SECTION),
205211
('CONTROL_FLOW', check_PE_control_flow),
212+
('Canary', check_PE_Canary),
206213
]
207214

208215
BASE_MACHO = [

contrib/devtools/test-security-check.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ def test_PE(self):
9494
cc = determine_wellknown_cmd('CC', 'x86_64-w64-mingw32-gcc')
9595
write_testcode(source)
9696

97-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--disable-nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE']),
98-
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA NX RELOC_SECTION CONTROL_FLOW'))
99-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE']),
97+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--disable-nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fno-stack-protector']),
98+
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA NX RELOC_SECTION CONTROL_FLOW Canary'))
99+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fstack-protector-all', '-lssp']),
100100
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA RELOC_SECTION CONTROL_FLOW'))
101-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE']),
101+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fstack-protector-all', '-lssp']),
102102
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA CONTROL_FLOW'))
103-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE']),
103+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
104104
(1, executable+': failed PIE DYNAMIC_BASE HIGH_ENTROPY_VA CONTROL_FLOW')) # -pie -fPIE does nothing unless --dynamicbase is also supplied
105-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE']),
105+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--disable-high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
106106
(1, executable+': failed HIGH_ENTROPY_VA CONTROL_FLOW'))
107-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE']),
107+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE','-fstack-protector-all', '-lssp']),
108108
(1, executable+': failed CONTROL_FLOW'))
109-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE', '-fcf-protection=full']),
109+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--enable-reloc-section','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE', '-fcf-protection=full','-fstack-protector-all', '-lssp']),
110110
(0, ''))
111111

112112
clean_files(source, executable)

0 commit comments

Comments
 (0)