From 9e6e6ca97b00d2bd3227cb49a77b1399f4c5def5 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 1 Aug 2026 21:49:53 +0300 Subject: [PATCH] Verify debug info for first-party release binaries --- scripts/release.sh | 2 +- scripts/tests/test-runtime-dependencies.sh | 32 ++++++++++++++++---- scripts/validate-release-elf.py | 35 ++++++++++++++++++---- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/scripts/release.sh b/scripts/release.sh index 90a2798..a04391a 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -480,7 +480,7 @@ elf_validation_args=( --root "$stage" --report "$dependency_report" --max-glibc 2.35 - --require-debug-info + --require-first-party-debug-info --forbid-content-prefix "$source_dir" --forbid-content-prefix "$build_dir" ) diff --git a/scripts/tests/test-runtime-dependencies.sh b/scripts/tests/test-runtime-dependencies.sh index 1fe30d1..148b503 100755 --- a/scripts/tests/test-runtime-dependencies.sh +++ b/scripts/tests/test-runtime-dependencies.sh @@ -7,7 +7,7 @@ if [[ $# != 1 ]]; then fi source_root=$(realpath -e -- "$1") -for command_name in cmake ldd patchelf readelf python3; do +for command_name in cmake ldd patchelf readelf python3 strip; do command -v "$command_name" >/dev/null || { echo "missing test command: $command_name" >&2 exit 2 @@ -93,7 +93,7 @@ for variant in preferred other; do preferred) variant_lib=$preferred_lib ;; other) variant_lib=$other_lib ;; esac - "$c_compiler" -fPIC -shared "$temporary/dependency.c" \ + "$c_compiler" -g -fPIC -shared "$temporary/dependency.c" \ '-DECHOION_VARIANT="'"$variant"'-runtime"' \ -Wl,-soname,libechoion-dependency.so.1 \ -o "$variant_lib/libechoion-dependency.so.1.2.3" @@ -121,7 +121,7 @@ for variant in seeded resolver; do "$variant_lib/libstdc++.so.6" done resolver_core="$resolver/Echoion.ts" -"$c_compiler" -fPIC -shared "$temporary/core.c" \ +"$c_compiler" -g -fPIC -shared "$temporary/core.c" \ -L"$preferred_lib" -lechoion-dependency \ -Wl,-l:libstdc++.so.6 \ -Wl,-soname,Echoion.ts \ @@ -130,11 +130,11 @@ resolver_core="$resolver/Echoion.ts" install -m 0644 "$resolver_core" "$bundle/lib/Echoion.ts" patchelf --set-rpath "\$ORIGIN" "$bundle/lib/Echoion.ts" bundle_plugin="$bundle/share/echoion/bootstrap-plugins/fixture-shortener/1.0.0/fixture-shortener.so" -"$c_compiler" -fPIC -shared "$temporary/plugin.c" \ +"$c_compiler" -g -fPIC -shared "$temporary/plugin.c" \ -L"$preferred_lib" -lechoion-dependency \ -Wl,-rpath,"$preferred_lib" \ -o "$bundle_plugin" -"$c_compiler" "$temporary/main.c" -o "$bundle/bin/echoiond" +"$c_compiler" -g "$temporary/main.c" -o "$bundle/bin/echoiond" install -m 0755 "$bundle/bin/echoiond" "$bundle/bin/echoion-updater" printf '%s\n' '[Service]' >"$bundle/service/echoion.service.in" printf '%s\n' 'Echoion' \ @@ -176,6 +176,18 @@ assert module.is_system_dependency("libc.so.6") assert module.is_system_dependency("libm.so.6") assert not module.is_system_dependency("libc.so.evil") assert not module.is_system_dependency("libm.so.99") +root = Path("/release") +plugins = { + root / "share/echoion/bootstrap-plugins/example/1.0.0/example.so" +} +assert module.is_first_party_payload(root / "bin/echoiond", root, plugins) +assert module.is_first_party_payload(root / "lib/Echoion.ts", root, plugins) +assert module.is_first_party_payload(root / "lib/libechoion-host.so.2.0.0", root, plugins) +assert module.is_first_party_payload(root / "lib/libVoid_Plugin.so", root, plugins) +assert module.is_first_party_payload(root / "lib/libVoidTeamspeak.so", root, plugins) +assert module.is_first_party_payload(next(iter(plugins)), root, plugins) +assert not module.is_first_party_payload(root / "lib/libacl.so.1.1.2301", root, plugins) +assert not module.is_first_party_payload(root / "lib/libqjs.so.0.11.0", root, plugins) unknown_abi = """ Version needs section '.gnu.version_r' contains 1 entry: @@ -222,6 +234,16 @@ fi report="$temporary/dependencies.txt" python3 "$source_root/scripts/validate-release-elf.py" \ --root "$bundle" --max-glibc 2.35 --report "$report" +python3 "$source_root/scripts/validate-release-elf.py" \ + --root "$bundle" --require-first-party-debug-info >/dev/null +cp "$bundle/lib/Echoion.ts" "$temporary/Echoion.ts.debug" +strip --strip-debug "$bundle/lib/Echoion.ts" +if python3 "$source_root/scripts/validate-release-elf.py" \ + --root "$bundle" --require-first-party-debug-info >/dev/null 2>&1; then + echo "first-party ELF without debug information passed validation" >&2 + exit 1 +fi +install -m 0644 "$temporary/Echoion.ts.debug" "$bundle/lib/Echoion.ts" if python3 "$source_root/scripts/validate-release-elf.py" \ --root "$bundle" \ --forbid-content-prefix /tmp/echoion-forbidden-build-path \ diff --git a/scripts/validate-release-elf.py b/scripts/validate-release-elf.py index 221d9d8..2e8a21c 100755 --- a/scripts/validate-release-elf.py +++ b/scripts/validate-release-elf.py @@ -49,6 +49,10 @@ PLUGIN_RUNPATH = ( "$ORIGIN/../../current/lib:" "$ORIGIN/lib" ) +FIRST_PARTY_LIBRARY_PATTERN = re.compile( + r"^(?:Echoion\.ts|libechoion-[A-Za-z0-9_.-]+\.so(?:\..*)?|" + r"libVoidTeamspeak\.so(?:\..*)?|libVoid_[A-Za-z0-9_.-]+\.so(?:\..*)?)$" +) def parse_version(value: str) -> tuple[int, ...]: @@ -113,6 +117,15 @@ def is_system_dependency(name: str) -> bool: return any(pattern.fullmatch(name) for pattern in SYSTEM_DEPENDENCIES) +def is_first_party_payload(path: Path, root: Path, plugin_files: set[Path]) -> bool: + if path in plugin_files or path.parent == root / "bin": + return True + return ( + path.parent == root / "lib" + and FIRST_PARTY_LIBRARY_PATTERN.fullmatch(path.name) is not None + ) + + def ensure_inside(path: Path, directory: Path, description: str) -> None: try: path.resolve(strict=True).relative_to(directory) @@ -181,7 +194,7 @@ def validate( root: Path, maximum_glibc: tuple[int, ...] | None = None, forbidden_content_prefixes: tuple[bytes, ...] = (), - require_debug_info: bool = False, + require_first_party_debug_info: bool = False, ) -> list[str]: executable = root / "bin/echoiond" updater = root / "bin/echoion-updater" @@ -226,13 +239,16 @@ def validate( re.MULTILINE, ): raise ValueError(f"{relative} is not an x86-64 ELF") - if require_debug_info: + if require_first_party_debug_info and is_first_party_payload( + path, root, plugin_files + ): sections = command_output(["readelf", "-SW", os.fspath(path)]) if re.search(r"\]\s+\.(?:z)?debug_info\s", sections) is None: raise ValueError( f"{relative} has no debug information; expected a " - "RelWithDebInfo artifact" + "first-party RelWithDebInfo artifact" ) + report.append(f"DEBUG\t{relative}\tFIRST_PARTY=verified") dynamic = command_output(["readelf", "-dW", os.fspath(path)]) runpaths = RUNPATH_PATTERN.findall(dynamic) if path in plugin_files: @@ -322,9 +338,13 @@ def main() -> int: parser.add_argument("--report", type=Path) parser.add_argument("--max-glibc", type=parse_version) parser.add_argument( - "--require-debug-info", + "--require-first-party-debug-info", action="store_true", - help="reject ELF payloads without DWARF debug information", + help=( + "reject Echoion, VoidLibrary, VoidTeamspeak, and bundled plugin " + "payloads without DWARF debug information; redistributed system " + "libraries are exempt" + ), ) parser.add_argument( "--forbid-content-prefix", @@ -347,12 +367,15 @@ def main() -> int: root, arguments.max_glibc, forbidden_content_prefixes, - arguments.require_debug_info, + arguments.require_first_party_debug_info, ) except (OSError, ValueError) as error: parser.error(str(error)) if arguments.report: write_report(report, arguments.report) + if arguments.require_first_party_debug_info: + verified = sum(line.startswith("DEBUG\t") for line in report) + print(f"verified debug information in {verified} first-party ELF files") else: print("\n".join(report)) return 0