Commit ab35b9d
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 23e2a06 commit ab35b9d
1 file changed
+43
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
74 | 83 | | |
75 | 84 | | |
76 | 85 | | |
| |||
102 | 111 | | |
103 | 112 | | |
104 | 113 | | |
105 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
106 | 133 | | |
107 | 134 | | |
108 | 135 | | |
| |||
150 | 177 | | |
151 | 178 | | |
152 | 179 | | |
153 | | - | |
| 180 | + | |
154 | 181 | | |
155 | 182 | | |
156 | 183 | | |
157 | | - | |
158 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
159 | 188 | | |
160 | | - | |
| 189 | + | |
161 | 190 | | |
162 | 191 | | |
163 | | - | |
164 | | - | |
| 192 | + | |
| 193 | + | |
165 | 194 | | |
| 195 | + | |
166 | 196 | | |
167 | | - | |
| 197 | + | |
168 | 198 | | |
169 | 199 | | |
170 | 200 | | |
| |||
186 | 216 | | |
187 | 217 | | |
188 | 218 | | |
189 | | - | |
| 219 | + | |
190 | 220 | | |
191 | 221 | | |
192 | 222 | | |
| |||
196 | 226 | | |
197 | 227 | | |
198 | 228 | | |
| 229 | + | |
199 | 230 | | |
200 | 231 | | |
201 | 232 | | |
202 | 233 | | |
203 | 234 | | |
204 | | - | |
| 235 | + | |
205 | 236 | | |
206 | 237 | | |
207 | 238 | | |
208 | 239 | | |
209 | | - | |
| 240 | + | |
210 | 241 | | |
211 | 242 | | |
212 | 243 | | |
| |||
0 commit comments