crypto: fix use-after-free risk in ManagedX509 assignment#62742
Open
om-ghante wants to merge 1 commit intonodejs:mainfrom
Open
crypto: fix use-after-free risk in ManagedX509 assignment#62742om-ghante wants to merge 1 commit intonodejs:mainfrom
om-ghante wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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