fix(libkernel): validate null pointers in pthread rwlock functions #14108
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14108"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-31T19:12:59Z.
What
In
core/libs/prx/libkernel/Pthread/Posix/Rwlock.cpp, passing a nullPthreadRwlock*toinitializeStaticorpthread_rwlock_destroythrewstd::runtime_error("...: null rwlock"). In FreeBSD 11.4 (libthr/thread/thr_rwlock.c), passing a null rwlock pointer dereferences it and faults. ReturningEINVAL(22) without dereferencing or crashing is a defensive host-safety fallback, with console behavior unmeasured.Similarly,
pthread_rwlockattr_initandpthread_rwlockattr_destroyreturnEINVAL(22) when passed a nullPthreadRwlockattr*as a defensive host-safety fallback.This change:
initializeStaticto returnfalseon nullrwlock, 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 returnEINVAL(22).pthread_rwlock_initandpthread_rwlock_destroyto returnEINVALwhen passed a nullrwlock.pthread_rwlockattr_initandpthread_rwlockattr_destroyto returnEINVALwhen passed a nullattr.core/libs/tests/GuestPthreadRwlock.cpp.docs/dev/debt/libkernel.md.Tested
guest_pthread_rwlockunit test passes.python tools/check_conventions.py --base upstream/main --head HEAD: 0 findings.Checklist
Summary by CodeRabbit
EINVALinstead of triggering an exception.EINVAL, including when a deadline is provided. Calls with a null deadline continue to use the regular locking behavior.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T19:29:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation returns
EINVALfor null rwlock pointers, but the new debt entry incorrectly attributes that behavior to FreeBSD 11.4 and omits several changed functions.What I ran
Reviewed head
4b5bd21e5ed852f0da5823bbfe3d891d07ba8e3fagainst basee30f38577c79f16747eee745a145ff6b37a2dede; GitHub reports the PR mergeable. Environment: Linux 6.1.0-54-amd64, Python 3.11.2, GCC 12.2.0.Results
Unedited relevant precheck output
Findings
Blocking
pthread_rwlock_*pointers returnEINVAL“matching FreeBSD 11.4.” That is not what the cited implementation does:_pthread_rwlock_initwrites throughrwlock, and the lock helpers and destroy/unlock paths read through it before any null check. The newEINVALreturn is a defensive host-safety fallback, not reproduced FreeBSD behavior; console behavior is unmeasured. Please correct the debt entry and list all changed functions, including the timed, relative-timed, and try-lock variants. Also state that the code checks null pointers only; non-null invalid pointers are not validated.Non-blocking
Sources
thr_rwlock.c, pinned commitNot verified
I did not run the test binary locally or test a PS5 console. The Windows CI job passed; Linux, relinker, and sanitizer product jobs were skipped by path eligibility.
To get this to a good state
Describe
EINVALas a defensive host-safety fallback, mark console behavior unmeasured, and list the complete set of changed functions and the null-only validation scope. I will re-check the same source and checks on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T19:49:00Z.
Review: APPROVED
Re-checked — new head, looks good
The revised debt entry resolves the documentation findings; I found no new blocker in the updated head.
What I ran
Reviewed head
e3b1036a900474c59ae37b9fb32af462c7e870adagainst basee30f38577c79f16747eee745a145ff6b37a2dede; GitHub reported the PR mergeable. The precheck ran on Linux 6.1.0-54-amd64 with Python 3.11.2 and GCC 12.2.0. No local C++ build or test was run.Results
Unedited relevant output
Findings
Blocking
None.
Non-blocking
None identified.
Sources
Not verified
I did not build or run tests locally. Linux product tests, specialized jobs, console behavior, and the local ABI/test-quality helper checks remain unverified.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T05:37:04Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the reviewed documentation change blocks merge; the entry accurately describes the stated null-pointer fallback and unmeasured console behavior.
What I ran
Read the prepared review materials for head
3385df150895b96c763650fdf78bc3526274f412and the changed documentation at that head. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The implementation and unit tests are excluded from this review by rule:
core/libs/prx/libkernel/Pthread/Posix/Rwlock.cppandcore/libs/tests/GuestPthreadRwlock.cpp. Their behavior and the author-reported Windows test and convention check were not verified. The only changed file listed in the manifest as reviewed wasdocs/dev/debt/libkernel.md; its added line was read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T00:07:36Z.
Review: COMMENTED
Reviewed — no blocking findings
The documentation change accurately records the stated defensive null-pointer behavior and its unmeasured console behavior.
What I ran
Reviewed head
861d61cb1bdc897252567fc153e2889e9a2302e6. I read the prepared description, commits, manifest and diff, then inspected the changed documentation and the referenced rwlock implementation and relevant test assertions throughrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The manifest identifies only
docs/dev/debt/libkernel.mdas reviewed. The implementation and test files named in the description were excluded from the prepared diff by rule; targeted portions were read at the pinned head, but their full contents were not reviewed. The unit test and convention check were not run, and console behavior remains unmeasured as documented.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T04:56:07Z.
Review: APPROVED
Reviewed — looks good
The documentation change records the null pointer behavior and its stated limits; the changed line agrees with the inspected implementation.
What I ran
55af236074006ee365696caacced8b7de3791e96usingrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libkernel/Pthread/Posix/Rwlock.cppandcore/libs/tests/GuestPthreadRwlock.cppare excluded from the prepared diff by review rule. I inspected their pinned-head contents throughrepo_read.pyto check the changed documentation's claims, but did not review their changes as diff hunks.files.jsonwas unavailable in the prepared review folder; the exclusion note indescription.mdidentifies the two excluded files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T10:30:02Z.
Review: COMMENTED
Actionable comments
038991e7-4c57-4daf-aeb9-f28bd395edf5Reviewing files that changed from the base of the PR and between
c3a823624fand5123fe1f16.core/libs/prx/libkernel/Pthread/Posix/Rwlock.cppcore/libs/tests/GuestKernelRwlockattrBounds.cppcore/libs/tests/GuestPthreadRwlock.cppdocs/dev/debt/libkernel.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T10:56:23Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this documentation change; the FreeBSD 11.4 source claim remains unverified.
What I ran
Reviewed head
5123fe1f16eb48c476f94674fbb3737c5b28cac0. I read the changed documentation and inspected the corresponding rwlock implementation at the pinned head. No tests or builds were run.Results
Negative control
Not run; no test was run.
Findings
Blocking
None.
Non-blocking
docs/dev/debt/libkernel.md:377says FreeBSD 11.4 faults on a null rwlock dereference. I could not verify that external source claim during this review.Sources
EINVALfor null pointers.Not verified
The FreeBSD 11.4 behavior cited in the changed entry and console behavior were not verified. Reviewed:
docs/dev/debt/libkernel.md. Read for source context:core/libs/prx/libkernel/Pthread/Posix/Rwlock.cpp. Excluded by the review rule and not read:core/libs/tests/GuestKernelRwlockattrBounds.cpp,core/libs/tests/GuestPthreadRwlock.cpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:00:58Z.
Review: COMMENTED
I built and ran the branch's
GuestPthreadRwlockandGuestKernelRwlockattrBoundsfixtures on Linux against the existing runtime libraries. Both passed, covering the ordinary lock lifecycle and the argument and attribute checks.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.