Skip to content

gh-148178: Validate async debug offsets read from remote process#148179

Closed
gpshead wants to merge 2 commits intopython:mainfrom
gpshead:fix-async-debug-offsets-validation
Closed

gh-148178: Validate async debug offsets read from remote process#148179
gpshead wants to merge 2 commits intopython:mainfrom
gpshead:fix-async-debug-offsets-validation

Conversation

@gpshead
Copy link
Copy Markdown
Member

@gpshead gpshead commented Apr 6, 2026

The _remote_debugging module reads async_debug_offsets from the target process's memory but did not validate them, unlike debug_offsets which go through validate_debug_offsets(). The asyncio_task_object.size field is used as the read length into fixed-size 4096-byte stack buffers (SIZEOF_TASK_OBJ); a malicious or compromised target process could supply a larger size and overflow the debugger's stack.

Add validate_async_debug_offsets() and call it from read_async_debug() (the single chokepoint for loading these offsets) to bound the task object size and the member offsets that index into the local buffer.

--

Opening as a draft to start with as this isn't my area of the code and there are possibly more of these to be fixed. Claude authored the fix.

@pablogsal
Copy link
Copy Markdown
Member

I need to think a bit more about how to do this properly. We need to validate every field of every section, not just the async debug. I also need to think carefully how to do this without having to write all by hand and how to ensure we fail at build time if we forget.

@pablogsal
Copy link
Copy Markdown
Member

pablogsal commented Apr 6, 2026

@gpshead I was working on a fix while you opened this. If you want we can iterate over this draft but since there is a lot more to do here and is quite tricky because I suspect we are going to need a lot of macros I am not sure if that's going to be the best route.

gpshead added 2 commits April 6, 2026 17:05
The _remote_debugging module reads async_debug_offsets from the target
process's memory but did not validate them, unlike debug_offsets which
go through validate_debug_offsets(). The asyncio_task_object.size field
is used as the read length into fixed-size 4096-byte stack buffers
(SIZEOF_TASK_OBJ); a malicious or compromised target process could
supply a larger size and overflow the debugger's stack.

Add validate_async_debug_offsets() and call it from read_async_debug()
(the single chokepoint for loading these offsets) to bound the task
object size and the member offsets that index into the local buffer.
@gpshead gpshead force-pushed the fix-async-debug-offsets-validation branch from 2943185 to 83bda8a Compare April 6, 2026 17:06
@gpshead
Copy link
Copy Markdown
Member Author

gpshead commented Apr 6, 2026

Totally fine if this PR gets closed. I mostly i wanted to surface it as food for thought (I suppose I could've just linked to the branch for that without a draft PR).

@pablogsal
Copy link
Copy Markdown
Member

Totally fine if this PR gets closed. I mostly i wanted to surface it as food for thought (I suppose I could've just linked to the branch for that without a draft PR).

Thanks a lot! I really appreciate the help and I want to say this explicitly :) It's just that unfortunately this fix will be tricky to balance in all fronts :(

@pablogsal
Copy link
Copy Markdown
Member

Closing in favour of #148187 Thanks for the draft Greg!

@pablogsal pablogsal closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants