forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit80ef926
committed
Improve our ability to detect bogus pointers passed to pfree et al.
Commitc6e0fe1 was a shade too trusting that any pointer passedto pfree, repalloc, etc will point at a valid chunk. Notably,passing a pointer that was actually obtained from malloc tendedto result in obscure assertion failures, if not worse. (On FreeBSDI've seen such mistakes take down the entire cluster, seemingly asa result of clobbering shared memory.)To improve matters, extend the mcxt_methods[] array so that ithas entries for every possible MemoryContextMethodID bit-pattern,with the currently unassigned ID codes pointing to error-reportingfunctions. Then, fiddle with the ID assignments so that patternslikely to be associated with bad pointers aren't valid ID codes.In particular, we should avoid assigning bit patterns 000 (zeroedmemory) and 111 (wipe_mem'd memory).It turns out that on glibc (Linux), malloc uses chunk headers thathave flag bits in the same place we keep MemoryContextMethodID,and that the bit patterns 000, 001, 010 are the only ones we'llsee as long as the backend isn't threaded. So we can have veryrobust detection of pfree'ing a malloc-assigned block on thatplatform, at least so long as we can refrain from using up thoseID codes. On other platforms, we don't have such a good guarantee,but keeping 000 reserved will be enough to catch many such cases.While here, make GetMemoryChunkMethodID() local to mcxt.c, as thereseems no need for it to be exposed even in memutils_internal.h.Patch by me, with suggestions from Andres Freund and David Rowley.Discussion:https://postgr.es/m/2910981.1665080361@sss.pgh.pa.us1 parente555565 commit80ef926
File tree
2 files changed
+124
-28
lines changed- src
- backend/utils/mmgr
- include/utils
2 files changed
+124
-28
lines changedLines changed: 110 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
32 | 32 |
| |
33 | 33 |
| |
34 | 34 |
| |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 |
| |
36 | 41 |
| |
37 | 42 |
| |
| |||
74 | 79 |
| |
75 | 80 |
| |
76 | 81 |
| |
77 |
| - | |
| 82 | + | |
78 | 83 |
| |
79 |
| - | |
| 84 | + | |
80 | 85 |
| |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
81 | 118 |
| |
82 | 119 |
| |
83 | 120 |
| |
| |||
125 | 162 |
| |
126 | 163 |
| |
127 | 164 |
| |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
128 | 236 |
| |
129 | 237 |
| |
130 | 238 |
| |
|
Lines changed: 14 additions & 26 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
74 | 74 |
| |
75 | 75 |
| |
76 | 76 |
| |
77 |
| - | |
78 |
| - | |
79 |
| - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 |
| |
81 | 87 |
| |
82 | 88 |
| |
| 89 | + | |
| 90 | + | |
| 91 | + | |
83 | 92 |
| |
84 | 93 |
| |
85 | 94 |
| |
| 95 | + | |
| 96 | + | |
86 | 97 |
| |
87 | 98 |
| |
88 | 99 |
| |
| |||
104 | 115 |
| |
105 | 116 |
| |
106 | 117 |
| |
107 |
| - | |
108 |
| - | |
109 |
| - | |
110 |
| - | |
111 |
| - | |
112 |
| - | |
113 |
| - | |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
129 |
| - | |
130 | 118 |
|
0 commit comments
Comments
(0)