From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Harden pmsignal.c against clobbered shared memory. |
Date: | 2022-10-11 22:54:50 |
Message-ID: | E1oiO9C-001xws-3d@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Harden pmsignal.c against clobbered shared memory.
The postmaster is not supposed to do anything that depends
fundamentally on shared memory contents, because that creates
the risk that a backend crash that trashes shared memory will
take the postmaster down with it, preventing automatic recovery.
In commit 969d7cd43 I lost sight of this principle and coded
AssignPostmasterChildSlot() in such a way that it could fail
or even crash if the shared PMSignalState structure became
corrupted. Remarkably, we've not seen field reports of such
crashes; but I managed to induce one while testing the recent
changes around palloc chunk headers.
To fix, make a semi-duplicative state array inside the postmaster
so that we need consult only local state while choosing a "child
slot" for a new backend. Ensure that other postmaster-executed
routines in pmsignal.c don't have critical dependencies on the
shared state, either. Corruption of PMSignalState might now
lead ReleasePostmasterChildSlot() to conclude that backend X
failed, when actually backend Y was the one that trashed things.
But that doesn't matter, because we'll force a cluster-wide reset
regardless.
Back-patch to all supported branches, since this is an old bug.
Discussion: https://postgr.es/m/3436789.1665187055@sss.pgh.pa.us
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/6c1de98bad93b6f12b5002b40c4a0cbd3adeafdb
Modified Files
--------------
src/backend/storage/ipc/pmsignal.c | 55 +++++++++++++++++++++++++++++---------
1 file changed, 43 insertions(+), 12 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2022-10-11 23:52:19 | pgsql: Fix compilation warning in test_copy_callbacks |
Previous Message | Andres Freund | 2022-10-11 22:42:21 | Re: pgsql: Add support for COPY TO callback functions |