gh-146266: Add bounds validation for _Py_DebugOffsets offset fields#146267
Closed
jackhax wants to merge 1 commit intopython:mainfrom
Closed
gh-146266: Add bounds validation for _Py_DebugOffsets offset fields#146267jackhax wants to merge 1 commit intopython:mainfrom
jackhax wants to merge 1 commit intopython:mainfrom
Conversation
…elds validate_debug_offsets() only checked the cookie and version but did not validate that individual offset fields are within their declared struct sizes. If a target process has corrupted _Py_DebugOffsets (e.g. from memory corruption or a misbehaving extension), the GET_MEMBER macro performs unchecked pointer arithmetic with the invalid offsets, causing RemoteUnwinder to crash with SIGSEGV. Add per-field bounds checking: each offset must be less than the .size of its containing sub-struct. Invalid offsets now raise RuntimeError with a descriptive message instead of crashing the debugger process. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Member
|
Thanks for the PR @jackhax. Unfortunately I don't think this PR is the right way (see the comment in the issue). Feel free to continue the discussion there if we are missing anything. Thanks for you work! |
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
validate_debug_offsets()now checks that every offset field in_Py_DebugOffsetsis within the declared.sizeof its containing sub-structRuntimeErrorwith a descriptive message instead of causing a SIGSEGV in the debugger processProblem
The
GET_MEMBERmacro in_remote_debugging.hperforms unchecked pointer arithmetic using offsets read from the target process. If those offsets are corrupted (memory corruption, partially-initialized interpreter, misbehaving extension),RemoteUnwinderdereferences a wild pointer and crashes with SIGSEGV.The existing
validate_debug_offsets()only checked the cookie and version — not the actual offset values.Fix
Added a
_CHECK_OFFSET(section, field)macro that verifiesoffset < sizefor each sub-struct's fields. This catches invalid offsets at attach time, before anyGET_MEMBERcalls.Test plan
test_remote_debuggingtests should pass unchanged (valid offsets always satisfy bounds checks)RuntimeErrorinstead of crashing the debugger