CPython PySequence_Tuple partial initialization sandbox escape PoC#10
Open
sigdevel wants to merge 1 commit into
Open
CPython PySequence_Tuple partial initialization sandbox escape PoC#10sigdevel wants to merge 1 commit into
sigdevel wants to merge 1 commit 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.
Finding in CPython's tuple construction path (based at my old issue python/cpython#101855 ; GH-127058;):
PySequence_Tuple()registers the result tuple with the cyclic GC before anyob_itemslot is initialized. Restricted code withgcaccess can callgc.get_referrers()to receive a direct reference to the partial tuple mid-construction, bypassing Python-level sandbox isolation.Validated on CPython 3.13.12 (GIL) and a local 3.16.0a0 free-threading build with the pre-fix
PySequence_Tuplerestored.whats included
Six standalone PoC scripts, each self-contained (stdlib only, no ctypes):
poc_escape_gil.py: privileged data disclosed via generator re-entry; SIGSEGV (exit -11) via normalfor slot in tupleiteration ;poc_escape_exec.py:exec()sandbox with restricted__builtins__bypassed viagc.get_referrers();poc_escape_ft.py: concurrent spy thread intercepts partial tuple on free-threaded Python without generator cooperation ;poc_escape_open.py: open file handle andos.popencallable extracted from sandbox context that has neitheropennorosin its globals ;poc_free_threaded.py: barrier-synchronized race (Scenario 1) and 32-builder + 8-GC + 4-spy stress test (Scenario 2) ;poc_memory_leak.py: GC retention primitive; spy accumulates stranded tuples and their payloads until explicit release ;