Repository navigation
Conversation
fspy benchmarklinuxmacoswindows |
… stack sizing Harden ELF image validation and stack setup ahead of SIGSYS syscall virtualization: - Export fixed-address `--no-pie --image-base=...` link args from `fspy_elf_loader/build.rs` and consume them in the test launcher. - Add `validate_exec`, fallible ELF metadata mapping (`Mapping::try_file`), `PT_GNU_STACK` `PF_X` rejection, and stricter segment validation with unit tests in `image/tests.rs`. - Size the target process stack dynamically from `RLIMIT_STACK` (clamped to `[8 MiB, 64 MiB]`) with unit tests in `stack.rs`, and update `/proc/self/comm` via `PR_SET_NAME`. Co-authored-by: Gemini 4 Neon <noreply@google.com>
wan9chi
force-pushed
the
fspy-linux/2-elf-loader-validation-stack
branch
from
November 27, 2026 00:46
3a359d1 to
28f84bd
Compare
…ng them `validate_exec` returned `ENOEXEC` for images the kernel loads, and shells turn that into a confusing "cannot execute binary file" under `vp run` only. Match `binfmt_elf` instead: - An executable `PT_GNU_STACK` (e.g. objects without `.note.GNU-stack`, gcc nested-function trampolines) maps the target stack executable. The interpreter's `PT_GNU_STACK` is ignored. - Overlapping `PT_LOAD`s are accepted; a later `MAP_FIXED` wins. - A non-power-of-two `p_align` is ignored. - The first `PT_INTERP` is used; an `ET_EXEC` interpreter or one with its own `PT_INTERP` is accepted. - `AT_PHDR` comes from the `PT_LOAD` containing `e_phoff`, or the load bias when none does, instead of requiring the whole table to be mapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ons, and expand tests - Clamp padzero using other_start > start && other_start >= file_end so BSS extending past a higher-vaddr LOAD on the same page cannot wipe it without self-clamping zero-filesz segments. - Require the full program-header table (headers.end <= file_start + p_filesz) before computing AT_PHDR from a PT_LOAD segment, with unit tests for both. - Share LAUNCHER_REGION_X86_64 and LAUNCHER_REGION_AARCH64 from src/launcher_region.rs across build.rs, lib.rs, and launcher_image tests; export LAUNCHER_REGION and add rerun-if-changed directives in build.rs. - Replace RLIM_INFINITY signed cast with u64::MAX in stack.rs and simplify unreachable null-mmap handling in mapping.rs. - Expand exec_elf and runtime.c tests for rwxp stack verification, malformed ELF/PT_INTERP/entry/alignment rejections, AT_PLATFORM/AT_BASE_PLATFORM, 16-byte AT_RANDOM alignment, and argv/envp string contiguity. Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ader-validation-stack
Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ader-validation-stack
Co-authored-by: Gemini 4 Neon <noreply@google.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0452b6e. Configure here.
…segments Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ions Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ON with EEXIST Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ader-validation-stack
This branch has not been deployed
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.

Motivation
Before
fspy_elf_loadercan host aSIGSYSsyscall-virtualization runtime for arbitrary Linux executables, it needs fallible pre-exec ELF validation (so invalid executables returnENOEXECinstead of panicking inside the launcher), fixed high-address link-arg propagation for IP allowlisting,RLIMIT_STACK-aware stack sizing, and/proc/self/comminitialization matching kernelexecve.Changes
--no-pie --image-base=...link args fromfspy_elf_loader/build.rsvialinksmetadata and consume them infspy_elf_loader_test_launcher/build.rs.validate_exec, fallible ELF metadata mapping (Mapping::try_file),ET_DYNhigh-p_vaddrload-bias fixes, and segment validation that accepts what Linuxbinfmt_elfaccepts (an executablePT_GNU_STACKmaps the stack executable; overlapping loads, non-power-of-twop_align, andET_EXECinterpreters are allowed;AT_PHDRis computed as the kernel does), with unit tests inimage/tests.rs.RLIMIT_STACKviaprlimit64(clamped to[8 MiB, 64 MiB]) with unit tests instack.rs, and update/proc/self/commviaPR_SET_NAME.Stack created with GitHub Stacks CLI • Give Feedback 💬
Note
Medium Risk
Touches in-process ELF mapping, fixed-address reservations, and raw syscalls (
prlimit64,prctl) on the critical path to running untrusted executables; regressions would break launcher startup or memory layout rather than typical app logic.Overview
Adds
validate_execso callers can reject bad ELF/interpreter images (returningNOEXEC/EEXISTfor launcher-region overlap) without mapping segments or closing the fd — a prerequisite for pre-exec checks before the freestanding launcher jumps in.ELF handling is reworked toward Linux
binfmt_elfbehavior: fallible parsing/open viaBorrowedFd, separatevalidate_segmentsthenmap, acceptance of executablePT_GNU_STACK, overlapping loads, and highp_vaddrPIE bias without underflow;AT_PHDRand padzero clamping are tightened.exec_elfnow setsPR_SET_NAMEfromexecfn, sizes the target stack fromRLIMIT_STACK(clamped 8–64 MiB) with optional rwx stack, and centralizes freestanding launcher link placement viabuild.rslinksmetadata consumed byfspy_elf_loader_test_launcher. Integration/runtime tests cover malformed binaries, executable stacks, and auxv/stack layout expectations.Reviewed by Cursor Bugbot for commit d6d08a6. Bugbot is set up for automated code reviews on this repo. Configure here.