From 96470f0a1129c61de5ecd1cdd3848d05fa6d106d Mon Sep 17 00:00:00 2001 From: roboterspinne <229981445+roboterspinne@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:24:57 +0100 Subject: [PATCH] fix(relinker): reject relocations against a non-null executable symbol entry 0 A symbolic relocation with symbol index 0 read the name, binding and type of dynamic symbol entry 0, so a named entry 0 turned STN_UNDEF relocations into named imports on Linux, Windows and macOS. The ELF gABI reserves index 0 as STN_UNDEF and requires its entry to be all zero, and the guest reader already rejects such a table as "Invalid null symbol". The relinker now fails with "Dynamic symbol table entry 0 is not a null symbol entry" when a symbolic relocation names index 0 and that entry has a nonzero byte; relocations against an all-zero entry 0 are unchanged. --- .../relinker/src/pipeline/RelinkerPipeline.cpp | 3 +++ .../tests/test_null_symbol_relocations.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp index 1dec1d5a254e..59f3c0449f11 100644 --- a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp +++ b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp @@ -300,6 +300,9 @@ RelinkResult RelinkerPipeline::Relink() { if (symOff < dynSymTabOffset || symOff > raw.size() || raw.size() - symOff < symEntSize || (dynSymTabSize && (off > *dynSymTabSize || symEntSize > *dynSymTabSize - off))) throw RelinkerException("Symbol table entry out of bounds", symOff); + if (symIdx == 0 && std::any_of(raw.begin() + static_cast(symOff), raw.begin() + static_cast(symOff + symEntSize), + [](const std::uint8_t byte) { return byte != 0; })) + throw RelinkerException("Dynamic symbol table entry 0 is not a null symbol entry", symOff); return symOff; }; diff --git a/core/relinker/relinker/tests/test_null_symbol_relocations.py b/core/relinker/relinker/tests/test_null_symbol_relocations.py index 99f436b7b726..6e9f22b35207 100644 --- a/core/relinker/relinker/tests/test_null_symbol_relocations.py +++ b/core/relinker/relinker/tests/test_null_symbol_relocations.py @@ -82,6 +82,21 @@ def main(): capture_output=True, text=True, timeout=20) assert result.returncode == 2 and "Unnamed import symbol is not a null symbol entry" in result.stderr, (target, result.stderr) assert not output.exists() + named_null = image_with(index=0) + names = b"\0foo\0libfoo.prx\0" + named_null[0x600:0x600 + len(names)] = names + struct.pack_into("