forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitaf9c5c0
committed
Be more careful to not lose sync in the FE/BE protocol.
If any error occurred while we were in the middle of reading a protocolmessage from the client, we could lose sync, and incorrectly try tointerpret a part of another message as a new protocol message. That willusually lead to an "invalid frontend message" error that terminates theconnection. However, this is a security issue because an attacker mightbe able to deliberately cause an error, inject a Query message in what'ssupposed to be just user data, and have the server execute it.We were quite careful to not have CHECK_FOR_INTERRUPTS() calls or otheroperations that could ereport(ERROR) in the middle of processing a message,but a query cancel interrupt or statement timeout could nevertheless causeit to happen. Also, the V2 fastpath and COPY handling were not so careful.It's very difficult to recover in the V2 COPY protocol, so we will justterminate the connection on error. In practice, that's what happenedpreviously anyway, as we lost protocol sync.To fix, add a new variable in pqcomm.c, PqCommReadingMsg, that is setwhenever we're in the middle of reading a message. When it's set, we cannotsafely ERROR out and continue running, because we might've read only partof a message. PqCommReadingMsg acts somewhat similarly to critical sectionsin that if an error occurs while it's set, the error handler will force theconnection to be terminated, as if the error was FATAL. It's notimplemented by promoting ERROR to FATAL in elog.c, like ERROR is promotedto PANIC in critical sections, because we want to be able to usePG_TRY/CATCH to recover and regain protocol sync. pq_getmessage() takesadvantage of that to prevent an OOM error from terminating the connection.To prevent unnecessary connection terminations, add a holdoff mechanismsimilar to HOLD/RESUME_INTERRUPTS() that can be used hold off query cancelinterrupts, but still allow die interrupts. The rules on which interruptsare processed when are now a bit more complicated, so refactorProcessInterrupts() and the calls to it in signal handlers so that thesignal handlers always call it if ImmediateInterruptOK is set, andProcessInterrupts() can decide to not do anything if the other conditionsare not met.Reported by Emil Lenngren. Patch reviewed by Noah Misch and Andres Freund.Backpatch to all supported versions.Security:CVE-2015-02441 parent8d412e0 commitaf9c5c0
File tree
13 files changed
+236
-93
lines changed- src
- backend
- commands
- libpq
- postmaster
- replication
- storage/lmgr
- tcop
- utils
- error
- init
- include
- libpq
- tcop
13 files changed
+236
-93
lines changedLines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
385 | 385 |
| |
386 | 386 |
| |
387 | 387 |
| |
| 388 | + | |
| 389 | + | |
388 | 390 |
| |
389 | 391 |
| |
390 | 392 |
| |
| |||
395 | 397 |
| |
396 | 398 |
| |
397 | 399 |
| |
| 400 | + | |
| 401 | + | |
398 | 402 |
| |
399 | 403 |
| |
400 | 404 |
| |
| |||
555 | 559 |
| |
556 | 560 |
| |
557 | 561 |
| |
| 562 | + | |
| 563 | + | |
558 | 564 |
| |
559 | 565 |
| |
560 | 566 |
| |
| |||
564 | 570 |
| |
565 | 571 |
| |
566 | 572 |
| |
| 573 | + | |
567 | 574 |
| |
568 | 575 |
| |
569 | 576 |
| |
| |||
2049 | 2056 |
| |
2050 | 2057 |
| |
2051 | 2058 |
| |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
2052 | 2066 |
| |
2053 | 2067 |
| |
2054 | 2068 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
653 | 653 |
| |
654 | 654 |
| |
655 | 655 |
| |
| 656 | + | |
656 | 657 |
| |
657 | 658 |
| |
658 | 659 |
| |
| |||
1058 | 1059 |
| |
1059 | 1060 |
| |
1060 | 1061 |
| |
| 1062 | + | |
1061 | 1063 |
| |
1062 | 1064 |
| |
1063 | 1065 |
| |
| |||
1296 | 1298 |
| |
1297 | 1299 |
| |
1298 | 1300 |
| |
| 1301 | + | |
1299 | 1302 |
| |
1300 | 1303 |
| |
1301 | 1304 |
| |
|
Lines changed: 74 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
129 | 129 |
| |
130 | 130 |
| |
131 | 131 |
| |
132 |
| - | |
133 |
| - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
134 | 135 |
| |
135 | 136 |
| |
136 | 137 |
| |
| |||
156 | 157 |
| |
157 | 158 |
| |
158 | 159 |
| |
| 160 | + | |
159 | 161 |
| |
160 | 162 |
| |
161 | 163 |
| |
| |||
860 | 862 |
| |
861 | 863 |
| |
862 | 864 |
| |
| 865 | + | |
| 866 | + | |
863 | 867 |
| |
864 | 868 |
| |
865 | 869 |
| |
| |||
898 | 902 |
| |
899 | 903 |
| |
900 | 904 |
| |
| 905 | + | |
| 906 | + | |
901 | 907 |
| |
902 | 908 |
| |
903 | 909 |
| |
| |||
950 | 956 |
| |
951 | 957 |
| |
952 | 958 |
| |
| 959 | + | |
| 960 | + | |
953 | 961 |
| |
954 | 962 |
| |
955 | 963 |
| |
| |||
982 | 990 |
| |
983 | 991 |
| |
984 | 992 |
| |
| 993 | + | |
| 994 | + | |
985 | 995 |
| |
986 | 996 |
| |
987 | 997 |
| |
| |||
1018 | 1028 |
| |
1019 | 1029 |
| |
1020 | 1030 |
| |
| 1031 | + | |
| 1032 | + | |
1021 | 1033 |
| |
1022 | 1034 |
| |
1023 | 1035 |
| |
| |||
1049 | 1061 |
| |
1050 | 1062 |
| |
1051 | 1063 |
| |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1052 | 1116 |
| |
1053 | 1117 |
| |
1054 | 1118 |
| |
| |||
1070 | 1134 |
| |
1071 | 1135 |
| |
1072 | 1136 |
| |
| 1137 | + | |
| 1138 | + | |
1073 | 1139 |
| |
1074 | 1140 |
| |
1075 | 1141 |
| |
| |||
1111 | 1177 |
| |
1112 | 1178 |
| |
1113 | 1179 |
| |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
1114 | 1183 |
| |
1115 | 1184 |
| |
1116 | 1185 |
| |
| |||
1128 | 1197 |
| |
1129 | 1198 |
| |
1130 | 1199 |
| |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
1131 | 1203 |
| |
1132 | 1204 |
| |
1133 | 1205 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1617 | 1617 |
| |
1618 | 1618 |
| |
1619 | 1619 |
| |
| 1620 | + | |
1620 | 1621 |
| |
1621 | 1622 |
| |
1622 | 1623 |
| |
| |||
1661 | 1662 |
| |
1662 | 1663 |
| |
1663 | 1664 |
| |
| 1665 | + | |
1664 | 1666 |
| |
1665 | 1667 |
| |
1666 | 1668 |
| |
|
Lines changed: 20 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
207 | 207 |
| |
208 | 208 |
| |
209 | 209 |
| |
| 210 | + | |
210 | 211 |
| |
211 | 212 |
| |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
212 | 220 |
| |
213 | 221 |
| |
214 | 222 |
| |
| |||
226 | 234 |
| |
227 | 235 |
| |
228 | 236 |
| |
229 |
| - | |
230 |
| - | |
231 |
| - | |
232 |
| - | |
233 |
| - | |
234 |
| - | |
235 |
| - | |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 | 237 |
| |
240 | 238 |
| |
241 | 239 |
| |
| |||
481 | 479 |
| |
482 | 480 |
| |
483 | 481 |
| |
| 482 | + | |
484 | 483 |
| |
485 | 484 |
| |
486 | 485 |
| |
| |||
493 | 492 |
| |
494 | 493 |
| |
495 | 494 |
| |
| 495 | + | |
496 | 496 |
| |
497 | 497 |
| |
498 | 498 |
| |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
499 | 509 |
| |
500 | 510 |
| |
501 | 511 |
| |
| |||
536 | 546 |
| |
537 | 547 |
| |
538 | 548 |
| |
539 |
| - | |
540 |
| - | |
541 |
| - | |
542 |
| - | |
543 |
| - | |
544 |
| - | |
545 |
| - | |
546 |
| - | |
547 |
| - | |
548 |
| - | |
549 |
| - | |
550 |
| - | |
551 |
| - | |
552 | 549 |
| |
553 | 550 |
| |
554 | 551 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
608 | 608 |
| |
609 | 609 |
| |
610 | 610 |
| |
| 611 | + | |
| 612 | + | |
611 | 613 |
| |
612 | 614 |
| |
| 615 | + | |
| 616 | + | |
613 | 617 |
| |
| 618 | + | |
614 | 619 |
| |
615 | 620 |
| |
616 | 621 |
| |
| |||
649 | 654 |
| |
650 | 655 |
| |
651 | 656 |
| |
| 657 | + | |
| 658 | + | |
652 | 659 |
| |
653 | 660 |
| |
654 | 661 |
| |
|
Lines changed: 1 addition & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
73 | 73 |
| |
74 | 74 |
| |
75 | 75 |
| |
76 |
| - | |
| 76 | + | |
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
| |||
278 | 278 |
| |
279 | 279 |
| |
280 | 280 |
| |
281 |
| - | |
282 |
| - | |
283 |
| - | |
284 |
| - | |
285 |
| - | |
286 |
| - | |
287 |
| - | |
288 |
| - | |
289 |
| - | |
290 |
| - | |
291 |
| - | |
292 |
| - | |
293 |
| - | |
294 |
| - | |
295 | 281 |
| |
296 | 282 |
| |
297 | 283 |
| |
|
0 commit comments
Comments
(0)