libkernel: sendmsg on guest memory it cannot read crashes the host instead of failing with EFAULT #8462

Closed
opened 2026-10-20 13:03:40 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-20 13:03:40 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T13:03:40Z.


Repro

Windows host. sendmsg(s, (const msghdr*)0x1000, 0), or a valid header whose iov, an iovec base or name points to unmapped or PROT_NONE memory.
Expected (FreeBSD 11.4): EFAULT (14): sys_sendmsg copies the header, copyiniov the iovec array, getsockaddr the name and uiomove the buffers with copyin.
Actual: the host takes an access violation (0xc0000005) in sendmsg_nid_postfix, which reads all four from guest memory directly. recvmsg already fails with EFAULT (#7675).
Test: guest_sendmsg_memory (mode sendmsg-memory of guest_socket_pair_tests, new); crashes before the fix.
Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sendmsg-guest-memory-efault
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5942138663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8462). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T13:03:40Z. --- ### Repro Windows host. `sendmsg(s, (const msghdr*)0x1000, 0)`, or a valid header whose `iov`, an iovec `base` or `name` points to unmapped or `PROT_NONE` memory. Expected (FreeBSD 11.4): EFAULT (14): `sys_sendmsg` copies the header, `copyiniov` the iovec array, `getsockaddr` the name and `uiomove` the buffers with `copyin`. Actual: the host takes an access violation (0xc0000005) in `sendmsg_nid_postfix`, which reads all four from guest memory directly. `recvmsg` already fails with EFAULT (#7675). Test: `guest_sendmsg_memory` (mode `sendmsg-memory` of `guest_socket_pair_tests`, new); crashes before the fix. Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/sendmsg-guest-memory-efault AI-assisted (Claude Code).
Filip722 commented 2026-10-21 09:45:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T09:45:56Z.


Confirmed on Linux: unreadable guest inputs to sendmsg terminate the process with SIGSEGV, rather than returning EFAULT.

Tested unchanged upstream main b5d763770a8e932b35db9bea1c415e7e0ac50a22 in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, ANYPS5_USE_SYSTEM_DEPS=OFF; rebuilt libc, libkernel and libkernel_sys. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes.

Reproduction: a temporary probe reused the layouts and guest-memory setup from GuestSocketPair.cpp: socketpair_nid_postfix(1, 2, 0, pair) and a 48-byte guest msghdr. For each input below I launched a separate process and called sendmsg_nid_postfix(pair[0], message, 0). The inaccessible page was allocated with sceKernelMapFlexibleMemory and protected with sceKernelMprotect(..., 0); the other bad address was 0x1000. Core dumps were disabled.

Unreadable input 0x1000 Guest page with protection 0
message header SIGSEGV SIGSEGV
iovec array SIGSEGV SIGSEGV
first iovec's 2-byte payload SIGSEGV SIGSEGV
16-byte destination name SIGSEGV SIGSEGV

All eight children reached the marker immediately before the call and exited from signal 11 (Python subprocess return code -11), without returning a guest errno. A debugger run of the header case confirms the affected path:

Program received signal SIGSEGV
#0 MessageLength()        from libkernel.prx
#1 sendmsg_nid_postfix()  from libkernel.prx
#2 main()

Positive controls: a valid message sent/received ok (2 bytes); a payload on a guest page protected read-only sent/received ro (2 bytes). Existing guest_socket_pair and guest_recvmsg_memory pass, so the receive-side protection test passing does not establish send-side safety.

Scope: unchanged-main reproduction only; #8463's checked-read implementation was not applied/tested. No second-iovec, racing unmap, ancillary-data, console, Windows, GPU or title testing claimed.

AI-assisted: yes (Codex); I am responsible for the reported investigation and results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312973383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8462#issuecomment-6312973383). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-21T09:45:56Z. --- Confirmed on Linux: unreadable guest inputs to `sendmsg` terminate the process with `SIGSEGV`, rather than returning `EFAULT`. Tested unchanged upstream `main` **`b5d763770a8e932b35db9bea1c415e7e0ac50a22`** in a separate validation checkout. Environment: Debian GNU/Linux 13.7 (trixie), x86-64, kernel `7.2.9-x64v3-xanmod1`, AMD Ryzen 5 7640HS, GCC/G++ 15.2.0, CMake 3.31.6/Ninja. Full project configuration: `Release`, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, `ANYPS5_USE_SYSTEM_DEPS=OFF`; rebuilt `libc`, `libkernel` and `libkernel_sys`. Temporary probes linked directly to these freshly built, unpatched runtime libraries, as the repository runtime tests do. No production source changes. Reproduction: a temporary probe reused the layouts and guest-memory setup from `GuestSocketPair.cpp`: `socketpair_nid_postfix(1, 2, 0, pair)` and a 48-byte guest `msghdr`. For each input below I launched a separate process and called `sendmsg_nid_postfix(pair[0], message, 0)`. The inaccessible page was allocated with `sceKernelMapFlexibleMemory` and protected with `sceKernelMprotect(..., 0)`; the other bad address was `0x1000`. Core dumps were disabled. | Unreadable input | `0x1000` | Guest page with protection 0 | |---|---|---| | message header | SIGSEGV | SIGSEGV | | iovec array | SIGSEGV | SIGSEGV | | first iovec's 2-byte payload | SIGSEGV | SIGSEGV | | 16-byte destination name | SIGSEGV | SIGSEGV | All eight children reached the marker immediately before the call and exited from signal 11 (Python subprocess return code `-11`), without returning a guest errno. A debugger run of the header case confirms the affected path: ```text Program received signal SIGSEGV #0 MessageLength() from libkernel.prx #1 sendmsg_nid_postfix() from libkernel.prx #2 main() ``` Positive controls: a valid message sent/received `ok` (2 bytes); a payload on a guest page protected read-only sent/received `ro` (2 bytes). Existing `guest_socket_pair` and `guest_recvmsg_memory` pass, so the receive-side protection test passing does not establish send-side safety. Scope: unchanged-main reproduction only; #8463's checked-read implementation was not applied/tested. No second-iovec, racing unmap, ancillary-data, console, Windows, GPU or title testing claimed. AI-assisted: yes (Codex); I am responsible for the reported investigation and results.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#8462
No description provided.