libkernel: sendfile crashes with SIGSEGV on invalid memory pointers instead of returning EFAULT #13525

Closed
opened 2026-10-30 17:38:43 +00:00 by pushkarreddyy · 0 comments
pushkarreddyy commented 2026-10-30 17:38:43 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-30T17:38:43Z.


Environment

  • AnyPS5 commit: 556547da71 (current origin/main)
  • OS: Windows 11 / Linux x86_64

Summary

In core/libs/prx/libkernel/Socket/src/Udp.cpp, sendfile_nid_postfix directly reads guest pointer headers and its nested KernelIovec buffers, and directly writes to *sbytes = sent; without guest memory validation:

int APS5_VABI sendfile_nid_postfix(int file, int descriptor, std::int64_t offset, std::uint64_t length,
    const GuestSendfileHeaders* headers, std::int64_t* sbytes, int flags) {
    (void)flags;
    if (offset < 0) return Fail(22);
    if (headers && (!SendfileIovecs(headers->headers, headers->headerCount) || !SendfileIovecs(headers->trailers, headers->trailerCount)))
        return Fail(22);
    std::int64_t sent = 0;
    const auto finish = [&](int error) {
        if (sbytes) *sbytes = sent;
        return error ? Fail(error) : 0;
    };

When a guest title or runtime passes an unreadable headers struct, an unreadable KernelIovec array, or an unwritable sbytes buffer (0x10), sendfile_nid_postfix crashes the host process with a fatal SIGSEGV segmentation fault rather than returning EFAULT (14) per FreeBSD 11.4 sys_sendfile / kern_sendfile.

I am implementing a fix with safe guest copying via GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch, accompanying regression tests in GuestSendfile.cpp, and will submit a PR shortly.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6124048735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/13525). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-30T17:38:43Z. --- ### Environment - AnyPS5 commit: 556547da71 (current `origin/main`) - OS: Windows 11 / Linux x86_64 ### Summary In `core/libs/prx/libkernel/Socket/src/Udp.cpp`, `sendfile_nid_postfix` directly reads guest pointer `headers` and its nested `KernelIovec` buffers, and directly writes to `*sbytes = sent;` without guest memory validation: ```cpp int APS5_VABI sendfile_nid_postfix(int file, int descriptor, std::int64_t offset, std::uint64_t length, const GuestSendfileHeaders* headers, std::int64_t* sbytes, int flags) { (void)flags; if (offset < 0) return Fail(22); if (headers && (!SendfileIovecs(headers->headers, headers->headerCount) || !SendfileIovecs(headers->trailers, headers->trailerCount))) return Fail(22); std::int64_t sent = 0; const auto finish = [&](int error) { if (sbytes) *sbytes = sent; return error ? Fail(error) : 0; }; ``` When a guest title or runtime passes an unreadable `headers` struct, an unreadable `KernelIovec` array, or an unwritable `sbytes` buffer (`0x10`), `sendfile_nid_postfix` crashes the host process with a fatal `SIGSEGV` segmentation fault rather than returning `EFAULT` (`14`) per FreeBSD 11.4 `sys_sendfile` / `kern_sendfile`. I am implementing a fix with safe guest copying via `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch`, accompanying regression tests in `GuestSendfile.cpp`, and will submit a PR shortly.
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#13525
No description provided.