forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit572d6ee
committed
Fix locking in WAL receiver/sender shmem state structs
In WAL receiver and WAL server, some accesses to their correspondingshared memory control structs were done without holding any kind oflock, which could lead to inconsistent and possibly insecure results.In walsender, fix by clarifying the locking rules and following themcorrectly, as documented in the new comment in walsender_private.h;namely that some members can be read in walsender itself without a lock,because the only writes occur in the same process. The rest of thestruct requires spinlock for accesses, as usual.In walreceiver, fix by always holding spinlock while accessing thestruct.While there is potentially a problem in all branches, it is minor instable ones. This only became a real problem in pg10 because of quorumcommit in synchronous replication (commit3901fd7), and a potentialsecurity problem in walreceiver because a superuser() check was removedby default monitoring roles (commit25fff40). Thus, no backpatch.In passing, clean up some leftover braces which were used to createunconditional blocks. Once upon a time these were used forvolatile-izing accesses to those shmem structs, which is no longerrequired. Many other occurrences of this pattern remain.Author: Michaël PaquierReported-by: Michaël PaquierReviewed-by: Masahiko Sawada, Kyotaro Horiguchi, Thomas Munro,Robert HaasDiscussion:https://postgr.es/m/CAB7nPqTWYqtzD=LN_oDaf9r-hAjUEPAy0B9yRkhcsLdRN8fzrw@mail.gmail.com1 parent898d24a commit572d6ee
File tree
5 files changed
+80
-55
lines changed- src
- backend/replication
- include/replication
5 files changed
+80
-55
lines changedLines changed: 26 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
711 | 711 |
| |
712 | 712 |
| |
713 | 713 |
| |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
714 | 718 |
| |
715 | 719 |
| |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
716 | 726 |
| |
717 |
| - | |
| 727 | + | |
718 | 728 |
| |
719 | 729 |
| |
720 | 730 |
| |
721 |
| - | |
| 731 | + | |
722 | 732 |
| |
723 | 733 |
| |
724 | 734 |
| |
725 | 735 |
| |
726 | 736 |
| |
727 | 737 |
| |
728 | 738 |
| |
729 |
| - | |
| 739 | + | |
730 | 740 |
| |
731 | 741 |
| |
732 | 742 |
| |
| |||
780 | 790 |
| |
781 | 791 |
| |
782 | 792 |
| |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
783 | 797 |
| |
784 | 798 |
| |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
785 | 805 |
| |
786 |
| - | |
| 806 | + | |
787 | 807 |
| |
788 | 808 |
| |
789 | 809 |
| |
790 |
| - | |
| 810 | + | |
791 | 811 |
| |
792 | 812 |
| |
793 | 813 |
| |
| |||
796 | 816 |
| |
797 | 817 |
| |
798 | 818 |
| |
799 |
| - | |
| 819 | + | |
800 | 820 |
| |
801 | 821 |
| |
802 | 822 |
| |
|
Lines changed: 22 additions & 20 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1379 | 1379 |
| |
1380 | 1380 |
| |
1381 | 1381 |
| |
1382 |
| - | |
| 1382 | + | |
| 1383 | + | |
1383 | 1384 |
| |
1384 | 1385 |
| |
1385 | 1386 |
| |
| |||
1392 | 1393 |
| |
1393 | 1394 |
| |
1394 | 1395 |
| |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1395 | 1413 |
| |
1396 | 1414 |
| |
1397 | 1415 |
| |
1398 | 1416 |
| |
1399 |
| - | |
| 1417 | + | |
1400 | 1418 |
| |
1401 | 1419 |
| |
1402 | 1420 |
| |
| |||
1406 | 1424 |
| |
1407 | 1425 |
| |
1408 | 1426 |
| |
1409 |
| - | |
1410 |
| - | |
1411 |
| - | |
1412 |
| - | |
1413 |
| - | |
1414 |
| - | |
1415 |
| - | |
1416 |
| - | |
1417 |
| - | |
1418 |
| - | |
1419 |
| - | |
1420 |
| - | |
1421 |
| - | |
1422 |
| - | |
1423 |
| - | |
1424 | 1427 |
| |
1425 |
| - | |
| 1428 | + | |
1426 | 1429 |
| |
1427 | 1430 |
| |
1428 | 1431 |
| |
| |||
1473 | 1476 |
| |
1474 | 1477 |
| |
1475 | 1478 |
| |
1476 |
| - | |
1477 |
| - | |
| 1479 | + | |
1478 | 1480 |
|
Lines changed: 21 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
668 | 668 |
| |
669 | 669 |
| |
670 | 670 |
| |
671 |
| - | |
672 |
| - | |
673 |
| - | |
674 |
| - | |
675 |
| - | |
676 |
| - | |
677 |
| - | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
678 | 674 |
| |
679 | 675 |
| |
680 | 676 |
| |
| |||
1093 | 1089 |
| |
1094 | 1090 |
| |
1095 | 1091 |
| |
1096 |
| - | |
1097 |
| - | |
1098 |
| - | |
1099 |
| - | |
1100 |
| - | |
1101 |
| - | |
1102 |
| - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1103 | 1095 |
| |
1104 | 1096 |
| |
1105 | 1097 |
| |
| |||
2892 | 2884 |
| |
2893 | 2885 |
| |
2894 | 2886 |
| |
| 2887 | + | |
2895 | 2888 |
| |
| 2889 | + | |
| 2890 | + | |
2896 | 2891 |
| |
2897 |
| - | |
2898 |
| - | |
| 2892 | + | |
2899 | 2893 |
| |
2900 | 2894 |
| |
2901 | 2895 |
| |
| |||
3071 | 3065 |
| |
3072 | 3066 |
| |
3073 | 3067 |
| |
3074 |
| - | |
3075 | 3068 |
| |
3076 | 3069 |
| |
3077 | 3070 |
| |
| |||
3082 | 3075 |
| |
3083 | 3076 |
| |
3084 | 3077 |
| |
3085 |
| - | |
3086 |
| - | |
3087 |
| - | |
3088 |
| - | |
| 3078 | + | |
3089 | 3079 |
| |
3090 | 3080 |
| |
| 3081 | + | |
3091 | 3082 |
| |
3092 | 3083 |
| |
| 3084 | + | |
3093 | 3085 |
| |
3094 | 3086 |
| |
3095 | 3087 |
| |
| |||
3210 | 3202 |
| |
3211 | 3203 |
| |
3212 | 3204 |
| |
| 3205 | + | |
3213 | 3206 |
| |
3214 | 3207 |
| |
3215 | 3208 |
| |
3216 | 3209 |
| |
| 3210 | + | |
3217 | 3211 |
| |
| 3212 | + | |
| 3213 | + | |
3218 | 3214 |
| |
3219 |
| - | |
3220 |
| - | |
| 3215 | + | |
| 3216 | + | |
3221 | 3217 |
| |
3222 | 3218 |
| |
3223 | 3219 |
| |
| |||
3230 | 3226 |
| |
3231 | 3227 |
| |
3232 | 3228 |
| |
3233 |
| - | |
| 3229 | + | |
3234 | 3230 |
| |
3235 | 3231 |
| |
3236 | 3232 |
| |
| |||
3265 | 3261 |
| |
3266 | 3262 |
| |
3267 | 3263 |
| |
3268 |
| - | |
| 3264 | + | |
3269 | 3265 |
| |
3270 | 3266 |
| |
3271 | 3267 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
114 | 114 |
| |
115 | 115 |
| |
116 | 116 |
| |
| 117 | + | |
| 118 | + | |
| 119 | + | |
117 | 120 |
| |
118 | 121 |
| |
119 | 122 |
| |
| |||
122 | 125 |
| |
123 | 126 |
| |
124 | 127 |
| |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 | 128 |
| |
129 | 129 |
| |
130 | 130 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 |
| |
34 | 40 |
| |
35 | 41 |
| |
36 |
| - | |
| 42 | + | |
| 43 | + | |
37 | 44 |
| |
38 | 45 |
| |
39 | 46 |
| |
|
0 commit comments
Comments
(0)