gh-154997: Guard stale self->raw access in bufferedio.c after reentrant detach() - #155017
Open
BHUVANSH855 wants to merge 7 commits into
Open
gh-154997: Guard stale self->raw access in bufferedio.c after reentrant detach()#155017BHUVANSH855 wants to merge 7 commits into
BHUVANSH855 wants to merge 7 commits into
Conversation
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.
Summary
Fix stale
self->rawaccesses in buffered I/O objects after a reentrantdetach().Introduce a shared
raw_access_safe()helper and use it before dispatchingto the underlying raw stream from the remaining affected buffered I/O paths.
This preserves the existing detached and uninitialized error semantics while
avoiding dereferences of a stale
self->rawpointer.The guarded call sites include:
_io__Buffered_close_impl()_buffered_raw_tell()_buffered_raw_seek()_io__Buffered_truncate_impl()_bufferedreader_raw_read()_bufferedreader_read_all()_bufferedwriter_raw_write()Tests
Added regression tests covering reentrant
detach()during:close()read_all()truncate()raw_tell()These tests verify that the affected operations raise the expected exception
(or preserve the intended behavior for
raw_tell()) instead of accessing astale raw stream.
The reproducer from the issue was also used to verify the patched code paths.
Notes
raw_seek()was intentionally left unchanged from a testing perspective.While it now benefits from the shared guard, it was not one of the original
SIGSEGV cases and is outside the scope of this change.
During testing,
test_read1_error_does_not_cause_reentrant_failurewas foundto abort under ASan even on an unmodified
maincheckout due to unrelatedallocator behavior, so it is not treated as a regression introduced by this
patch.