Repository navigation
gh-158923: Fix use-after-free in xibufferview_getbuf() - #159005
Open
christianaurichzm wants to merge 1 commit into
Open
christianaurichzm wants to merge 1 commit into
christianaurichzm wants to merge 1 commit into
Conversation
xibufferview_getbuf() didn't incref view->obj. The wrapper is exposed as mv.obj, so something like bytes(mv.obj) released a reference it never took, and the wrapper could be freed while the shared memoryview was still using it.
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.
Fixes #158923
xibufferview_getbuf()setsview->objwithout an incref. That's fine for_memoryview_from_xid(), which passes its own reference to the new memoryview, but the wrapper is also visible from Python asmv.obj. Sobytes(mv.obj),memoryview(mv.obj)etc. release a reference they never got, the wrapper is freed, and the shared memoryview still points to it.Fix: incref in
xibufferview_getbuf()like any other getbuffer, and decref in_memoryview_from_xid()after creating the memoryview.Tested on a debug build: the reproducer from the issue and the new test both segfault without the patch and pass with it (the test also passes with
-R 3:3).test_interpreters,test__interpreters,test__interpchannels,test_crossinterpandtest_concurrent_futures.test_interpreter_poolpass._interpretersxibufferview_getbufmissing INCREF: shared-memoryview UAF #158923