fix(libkernel): fail madvise MADV_PROTECT with EPERM #3795

Closed
13hourstilliland wants to merge 1 commit from upstream-pr/3795 into main
13hourstilliland commented 2026-10-11 16:44:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-11T16:44:42Z.


What

madvise threw on MADV_PROTECT. It now fails with EPERM, as an unprivileged process does on FreeBSD 11.4. There, MADV_PROTECT is handled before the address and length checks and becomes PROC_SPROTECT. That call requires PRIV_VM_MADV_PROTECT. This keeps the same order, so an invalid range with MADV_PROTECT still gets EPERM. Whether PS5 titles hold that privilege isn't verified; it's noted in TechnicalDebt.

Tested

Linux (GCC 14.2): guest_memory checks that MADV_PROTECT returns -1 with errno 1 on a mapped page and on an out-of-range address. The test aborts on current main and passes with this change. check_conventions.py passes. Not tested with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820657284 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3795). Originally posted by [13hourstilliland](https://github.com/13hourstilliland) on 2026-10-11T16:44:42Z. --- ### What `madvise` threw on `MADV_PROTECT`. It now fails with `EPERM`, as an unprivileged process does on FreeBSD 11.4. There, `MADV_PROTECT` is handled [before the address and length checks](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/vm/vm_mmap.c#L700-L710) and becomes `PROC_SPROTECT`. That call [requires `PRIV_VM_MADV_PROTECT`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/kern_procctl.c#L114-L116). This keeps the same order, so an invalid range with `MADV_PROTECT` still gets `EPERM`. Whether PS5 titles hold that privilege isn't verified; it's noted in TechnicalDebt. ### Tested Linux (GCC 14.2): `guest_memory` checks that `MADV_PROTECT` returns -1 with errno 1 on a mapped page and on an out-of-range address. The test aborts on current `main` and passes with this change. `check_conventions.py` passes. Not tested with a title. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 16:47:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:47:19Z.


Progress report (11d9c00 → 0e00e27)

📈 System libraries: 86.23% (+0.03%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel madvise_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111330868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3795#issuecomment-6111330868). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T16:47:19Z. --- <!-- progress-report --> ### Progress report (11d9c00 → 0e00e27) 📈 **System libraries**: 86.23% (+0.03%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `madvise_nid_postfix` | </details>
oneandonlydean commented 2026-10-11 23:17:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:17:12Z.


Which title calls madvise with MADV_PROTECT? With the ID and the log line where it stops on main this can go in; otherwise I'll close it until one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115007374 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3795#issuecomment-6115007374). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:17:12Z. --- Which title calls `madvise` with `MADV_PROTECT`? With the ID and the log line where it stops on main this can go in; otherwise I'll close it until one does.
13hourstilliland commented 2026-10-12 07:36:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-12T07:36:16Z.


No title: I can't give a title ID or a log line where a title calls madvise with MADV_PROTECT — the change is FreeBSD-fidelity only (the PRIV_VM_MADV_PROTECT requirement mapped to an unprivileged EPERM), with a host test showing the errno on a mapped page.

If title evidence is the bar for this kind of turn, close it until a title calls it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119846772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3795#issuecomment-6119846772). Originally posted by [13hourstilliland](https://github.com/13hourstilliland) on 2026-10-12T07:36:16Z. --- No title: I can't give a title ID or a log line where a title calls `madvise` with `MADV_PROTECT` — the change is FreeBSD-fidelity only (the `PRIV_VM_MADV_PROTECT` requirement mapped to an unprivileged `EPERM`), with a host test showing the errno on a mapped page. If title evidence is the bar for this kind of turn, close it until a title calls it.
adriadam10 commented 2026-10-12 20:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:07:28Z.


Closing as agreed in the thread: @oneandonlydean asked which title calls madvise with MADV_PROTECT, and there is none, so the change has no consumer and whether PS5 titles hold PRIV_VM_MADV_PROTECT is unverified. The branch also conflicts with main now.

Feel free to reopen, rebased, once a title ID and the log line where it stops on main are available.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131753901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3795#issuecomment-6131753901). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:07:28Z. --- Closing as agreed in the thread: @oneandonlydean asked which title calls `madvise` with `MADV_PROTECT`, and there is none, so the change has no consumer and whether PS5 titles hold `PRIV_VM_MADV_PROTECT` is unverified. The branch also conflicts with `main` now. Feel free to reopen, rebased, once a title ID and the log line where it stops on `main` are available.

Pull request closed

Sign in to join this conversation.
No reviewers
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!3795
No description provided.