Skip to content

Commit 1527b7e

Browse files
committed
symbol-check: Check requested ELF interpreter
It is important that binaries request a standard interpreter location where most distros would place the linker-loader. Otherwise, the user would be met with a very confusing message: bash: <path>/<to>/bitcoind: No such file or directory When really it's the interpreter that's not found.
1 parent b96adcb commit 1527b7e

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

contrib/devtools/symbol-check.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
find ../path/to/binaries -type f -executable | xargs python3 contrib/devtools/symbol-check.py
1212
'''
1313
import sys
14-
from typing import List
14+
from typing import List, Dict
1515

1616
import lief
1717

@@ -63,6 +63,30 @@
6363
'environ', '_environ', '__environ',
6464
}
6565

66+
# Expected linker-loader names can be found here:
67+
# https://sourceware.org/glibc/wiki/ABIList?action=recall&rev=16
68+
ELF_INTERPRETER_NAMES: Dict[lief.ELF.ARCH, Dict[lief.ENDIANNESS, str]] = {
69+
lief.ELF.ARCH.i386: {
70+
lief.ENDIANNESS.LITTLE: "/lib/ld-linux.so.2",
71+
},
72+
lief.ELF.ARCH.x86_64: {
73+
lief.ENDIANNESS.LITTLE: "/lib64/ld-linux-x86-64.so.2",
74+
},
75+
lief.ELF.ARCH.ARM: {
76+
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-armhf.so.3",
77+
},
78+
lief.ELF.ARCH.AARCH64: {
79+
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-aarch64.so.1",
80+
},
81+
lief.ELF.ARCH.PPC64: {
82+
lief.ENDIANNESS.BIG: "/lib64/ld64.so.1",
83+
lief.ENDIANNESS.LITTLE: "/lib64/ld64.so.2",
84+
},
85+
LIEF_ELF_ARCH_RISCV: {
86+
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-riscv64-lp64d.so.1",
87+
},
88+
}
89+
6690
# Allowed NEEDED libraries
6791
ELF_ALLOWED_LIBRARIES = {
6892
# bitcoind and bitcoin-qt
@@ -215,11 +239,17 @@ def check_PE_subsystem_version(binary) -> bool:
215239
return True
216240
return False
217241

242+
def check_ELF_interpreter(binary) -> bool:
243+
expected_interpreter = ELF_INTERPRETER_NAMES[binary.header.machine_type][binary.abstract.header.endianness]
244+
245+
return binary.concrete.interpreter == expected_interpreter
246+
218247
CHECKS = {
219248
'ELF': [
220249
('IMPORTED_SYMBOLS', check_imported_symbols),
221250
('EXPORTED_SYMBOLS', check_exported_symbols),
222-
('LIBRARY_DEPENDENCIES', check_ELF_libraries)
251+
('LIBRARY_DEPENDENCIES', check_ELF_libraries),
252+
('INTERPRETER_NAME', check_ELF_interpreter),
223253
],
224254
'MACHO': [
225255
('DYNAMIC_LIBRARIES', check_MACHO_libraries),

0 commit comments

Comments
 (0)