]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup (gh...
authorSam Gross <colesbury@gmail.com>
Wed, 22 Apr 2026 18:59:58 +0000 (14:59 -0400)
committerGitHub <noreply@github.com>
Wed, 22 Apr 2026 18:59:58 +0000 (18:59 +0000)
commite5d554168337fc53f4fd5ff0dbeb7c3460ce80db
tree57e7697f9d25db8051be2c3f7330ccb977d9b312
parent5aa8234cce8b6746006b7d38f10763abf1393574
[3.14] gh-148820: Fix _PyRawMutex use-after-free on spurious semaphore wakeup (gh-148852) (#148884)

_PyRawMutex_UnlockSlow CAS-removes the waiter from the list and then
calls _PySemaphore_Wakeup, with no handshake. If _PySemaphore_Wait
returns Py_PARK_INTR, the waiter can destroy its stack-allocated
semaphore before the unlocker's Wakeup runs, causing a fatal error from
ReleaseSemaphore / sem_post.

Loop in _PyRawMutex_LockSlow until _PySemaphore_Wait returns Py_PARK_OK,
which is only signalled when a matching Wakeup has been observed.

Also include GetLastError() and the handle in the Windows fatal messages
in _PySemaphore_Init, _PySemaphore_Wait, and _PySemaphore_Wakeup to make
similar races easier to diagnose in the future.

(cherry picked from commit ad3c5b7958b890382f431a53349320cb7c84d405)
Misc/NEWS.d/next/Core_and_Builtins/2026-04-21-14-36-44.gh-issue-148820.XhOGhA.rst [new file with mode: 0644]
Python/lock.c
Python/parking_lot.c