Skip to content

Commit ecf5f2c

Browse files
committed
Merge bitcoin#21889: macho: check for control flow instrumentation
42b589d scripts: test for MACHO control flow instrumentation (fanquake) 469a5bc build: build Boost with -fcf-protection when targeting Darwin (fanquake) Pull request description: Addresses the macOS portion of bitcoin#21888. Build Boost with `-fcf-protection` when targeting Darwin. This should be ok, because our cross-compiler (Clang 10) supports the option, and I'd expect all versions of Apple Clang being used to compile Core would also support it. Building Boost with this option is required so that the `main` provided to `test_bitcoin` has instrumentation. Note that the presence of instrumentation does not mean it will be used, as that is determined at runtime by the CPU. From the Intel control flow enforcement documentation: > The ENDBR32 and ENDBR64 instructions will have the same effect as the NOP instruction on Intel 64 processors that do not support CET. On processors supporting CET, these instructions do not change register or flag state. This allows CET instrumented programs to execute on processors that do not support CET. Even when CET is supported and enabled, these NOP–like instructions do not affect the execution state of the program, do not cause any additional register pressure, and are minimally intrusive from power and performance perspectives. Follow up from bitcoin#21135. Guix builds: ```bash 663df8471400f06d4da739e39a886aa17f56a36d66e0ff7cc290686294ef39c9 guix-build-42b589d18fed/output/dist-archive/bitcoin-42b589d18fed.tar.gz 45e841661e1659a634468b6f8c9fb0a7956c31ba296f1fd0c02cd880736d6127 guix-build-42b589d18fed/output/x86_64-apple-darwin18/bitcoin-42b589d18fed-osx-unsigned.dmg 0ea85c99fef35429a5048fa14850bce6b900eaa887aeea419b019852f8d2be78 guix-build-42b589d18fed/output/x86_64-apple-darwin18/bitcoin-42b589d18fed-osx-unsigned.tar.gz 85857a5a4a5d4d3a172d6c361c12c4a94f6505fc12b527ea63b75bfe54ee1001 guix-build-42b589d18fed/output/x86_64-apple-darwin18/bitcoin-42b589d18fed-osx64.tar.gz ``` Gitian builds: ```bash # macOS: bdfd677a6b88273a741b433e1e7f554af50cc76b3342d44ab0c441e2b40efc96 bitcoin-42b589d18fed-osx-unsigned.dmg f3b2d09f3bea7a5cc489b02e8e53dd76a9922338500fae79cad0506655af56f9 bitcoin-42b589d18fed-osx-unsigned.tar.gz 29d5ad5e46bc9fb0056922a8b47c026e5e9f71e6cf447203b74644587d6fb6f7 bitcoin-42b589d18fed-osx64.tar.gz 663df8471400f06d4da739e39a886aa17f56a36d66e0ff7cc290686294ef39c9 src/bitcoin-42b589d18fed.tar.gz 366f8d7a2fc1f3e22cb1018043099126a71ce65380cc27b1c3280cce42d06c98 bitcoin-core-osx-22-res.yml ``` ACKs for top commit: laanwj: Code review ACK 42b589d Tree-SHA512: 12cb8d462d64d845b9fe48c5c6978892adff8bf5b5572bb29f35df1f6176e47b32a68bcb6e4883c7d9454e76e8868851005a7325916852a2d0d32659ac7dae3f
2 parents b82c3a0 + 42b589d commit ecf5f2c

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

contrib/devtools/security-check.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ def check_NX(executable) -> bool:
188188
binary = lief.parse(executable)
189189
return binary.has_nx
190190

191+
def check_control_flow(executable) -> bool:
192+
'''
193+
Check for control flow instrumentation
194+
'''
195+
binary = lief.parse(executable)
196+
197+
content = binary.get_content_from_virtual_address(binary.entrypoint, 4, lief.Binary.VA_TYPES.AUTO)
198+
199+
if content == [243, 15, 30, 250]: # endbr64
200+
return True
201+
return False
202+
203+
191204
CHECKS = {
192205
'ELF': [
193206
('PIE', check_ELF_PIE),
@@ -208,7 +221,8 @@ def check_NX(executable) -> bool:
208221
('NOUNDEFS', check_MACHO_NOUNDEFS),
209222
('NX', check_NX),
210223
('LAZY_BINDINGS', check_MACHO_LAZY_BINDINGS),
211-
('Canary', check_MACHO_Canary)
224+
('Canary', check_MACHO_Canary),
225+
('CONTROL_FLOW', check_control_flow),
212226
]
213227
}
214228

contrib/devtools/test-security-check.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ def test_MACHO(self):
7777
write_testcode(source)
7878

7979
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fno-stack-protector']),
80-
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS Canary'))
80+
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS Canary CONTROL_FLOW'))
8181
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-Wl,-allow_stack_execute','-fstack-protector-all']),
82-
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS'))
82+
(1, executable+': failed PIE NOUNDEFS NX LAZY_BINDINGS CONTROL_FLOW'))
8383
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-flat_namespace','-fstack-protector-all']),
84-
(1, executable+': failed PIE NOUNDEFS LAZY_BINDINGS'))
84+
(1, executable+': failed PIE NOUNDEFS LAZY_BINDINGS CONTROL_FLOW'))
8585
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-fstack-protector-all']),
86-
(1, executable+': failed PIE LAZY_BINDINGS'))
86+
(1, executable+': failed PIE LAZY_BINDINGS CONTROL_FLOW'))
8787
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all']),
88+
(1, executable+': failed PIE CONTROL_FLOW'))
89+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-no_pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
8890
(1, executable+': failed PIE'))
89-
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all']),
91+
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all', '-fcf-protection=full']),
9092
(0, ''))
9193

9294
clean_files(source, executable)

depends/packages/boost.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $(package)_config_libraries=filesystem,system,test
2626
$(package)_cxxflags=-std=c++17 -fvisibility=hidden
2727
$(package)_cxxflags_linux=-fPIC
2828
$(package)_cxxflags_android=-fPIC
29+
$(package)_cxxflags_darwin=-fcf-protection=full
2930
endef
3031

3132
define $(package)_preprocess_cmds

0 commit comments

Comments
 (0)