Open
Conversation
Replace the rtld_audit LD_AUDIT-based syscall interception with runtime ELF patching during mmap. When a PROT_EXEC segment is mapped, the shim now patches syscall instructions in-place and places trampoline stubs in a dynamically-allocated region near the code. Key changes: - Add patch_code_segment() public API to syscall rewriter for runtime use - Add ElfPatchState/ElfPatchCache for per-fd tracking of patch state - Add maybe_patch_exec_segment() called from do_mmap_file for PROT_EXEC - Add init_elf_patch_state() to parse ELF headers and detect pre-patched binaries via trampoline magic at file tail - Add finalize_elf_patch() on fd close to clean up trampoline mappings - Add reserve_trampoline parameter to ElfParsedFile::load() to bump brk past the runtime trampoline region for unpatched binaries - Add UnpatchedBinary error variant for loader trampoline parsing - Remove litebox_rtld_audit/ (C LD_AUDIT library) - Remove rtld_audit.so packaging from litebox_packager and runner crates - Remove LD_AUDIT environment variable injection from runners - Remove build.rs files that compiled rtld_audit.so
Mirror the linux shim's parse_trampoline/load_mapped pattern: tolerate UnpatchedBinary errors and reserve trampoline space for runtime patching.
Member
Author
|
This PR is ready for review. Thanks! |
|
🤖 SemverChecks 🤖 Click for details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the rtld_audit LD_AUDIT-based syscall interception with runtime ELF patching during mmap. When a PROT_EXEC segment is mapped, the shim now patches syscall instructions in-place and places trampoline stubs in a dynamically-allocated region near the code.
This is part of a series splitting PR #739 into independent PRs:
Key changes
patch_code_segment()public API to syscall rewriter for runtime useElfPatchState/ElfPatchCachefor per-fd tracking of patch statemaybe_patch_exec_segment()called fromdo_mmap_filefor PROT_EXEC segmentsinit_elf_patch_state()to parse ELF headers and detect pre-patched binaries via trampoline magic at file tailfinalize_elf_patch()on fd close to clean up trampoline mappingsreserve_trampolineparameter toElfParsedFile::load()to bump brk past the runtime trampoline regionUnpatchedBinaryerror variant for loader trampoline parsinglitebox_rtld_audit/(C LD_AUDIT library)Testing
All non-TUN tests pass locally (TUN tests require EPERM capabilities not available in dev environments).