Skip to content

fix(libkernel): validate null pointers in pthread rwlock functions - #258

Open
Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/14108
Open

Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/14108

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#14108, originally opened by slopgobblercobbler.

Source commit: 55af236074006ee365696caacced8b7de3791e96. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

In core/libs/prx/libkernel/Pthread/Posix/Rwlock.cpp, passing a null PthreadRwlock* to initializeStatic or pthread_rwlock_destroy threw std::runtime_error("...: null rwlock"). In FreeBSD 11.4 (libthr/thread/thr_rwlock.c), passing a null rwlock pointer dereferences it and faults. Returning EINVAL (22) without dereferencing or crashing is a defensive host-safety fallback, with console behavior unmeasured.

Similarly, pthread_rwlockattr_init and pthread_rwlockattr_destroy return EINVAL (22) when passed a null PthreadRwlockattr* as a defensive host-safety fallback.

This change:

  1. Updates initializeStatic to return false on null rwlock, allowing caller POSIX functions (pthread_rwlock_rdlock, pthread_rwlock_timedrdlock, pthread_rwlock_wrlock, pthread_rwlock_timedwrlock, pthread_rwlock_reltimedrdlock_np, pthread_rwlock_reltimedwrlock_np, pthread_rwlock_tryrdlock, pthread_rwlock_trywrlock, pthread_rwlock_unlock) to return EINVAL (22).
  2. Updates pthread_rwlock_init and pthread_rwlock_destroy to return EINVAL when passed a null rwlock.
  3. Updates pthread_rwlockattr_init and pthread_rwlockattr_destroy to return EINVAL when passed a null attr.
  4. Adds unit test validation in core/libs/tests/GuestPthreadRwlock.cpp.
  5. Documents unmeasured console fault handling in docs/dev/debt/libkernel.md.

Tested

  • Tested on Windows 11 x86_64: guest_pthread_rwlock unit test passes.
  • Verified with python tools/check_conventions.py --base upstream/main --head HEAD: 0 findings.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants