pgsql: Fix possible double-release of spinlock in procsignal.c

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix possible double-release of spinlock in procsignal.c
Date: 2025-02-27 00:45:34
Message-ID: E1tnS1s-000GPv-2U@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix possible double-release of spinlock in procsignal.c

9d9b9d46f3c5 has added spinlocks to protect the fields in ProcSignal
flags, introducing a code path in ProcSignalInit() where a spinlock
could be released twice if the pss_pid field of a ProcSignalSlot is
found as already set. Multiple spinlock releases have no effect with
most spinlock implementations, but this could cause the code to run into
issues when the spinlock is acquired concurrently by a different
process.

This sanity check on pss_pid generates a LOG that can be delayed until
after the spinlock is released as, like older versions up to v17, the
code expects the initialization of the ProcSignalSlot to happen even if
pss_pid is found incorrect. The code is changed so as the old pss_pid
is read while holding the slot's spinlock, with the LOG from the sanity
check generated after releasing the spinlock, preventing the double
release.

Author: Maksim Melnikov <m(dot)melnikov(at)postgrespro(dot)ru>
Co-authored-by: Maxim Orlov <orlovmg(at)gmail(dot)com>
Reviewed-by: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Discussion: https://postgr.es/m/dca47527-2d8b-4e3b-b5a0-e2deb73371a4@postgrespro.ru

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/62ec3e1f6786181431210643a2d427b9a98b8af8

Modified Files
--------------
src/backend/storage/ipc/procsignal.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-02-27 02:54:57 pgsql: Refactor code of pg_stat_get_wal() building result tuple
Previous Message Jeff Davis 2025-02-26 21:38:54 pgsql: Remove stray diff introduced by a5cbdeb98a.