JSSE: protect from calling freeSSL() while I/O operations in progress#278
Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom Aug 18, 2025
Merged
JSSE: protect from calling freeSSL() while I/O operations in progress#278rlm2002 merged 1 commit intowolfSSL:masterfrom
rlm2002 merged 1 commit intowolfSSL:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
The PR introduces an atomic counter to track active I/O operations in WolfSSLSocket and prevent freeSSL() from being called while reads or writes are in flight.
- Added
activeOperationscounter withenterIOOperation()/exitIOOperation()helpers. - Wrapped read/write streams to increment/decrement the counter.
- Updated
close()to defer freeing SSL until no active operations remain.
Comments suppressed due to low confidence (1)
src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java:2735
- No tests were added to verify that
activeOperationspreventsfreeSSL()under concurrent I/O, or that the counter remains accurate under failure paths. Consider adding multithreaded unit tests or integration tests that simulate concurrent read/write and close calls.
/* Enter I/O operation to prevent use-after-free */
rlm2002
approved these changes
Aug 18, 2025
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.
This PR adds an atomic counter of active I/O operations (read/write) to
WolfSSLSocket.javato protect against callingfreeSSL()while I/O ops are still in progress.This fixes an issue where AddressSanitizer detected heap-use-after-free errors when multiple threads performed concurrent I/O operations while another thread called close() on the same WolfSSLSocket. The race condition occurred when wolfSSL_get_app_data() was called on a freed WOLFSSL object during active read/write operations.
I did try to get a unit test put together for regression on this item, but was unsuccessful in a reliable consistent test yet. Separate reproducer confirmed this fixed the issue locally.