From ae32db8df4f65dea48e19677d4192376e6bc3411 Mon Sep 17 00:00:00 2001 From: Bram910 Date: Sat, 24 Oct 2026 12:00:55 +0200 Subject: [PATCH 1/2] fix(tools): avoid repeated GNU hash chain walks --- tools/import_audit.py | 4 ++- tools/tests/test_import_audit.py | 52 ++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/tools/import_audit.py b/tools/import_audit.py index b683e5e5a8..b8dca333f0 100644 --- a/tools/import_audit.py +++ b/tools/import_audit.py @@ -116,16 +116,18 @@ def elf_program_dynamic_symbols(path, data): bucket_data = take(data, bucket_offset, buckets * 4, path, "GNU hash buckets") chain_offset = bucket_offset + buckets * 4 maximum = first_symbol - 1 + visited_chain_entries = set() for index in struct.unpack(f"<{buckets}I", bucket_data) if buckets else (): if index == 0: continue if index < first_symbol: raise AuditError(f"{path}: GNU hash bucket index {index} precedes symbol offset {first_symbol}") symbol_index = index - while True: + while symbol_index not in visited_chain_entries: chain_address = dynamic[0x6ffffef5] + (chain_offset - hash_offset) + (symbol_index - first_symbol) * 4 chain_file_offset = file_offset(chain_address, 4, "GNU hash chain") chain_value = unpack(" Date: Sat, 24 Oct 2026 20:07:38 +0200 Subject: [PATCH 2/2] test(tools): clarify GNU hash chain coverage --- tools/tests/test_import_audit.py | 34 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/tests/test_import_audit.py b/tools/tests/test_import_audit.py index 7ca6f097a6..b1231012ea 100644 --- a/tools/tests/test_import_audit.py +++ b/tools/tests/test_import_audit.py @@ -101,6 +101,21 @@ def build_sectionless_elf(symbols, needed=(), gnu_hash=False, gnu_buckets=(1,)): return bytes(image) +def gnu_hash_chain_offset(image): + header = struct.unpack_from("<16sHHIQQQIHHHHHH", image) + segments = [struct.unpack_from("