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

From Michael Paquier
Subject pgsql: Fix possible double-release of spinlock in procsignal.c
Date
Msg-id E1tnS1s-000GPv-2U@gemulon.postgresql.org
Whole thread Raw
List 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.melnikov@postgrespro.ru>
Co-authored-by: Maxim Orlov <orlovmg@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.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(-)


pgsql-committers by date:

Previous
From: Jeff Davis
Date:
Subject: pgsql: Remove stray diff introduced by a5cbdeb98a.
Next
From: Michael Paquier
Date:
Subject: pgsql: Refactor code of pg_stat_get_wal() building result tuple