Verify debug info for first-party release binaries
This commit is contained in:
3 files changed
+57
-12
No files matched your search
+1
-1
@@ -480,7 +480,7 @@ elf_validation_args=(
|
|||||||
--root "$stage"
|
--root "$stage"
|
||||||
--report "$dependency_report"
|
--report "$dependency_report"
|
||||||
--max-glibc 2.35
|
--max-glibc 2.35
|
||||||
--require-debug-info
|
--require-first-party-debug-info
|
||||||
--forbid-content-prefix "$source_dir"
|
--forbid-content-prefix "$source_dir"
|
||||||
--forbid-content-prefix "$build_dir"
|
--forbid-content-prefix "$build_dir"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ if [[ $# != 1 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
source_root=$(realpath -e -- "$1")
|
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 || {
|
command -v "$command_name" >/dev/null || {
|
||||||
echo "missing test command: $command_name" >&2
|
echo "missing test command: $command_name" >&2
|
||||||
exit 2
|
exit 2
|
||||||
@@ -93,7 +93,7 @@ for variant in preferred other; do
|
|||||||
preferred) variant_lib=$preferred_lib ;;
|
preferred) variant_lib=$preferred_lib ;;
|
||||||
other) variant_lib=$other_lib ;;
|
other) variant_lib=$other_lib ;;
|
||||||
esac
|
esac
|
||||||
"$c_compiler" -fPIC -shared "$temporary/dependency.c" \
|
"$c_compiler" -g -fPIC -shared "$temporary/dependency.c" \
|
||||||
'-DECHOION_VARIANT="'"$variant"'-runtime"' \
|
'-DECHOION_VARIANT="'"$variant"'-runtime"' \
|
||||||
-Wl,-soname,libechoion-dependency.so.1 \
|
-Wl,-soname,libechoion-dependency.so.1 \
|
||||||
-o "$variant_lib/libechoion-dependency.so.1.2.3"
|
-o "$variant_lib/libechoion-dependency.so.1.2.3"
|
||||||
@@ -121,7 +121,7 @@ for variant in seeded resolver; do
|
|||||||
"$variant_lib/libstdc++.so.6"
|
"$variant_lib/libstdc++.so.6"
|
||||||
done
|
done
|
||||||
resolver_core="$resolver/Echoion.ts"
|
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 \
|
-L"$preferred_lib" -lechoion-dependency \
|
||||||
-Wl,-l:libstdc++.so.6 \
|
-Wl,-l:libstdc++.so.6 \
|
||||||
-Wl,-soname,Echoion.ts \
|
-Wl,-soname,Echoion.ts \
|
||||||
@@ -130,11 +130,11 @@ resolver_core="$resolver/Echoion.ts"
|
|||||||
install -m 0644 "$resolver_core" "$bundle/lib/Echoion.ts"
|
install -m 0644 "$resolver_core" "$bundle/lib/Echoion.ts"
|
||||||
patchelf --set-rpath "\$ORIGIN" "$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"
|
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 \
|
-L"$preferred_lib" -lechoion-dependency \
|
||||||
-Wl,-rpath,"$preferred_lib" \
|
-Wl,-rpath,"$preferred_lib" \
|
||||||
-o "$bundle_plugin"
|
-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"
|
install -m 0755 "$bundle/bin/echoiond" "$bundle/bin/echoion-updater"
|
||||||
printf '%s\n' '[Service]' >"$bundle/service/echoion.service.in"
|
printf '%s\n' '[Service]' >"$bundle/service/echoion.service.in"
|
||||||
printf '%s\n' '<!doctype html><title>Echoion</title>' \
|
printf '%s\n' '<!doctype html><title>Echoion</title>' \
|
||||||
@@ -176,6 +176,18 @@ assert module.is_system_dependency("libc.so.6")
|
|||||||
assert module.is_system_dependency("libm.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("libc.so.evil")
|
||||||
assert not module.is_system_dependency("libm.so.99")
|
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 = """
|
unknown_abi = """
|
||||||
Version needs section '.gnu.version_r' contains 1 entry:
|
Version needs section '.gnu.version_r' contains 1 entry:
|
||||||
@@ -222,6 +234,16 @@ fi
|
|||||||
report="$temporary/dependencies.txt"
|
report="$temporary/dependencies.txt"
|
||||||
python3 "$source_root/scripts/validate-release-elf.py" \
|
python3 "$source_root/scripts/validate-release-elf.py" \
|
||||||
--root "$bundle" --max-glibc 2.35 --report "$report"
|
--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" \
|
if python3 "$source_root/scripts/validate-release-elf.py" \
|
||||||
--root "$bundle" \
|
--root "$bundle" \
|
||||||
--forbid-content-prefix /tmp/echoion-forbidden-build-path \
|
--forbid-content-prefix /tmp/echoion-forbidden-build-path \
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ PLUGIN_RUNPATH = (
|
|||||||
"$ORIGIN/../../current/lib:"
|
"$ORIGIN/../../current/lib:"
|
||||||
"$ORIGIN/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, ...]:
|
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)
|
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:
|
def ensure_inside(path: Path, directory: Path, description: str) -> None:
|
||||||
try:
|
try:
|
||||||
path.resolve(strict=True).relative_to(directory)
|
path.resolve(strict=True).relative_to(directory)
|
||||||
@@ -181,7 +194,7 @@ def validate(
|
|||||||
root: Path,
|
root: Path,
|
||||||
maximum_glibc: tuple[int, ...] | None = None,
|
maximum_glibc: tuple[int, ...] | None = None,
|
||||||
forbidden_content_prefixes: tuple[bytes, ...] = (),
|
forbidden_content_prefixes: tuple[bytes, ...] = (),
|
||||||
require_debug_info: bool = False,
|
require_first_party_debug_info: bool = False,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
executable = root / "bin/echoiond"
|
executable = root / "bin/echoiond"
|
||||||
updater = root / "bin/echoion-updater"
|
updater = root / "bin/echoion-updater"
|
||||||
@@ -226,13 +239,16 @@ def validate(
|
|||||||
re.MULTILINE,
|
re.MULTILINE,
|
||||||
):
|
):
|
||||||
raise ValueError(f"{relative} is not an x86-64 ELF")
|
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)])
|
sections = command_output(["readelf", "-SW", os.fspath(path)])
|
||||||
if re.search(r"\]\s+\.(?:z)?debug_info\s", sections) is None:
|
if re.search(r"\]\s+\.(?:z)?debug_info\s", sections) is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"{relative} has no debug information; expected a "
|
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)])
|
dynamic = command_output(["readelf", "-dW", os.fspath(path)])
|
||||||
runpaths = RUNPATH_PATTERN.findall(dynamic)
|
runpaths = RUNPATH_PATTERN.findall(dynamic)
|
||||||
if path in plugin_files:
|
if path in plugin_files:
|
||||||
@@ -322,9 +338,13 @@ def main() -> int:
|
|||||||
parser.add_argument("--report", type=Path)
|
parser.add_argument("--report", type=Path)
|
||||||
parser.add_argument("--max-glibc", type=parse_version)
|
parser.add_argument("--max-glibc", type=parse_version)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--require-debug-info",
|
"--require-first-party-debug-info",
|
||||||
action="store_true",
|
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(
|
parser.add_argument(
|
||||||
"--forbid-content-prefix",
|
"--forbid-content-prefix",
|
||||||
@@ -347,12 +367,15 @@ def main() -> int:
|
|||||||
root,
|
root,
|
||||||
arguments.max_glibc,
|
arguments.max_glibc,
|
||||||
forbidden_content_prefixes,
|
forbidden_content_prefixes,
|
||||||
arguments.require_debug_info,
|
arguments.require_first_party_debug_info,
|
||||||
)
|
)
|
||||||
except (OSError, ValueError) as error:
|
except (OSError, ValueError) as error:
|
||||||
parser.error(str(error))
|
parser.error(str(error))
|
||||||
if arguments.report:
|
if arguments.report:
|
||||||
write_report(report, 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:
|
else:
|
||||||
print("\n".join(report))
|
print("\n".join(report))
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in new issue
Block a user