Commit 18a4a62
committed
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 969d7cd 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.us1 parent b8f2687 commit 18a4a62
1 file changed
+44
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
84 | 94 | | |
85 | 95 | | |
86 | 96 | | |
| |||
142 | 152 | | |
143 | 153 | | |
144 | 154 | | |
145 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
146 | 174 | | |
147 | 175 | | |
148 | 176 | | |
| |||
218 | 246 | | |
219 | 247 | | |
220 | 248 | | |
221 | | - | |
| 249 | + | |
222 | 250 | | |
223 | 251 | | |
224 | 252 | | |
225 | | - | |
226 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
227 | 257 | | |
228 | | - | |
| 258 | + | |
229 | 259 | | |
230 | 260 | | |
231 | | - | |
232 | | - | |
| 261 | + | |
| 262 | + | |
233 | 263 | | |
| 264 | + | |
234 | 265 | | |
235 | | - | |
| 266 | + | |
236 | 267 | | |
237 | 268 | | |
238 | 269 | | |
| |||
254 | 285 | | |
255 | 286 | | |
256 | 287 | | |
257 | | - | |
| 288 | + | |
258 | 289 | | |
259 | 290 | | |
260 | 291 | | |
| |||
264 | 295 | | |
265 | 296 | | |
266 | 297 | | |
| 298 | + | |
267 | 299 | | |
268 | 300 | | |
269 | 301 | | |
270 | 302 | | |
271 | 303 | | |
272 | | - | |
| 304 | + | |
273 | 305 | | |
274 | 306 | | |
275 | 307 | | |
276 | 308 | | |
277 | | - | |
| 309 | + | |
278 | 310 | | |
279 | 311 | | |
280 | 312 | | |
| |||
0 commit comments