Repository navigation
Return EFAULT instead of crashing on an unreadable path name - #12
Merged
linuxkid473 merged 1 commit intoNov 10, 2026
Merged
Conversation
bsd() read a path argument with CStr::from_ptr on the guest's pointer. A name the guest cannot read (NULL-adjacent, unmapped, PROT_NONE, or running into an unmapped page before its NUL) therefore crashed the runtime with SIGSEGV/SIGBUS, where macOS returns EFAULT from the call. Read the name with guestmem::read, in pieces that stop at each 4 KiB boundary, so a name that ends just before an unmapped page is still read, up to 8 KiB. If any byte before the NUL cannot be read, or no NUL comes within 8 KiB, the call is passed to the host kernel unchanged, which returns the appropriate error (EFAULT for an unreadable name). tests/guest/bad_name_pointers.c checks seven rows (open, openat, stat, access on an unreadable page, an unmapped address, a name running into an unreadable page, and, as a no-crash control, a name ending just before one) against the native answers. A row whose child process cannot be forked or reaped counts as a failure. The read up to the boundary itself is covered by the unit tests.
This was referenced Nov 23, 2026
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.
When an arm64 program passes a path name that the runtime cannot read (an unmapped address, a PROT_NONE page, or a name whose bytes run into an unmapped page before the NUL), Maclator currently crashes with SIGSEGV or SIGBUS. On macOS the same call simply fails with
EFAULT. This PR makes the translated call behave like the native one, so a stray pointer in one call no longer takes the whole program down.Cause
bsd()reads the path argument of path-taking calls (open,openat,stat,access, ...) withcstr_at, which callsCStr::from_ptrdirectly on the guest's pointer. The kernel never sees the call, because the runtime faults first.Change
guest_cstrhelper reads the name withguestmem::read, the fault-safe copy the runtime already uses for other guest memory. It reads in pieces that stop at each 4 KiB boundary, so a name that ends just before an unmapped page is still read correctly, and it stops at 8 KiB (well aboveMAXPATHLEN).bsd()passes the call to the host kernel unchanged and lets it return the appropriate error (EFAULTfor an unreadable name). The existing path handling is untouched for every readable name up to that limit.Two files:
crates/maclator/src/syscalls.rs(+75 -2, including two unit tests for the helper) and the new guest testtests/guest/bad_name_pointers.c.Testing
tests/guest/bad_name_pointers.cruns seven rows, each in its own child process so a crash shows up as that row's failure:open,openat,statandaccesson a PROT_NONE page,openon an unmapped address, a name running into a PROT_NONE page, and a name whose NUL is the last readable byte before one (a no-crash control; the read up to the boundary itself is covered by the unit tests). A row whose child cannot be forked or reaped counts as a failure, never a pass.main(debddd6)The unit tests pass (
cargo test -p maclator, 10 passed), and so does the workspace. As a regression check,tests/guest/hello.c,forktest.c,thread_create.candtimer.c, plus a small program doinguname,sysctlbyname,statandopenthrough libc, print byte-identical output undermainand under this change.Test setup, to be clear about its limits: an Apple Silicon Mac, running the x86_64 Maclator build under Rosetta 2, with a macOS 26.6.2 (25G83) arm64e shared cache as the sysroot and dyld from 26.7.1,
--no-aot. I have not yet run it on an Intel host.Not in this PR
sysctlbynameandsysctlread their name or MIB the same way and crash the same way on an unreadable pointer. I have a separate small follow-up for those that reuses this helper's approach, and will open it after this one if it is welcome. Separately, the sysctl output helpers (write_sysctl_str,write_sysctl_int) still read and write the guest'soldpandoldlenpdirectly, so a bad output pointer can still crash; that would be a later, equally small change.