forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2c0cefc
committed
Set libcrypto callbacks for all connection threads in libpq
Based on an analysis of the OpenSSL code with Jacob, moving to EVP forthe cryptohash computations makes necessary the setup of the libcryptocallbacks that were getting set only for SSL connections, but not forconnections without SSL. Not setting the callbacks makes the use ofthreads potentially unsafe for connections calling cryptohashes duringauthentication, like MD5 or SCRAM, if a failure happens during acryptohash computation. The logic setting the libssl and libcryptostates is then split into two parts, both using the same locking, withlibcrypto being set up for SSL and non-SSL connections, while SSLconnections set any libssl state afterwards as needed.Prior to this commit, only SSL connections would have set libcryptocallbacks that are necessary to ensure a proper thread locking whenusing multiple concurrent threads in libpq (ENABLE_THREAD_SAFETY). Notethat this is only required for OpenSSL 1.0.2 and 1.0.1 (oldest versionsupported on HEAD), as 1.1.0 has its own internal locking and it hasdropped support for CRYPTO_set_locking_callback().Tests with up to 300 threads with OpenSSL 1.0.1 and 1.0.2, mixing SSLand non-SSL connection threads did not show any performance impact aftersome micro-benchmarking. pgbench can be used here with -C and amostly-empty script (with one \set meta-command for example) to stressauthentication requests, and we have mixed that with some customprograms for testing.Reported-by: Jacob ChampionAuthor: Michael PaquierReviewed-by: Jacob ChampionDiscussion:https://postgr.es/m/fd3ba610085f1ff54623478cf2f7adf5af193cbb.camel@vmware.com1 parent3f0daeb commit2c0cefc
File tree
4 files changed
+96
-51
lines changed- src/interfaces/libpq
4 files changed
+96
-51
lines changedLines changed: 18 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2887 | 2887 |
| |
2888 | 2888 |
| |
2889 | 2889 |
| |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
2890 | 2900 |
| |
2891 | 2901 |
| |
2892 | 2902 |
| |
| |||
2998 | 3008 |
| |
2999 | 3009 |
| |
3000 | 3010 |
| |
3001 |
| - | |
3002 |
| - | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
| 3016 | + | |
| 3017 | + | |
| 3018 | + | |
3003 | 3019 |
| |
3004 | 3020 |
| |
3005 | 3021 |
| |
|
Lines changed: 65 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
85 | 85 |
| |
86 | 86 |
| |
87 | 87 |
| |
88 |
| - | |
| 88 | + | |
89 | 89 |
| |
90 | 90 |
| |
91 | 91 |
| |
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
| 114 | + | |
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
| |||
635 | 635 |
| |
636 | 636 |
| |
637 | 637 |
| |
638 |
| - | |
| 638 | + | |
639 | 639 |
| |
640 | 640 |
| |
641 | 641 |
| |
| |||
684 | 684 |
| |
685 | 685 |
| |
686 | 686 |
| |
687 |
| - | |
| 687 | + | |
688 | 688 |
| |
689 |
| - | |
690 |
| - | |
691 |
| - | |
692 |
| - | |
693 |
| - | |
694 |
| - | |
695 |
| - | |
696 |
| - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
697 | 703 |
| |
698 | 704 |
| |
699 | 705 |
| |
700 | 706 |
| |
701 | 707 |
| |
702 |
| - | |
| 708 | + | |
703 | 709 |
| |
704 | 710 |
| |
705 | 711 |
| |
| |||
740 | 746 |
| |
741 | 747 |
| |
742 | 748 |
| |
743 |
| - | |
744 |
| - | |
| 749 | + | |
| 750 | + | |
745 | 751 |
| |
746 |
| - | |
| 752 | + | |
747 | 753 |
| |
748 | 754 |
| |
749 | 755 |
| |
| |||
1402 | 1408 |
| |
1403 | 1409 |
| |
1404 | 1410 |
| |
1405 |
| - | |
| 1411 | + | |
1406 | 1412 |
| |
1407 |
| - | |
1408 |
| - | |
1409 |
| - | |
1410 |
| - | |
1411 |
| - | |
1412 |
| - | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1413 | 1420 |
| |
1414 |
| - | |
1415 |
| - | |
1416 |
| - | |
1417 |
| - | |
1418 |
| - | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
1419 | 1425 |
| |
1420 |
| - | |
1421 |
| - | |
1422 |
| - | |
1423 |
| - | |
1424 |
| - | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
1425 | 1434 |
| |
1426 | 1435 |
| |
1427 |
| - | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
1428 | 1445 |
| |
1429 |
| - | |
1430 |
| - | |
1431 |
| - | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
1432 | 1453 |
| |
1433 |
| - | |
1434 | 1454 |
| |
1435 | 1455 |
| |
1436 |
| - | |
1437 |
| - | |
1438 |
| - | |
1439 |
| - | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
1440 | 1460 |
| |
1441 | 1461 |
| |
1442 | 1462 |
| |
1443 | 1463 |
| |
| 1464 | + | |
1444 | 1465 |
| |
| 1466 | + | |
| 1467 | + | |
1445 | 1468 |
| |
1446 | 1469 |
| |
1447 | 1470 |
| |
|
Lines changed: 3 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
159 | 159 |
| |
160 | 160 |
| |
161 | 161 |
| |
162 |
| - | |
| 162 | + | |
163 | 163 |
| |
164 | 164 |
| |
165 | 165 |
| |
166 | 166 |
| |
167 |
| - | |
| 167 | + | |
168 | 168 |
| |
169 | 169 |
| |
170 | 170 |
| |
| |||
191 | 191 |
| |
192 | 192 |
| |
193 | 193 |
| |
194 |
| - | |
195 |
| - | |
| 194 | + | |
196 | 195 |
| |
197 | 196 |
| |
198 | 197 |
| |
|
Lines changed: 10 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
486 | 486 |
| |
487 | 487 |
| |
488 | 488 |
| |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
489 | 494 |
| |
490 | 495 |
| |
491 | 496 |
| |
| |||
667 | 672 |
| |
668 | 673 |
| |
669 | 674 |
| |
670 |
| - | |
| 675 | + | |
671 | 676 |
| |
672 | 677 |
| |
673 | 678 |
| |
| |||
696 | 701 |
| |
697 | 702 |
| |
698 | 703 |
| |
699 |
| - | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
700 | 707 |
| |
701 | 708 |
| |
702 | 709 |
| |
703 |
| - | |
| 710 | + | |
704 | 711 |
| |
705 | 712 |
| |
706 | 713 |
| |
|
0 commit comments
Comments
(0)