Add PIE kernel-assigned base address loading, fix exit status#344
Open
Ebola-Chan-bot wants to merge 1 commit intotermux:masterfrom
Open
Add PIE kernel-assigned base address loading, fix exit status#344Ebola-Chan-bot wants to merge 1 commit intotermux:masterfrom
Ebola-Chan-bot wants to merge 1 commit intotermux:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates PRoot’s in-tracee loader script format and loader implementation to better support PIE binaries by letting the kernel choose a safe base address, and fixes exit-status reporting so cleanup-killed child tracees don’t override the main process’ exit code.
Changes:
- Emit PIE-specific load actions for exec/interpreter mappings and detect PIE via
IS_POSITION_INDENPENDANT(...). - Implement PIE base selection and relocation deltas in the loader, adjusting entry/auxv addresses accordingly and separating exec vs interpreter deltas.
- Ensure signaled termination exit codes are only derived from the root tracee (vpid 1).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tracee/event.c | Prevent child tracees terminated by signals during cleanup from overwriting PRoot’s final exit status. |
| src/loader/script.h | Add new load script action IDs for PIE kernel-chosen-base mapping variants. |
| src/loader/loader.c | Add handling for PIE mmap variants, compute/apply pic_delta, and adjust auxv/entry targets at START. |
| src/execve/exit.c | Thread PIE detection into load-script emission so loader can apply PIE-aware mapping strategy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
exit.c: - Add is_pic parameter to transcript_mappings() to emit PIE action variants (LOAD_ACTION_MMAP_PIC_FILE / LOAD_ACTION_MMAP_PIC_ANON) for position-independent executables and interpreters. - Detect PIE via IS_POSITION_INDENPENDANT and pass the flag through to transcript_mappings() for both executable and interpreter. loader.c: - LOAD_ACTION_MMAP_PIC_FILE: first segment uses mmap(addr=0) to let the kernel choose a conflict-free base address, computes pic_delta from the difference; subsequent segments use MAP_FIXED at delta-adjusted addresses. - LOAD_ACTION_MMAP_PIC_ANON: same kernel-assigned base logic for anonymous mappings. - START action: apply pic_delta to entry_point, at_phdr, at_entry so auxv and branch target reflect actual load addresses. - Track exec_pic_delta separately via OPEN_NEXT so interpreter and executable deltas don't interfere. script.h: - Define LOAD_ACTION_MMAP_PIC_FILE (7) and LOAD_ACTION_MMAP_PIC_ANON (8). event.c: - Fix WIFSIGNALED: only set last_exit_status for the root tracee (vpid 1). Child tracees killed during cleanup (e.g. SIGKILL after root exits) previously overwrote it, causing proot to incorrectly return exit code 137.
1741a0f to
76d5d8d
Compare
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.
This PR deprecated the high-risk mmap method using hardcoded addresses and instead requested a physically available address from the kernel. Addresses hardcoded before this may be preempted by the kernel, resulting in mmap failures like 182.
exit.c:
loader.c:
script.h:
event.c:
Probably an elegent and final fix of #12, instead of a workaround