Commit 42cc33c
src: add mutex to ManagedEVPPKey class
This commit introduces a mutex field on the ManagedEVPPKey class
intended to be used when multiple threads require access to an OpenSSL
EVP_PKEY object. The motivation for this came from the work being done
to upgrade Node.js to OpenSSL 3.0.
OpenSSL objects, like EVP_PKEY, are not thread safe (see refs for
details). In versions prior to OpenSSL 3.0 this was not noticeable and
did not cause any issues (like incorrect logic or crashes), but with
OpenSSL 3.0 this does cause issues if access to an EVP_PKEY instance is
required from multiple threads without locking.
In OpenSSL 3.0 when the evp_pkey_downgrade function is called, which
downgrades an EVP_PKEY instance to a legacy version, it will clear all
the fields of EVP_PKEY struct except the lock (#13374). But this also
means that keymgmt and keydata will also be cleared, which other parts
of the code base depends on, and those calls will either fail to export
the key (returning null) or crash due to a segment fault.
This same code works with OpenSSL 1.1.1 without locking and I think this
is because there is no downgrade being done in OpenSSL 1.1.1. But even
so, as far as I can tell there are no guarantees that these object are
thread safe in 1.1.1 either and should be protected with a lock.
PR-URL: #36825
Refs: openssl/openssl#13374
Refs: openssl/openssl#13374
Refs: openssl/openssl#2165)
Refs: https://www.openssl.org/blog/blog/2017/02/21/threads
Reviewed-By: James M Snell <jasnell@gmail.com>1 parent e28ea89 commit 42cc33cCopy full SHA for 42cc33c
File tree
Expand file treeCollapse file tree
6 files changed
+59
-35
lines changedOpen diff view settings
Filter options
- src/crypto
Expand file treeCollapse file tree
6 files changed
+59
-35
lines changedOpen diff view settings
Collapse file
+4-3Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
133 | 133 | |
134 | 134 | |
135 | 135 | |
136 | | - |
137 | | - |
| 136 | + |
| 137 | + |
| 138 | + |
138 | 139 | |
139 | 140 | |
140 | | - |
| 141 | + |
141 | 142 | |
142 | 143 | |
143 | 144 | |
|
Collapse file
+12-8Lines changed: 12 additions & 8 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
601 | 601 | |
602 | 602 | |
603 | 603 | |
604 | | - |
| 604 | + |
| 605 | + |
| 606 | + |
605 | 607 | |
606 | | - |
| 608 | + |
607 | 609 | |
608 | 610 | |
609 | 611 | |
| ||
688 | 690 | |
689 | 691 | |
690 | 692 | |
691 | | - |
692 | | - |
| 693 | + |
| 694 | + |
| 695 | + |
693 | 696 | |
694 | | - |
| 697 | + |
695 | 698 | |
696 | 699 | |
697 | 700 | |
| ||
893 | 896 | |
894 | 897 | |
895 | 898 | |
896 | | - |
897 | | - |
| 899 | + |
| 900 | + |
| 901 | + |
898 | 902 | |
899 | | - |
| 903 | + |
900 | 904 | |
901 | 905 | |
902 | 906 | |
|
Collapse file
+15-3Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
552 | 552 | |
553 | 553 | |
554 | 554 | |
555 | | - |
| 555 | + |
| 556 | + |
556 | 557 | |
557 | 558 | |
558 | 559 | |
| ||
564 | 565 | |
565 | 566 | |
566 | 567 | |
| 568 | + |
| 569 | + |
567 | 570 | |
568 | 571 | |
569 | 572 | |
| ||
575 | 578 | |
576 | 579 | |
577 | 580 | |
| 581 | + |
| 582 | + |
| 583 | + |
| 584 | + |
578 | 585 | |
579 | 586 | |
580 | 587 | |
| ||
1326 | 1333 | |
1327 | 1334 | |
1328 | 1335 | |
| 1336 | + |
| 1337 | + |
1329 | 1338 | |
1330 | | - |
| 1339 | + |
1331 | 1340 | |
1332 | 1341 | |
1333 | 1342 | |
| ||
1338 | 1347 | |
1339 | 1348 | |
1340 | 1349 | |
| 1350 | + |
| 1351 | + |
| 1352 | + |
1341 | 1353 | |
1342 | | - |
| 1354 | + |
1343 | 1355 | |
1344 | 1356 | |
1345 | 1357 | |
|
Collapse file
+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
81 | 81 | |
82 | 82 | |
83 | 83 | |
| 84 | + |
84 | 85 | |
85 | 86 | |
86 | 87 | |
| ||
127 | 128 | |
128 | 129 | |
129 | 130 | |
| 131 | + |
130 | 132 | |
131 | 133 | |
132 | 134 | |
|
Collapse file
+13-10Lines changed: 13 additions & 10 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
191 | 191 | |
192 | 192 | |
193 | 193 | |
| 194 | + |
| 195 | + |
194 | 196 | |
195 | | - |
196 | | - |
| 197 | + |
197 | 198 | |
198 | 199 | |
199 | 200 | |
| ||
363 | 364 | |
364 | 365 | |
365 | 366 | |
366 | | - |
367 | | - |
| 367 | + |
| 368 | + |
| 369 | + |
368 | 370 | |
369 | 371 | |
370 | 372 | |
371 | 373 | |
372 | 374 | |
373 | 375 | |
374 | | - |
| 376 | + |
375 | 377 | |
376 | | - |
| 378 | + |
377 | 379 | |
378 | 380 | |
379 | 381 | |
| ||
511 | 513 | |
512 | 514 | |
513 | 515 | |
514 | | - |
515 | | - |
| 516 | + |
| 517 | + |
| 518 | + |
516 | 519 | |
517 | 520 | |
518 | 521 | |
519 | 522 | |
520 | 523 | |
521 | 524 | |
522 | | - |
| 525 | + |
523 | 526 | |
524 | | - |
| 527 | + |
525 | 528 | |
526 | 529 | |
527 | 530 | |
|
Collapse file
+13-11Lines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
96 | 96 | |
97 | 97 | |
98 | 98 | |
99 | | - |
100 | | - |
101 | | - |
| 99 | + |
| 100 | + |
| 101 | + |
102 | 102 | |
103 | 103 | |
104 | 104 | |
| ||
752 | 752 | |
753 | 753 | |
754 | 754 | |
755 | | - |
| 755 | + |
| 756 | + |
| 757 | + |
756 | 758 | |
757 | | - |
758 | | - |
759 | | - |
| 759 | + |
760 | 760 | |
761 | 761 | |
762 | 762 | |
| ||
774 | 774 | |
775 | 775 | |
776 | 776 | |
| 777 | + |
| 778 | + |
777 | 779 | |
778 | 780 | |
779 | 781 | |
| ||
782 | 784 | |
783 | 785 | |
784 | 786 | |
785 | | - |
| 787 | + |
786 | 788 | |
787 | 789 | |
788 | 790 | |
| ||
793 | 795 | |
794 | 796 | |
795 | 797 | |
796 | | - |
| 798 | + |
797 | 799 | |
798 | 800 | |
799 | 801 | |
800 | 802 | |
801 | 803 | |
802 | 804 | |
803 | 805 | |
804 | | - |
| 806 | + |
805 | 807 | |
806 | 808 | |
807 | 809 | |
808 | 810 | |
809 | 811 | |
810 | | - |
| 812 | + |
811 | 813 | |
812 | 814 | |
813 | 815 | |
|
0 commit comments