forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1da569c
committed
Don't leak descriptors into subprograms.
Open long-lived data and WAL file descriptors with O_CLOEXEC. This flagwas introduced by SUSv4 (POSIX.1-2008), and by now all of our targetUnix systems have it. Our open() implementation for Windows already hadthat behavior, so provide a dummy O_CLOEXEC flag on that platform.For now, callers of open() and the "thin" wrappers in fd.c that deal inraw descriptors need to pass in O_CLOEXEC explicitly if desired. Thiscommit does that for WAL files, and automatically for everythingaccessed via VFDs including SMgrRelation and BufFile. (With morediscussion we might decide to turn it on automatically for the thinopen()-wrappers too to avoid risk of missing places that need it, butthese are typically used for short-lived descriptors where we don'texpect to fork/exec, and it's remotely possible that extensions could beusing these APIs and passing descriptors to subprograms deliberately, sothat hasn't been done here.)Do the same for sockets and the postmaster pipe with FD_CLOEXEC. (Latercommits might use modern interfaces to remove these extra fcntl() callsand more where possible, but we'll need them as a fallback for a coupleof systems, so do it that way in this initial commit.)With this change, subprograms executed for archiving, copying etc willno longer have access to the server's descriptors, other than the onesthat we decide to pass down.Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version)Discussion:https://postgr.es/m/CA%2BhUKGKb6FsAdQWcRL35KJsftv%2B9zXqQbzwkfRf1i0J2e57%2BhQ%40mail.gmail.com1 parent6b661b0 commit1da569c
File tree
5 files changed
+36
-3
lines changed- src
- backend
- access/transam
- libpq
- storage/file
- utils/init
- include/port
5 files changed
+36
-3
lines changedLines changed: 6 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2936 | 2936 |
| |
2937 | 2937 |
| |
2938 | 2938 |
| |
2939 |
| - | |
| 2939 | + | |
| 2940 | + | |
2940 | 2941 |
| |
2941 | 2942 |
| |
2942 | 2943 |
| |
| |||
3097 | 3098 |
| |
3098 | 3099 |
| |
3099 | 3100 |
| |
3100 |
| - | |
| 3101 | + | |
| 3102 | + | |
3101 | 3103 |
| |
3102 | 3104 |
| |
3103 | 3105 |
| |
| |||
3328 | 3330 |
| |
3329 | 3331 |
| |
3330 | 3332 |
| |
3331 |
| - | |
| 3333 | + | |
| 3334 | + | |
3332 | 3335 |
| |
3333 | 3336 |
| |
3334 | 3337 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
200 | 200 |
| |
201 | 201 |
| |
202 | 202 |
| |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
203 | 210 |
| |
204 | 211 |
| |
205 | 212 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1515 | 1515 |
| |
1516 | 1516 |
| |
1517 | 1517 |
| |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
1518 | 1526 |
| |
1519 | 1527 |
| |
1520 | 1528 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
163 | 163 |
| |
164 | 164 |
| |
165 | 165 |
| |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
166 | 174 |
| |
167 | 175 |
| |
168 | 176 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
353 | 353 |
| |
354 | 354 |
| |
355 | 355 |
| |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
356 | 363 |
| |
357 | 364 |
| |
358 | 365 |
| |
|
0 commit comments
Comments
(0)