crypto: fix use-after-free risk in ManagedX509 assignment - #62742
crypto: fix use-after-free risk in ManagedX509 assignment#62742omghante wants to merge 1 commit into
Conversation
|
Review requested:
|
Fixes a potential double-free issue where ManagedX509::operator= resets the underlying smart pointer using a raw pointer from another instance before incrementing the reference count. If both instances were managing the same underlying OpenSSL object, the reset could decrement the reference count to 0 and free the object before the reference count could be incremented. This fixes Coverity issue 367349 where different smart pointers were seemingly managing the same raw pointer. Fixes: nodejs#56926
49fa1be to
9da6f80
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62742 +/- ##
==========================================
- Coverage 89.69% 89.69% -0.01%
==========================================
Files 706 706
Lines 218127 218130 +3
Branches 41734 41739 +5
==========================================
- Hits 195651 195641 -10
- Misses 14400 14419 +19
+ Partials 8076 8070 -6
🚀 New features to boost your workflow:
|
|
Gentle ping - this PR has been open for ~3 weeks without review. This fixes the Coverity 367349 use-after-free risk in CI is green and the fix is ready for review. Would anyone from the crypto @targos (as the issue author) @tniessen @panva would appreciate your |
|
This pull request has been marked as stale due to 90 days of inactivity. |
|
Keep this open |
Description
This PR resolves a potential double-free/use-after-free vulnerability identified by Coverity (Issue 367349) within
ManagedX509::operator=.Previously,
cert_.reset(that.get())was destructing the underlying X509 structure prior to correctly tracking the reference count out-of-band viaX509_up_ref(cert_.get()). If multiple ManagedX509 instances mistakenly managed the same underlying raw pointer, it could cause the OpenSSL backing object's internal reference count to reach zero and prematurely free the memory beforeup_refexecutes.The refactored logic now ensures strict adherence to OpenSSL smart pointer semantics:
X509_up_ref(cert)increments the reference limits first before the object acts on.reset(), strictly guaranteeing the memory boundary.Fixes: #56926