-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-140739: Fix crashes from corrupted remote memory #143190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix several crashes due to reading invalid memory in the new Tachyon | ||
| sampling profiler. Patch by Pablo Galindo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,15 @@ process_single_stack_chunk( | |
| // Check actual size and reread if necessary | ||
| size_t actual_size = GET_MEMBER(size_t, this_chunk, offsetof(_PyStackChunk, size)); | ||
| if (actual_size != current_size) { | ||
| // Validate size: reject garbage (too small or unreasonably large) | ||
| // Size must be at least enough for the header and reasonably bounded | ||
| if (actual_size <= offsetof(_PyStackChunk, data) || actual_size > MAX_STACK_CHUNK_SIZE) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is looser than I'd like for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any suggestion?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish we had a tighter bound, but I'm not sure what would be appropiate for a real world stack frame? So that's why I said whatever :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But this is for the entire chunk no? Chunks will grow from 16Kb to whatever, we just need to ensure we don't copy too much because we just read a garbage size to copy. Chunks here are just an optimization so if we fail to read the chunks we will fallback to read frame-by-frame (which sucks but it works).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I didn't know you do the second part (fallback to read one by one). I think that's fine then. |
||
| PyMem_RawFree(this_chunk); | ||
| set_exception_cause(unwinder, PyExc_RuntimeError, | ||
| "Invalid stack chunk size (corrupted remote memory)"); | ||
| return -1; | ||
| } | ||
|
|
||
| this_chunk = PyMem_RawRealloc(this_chunk, actual_size); | ||
| if (!this_chunk) { | ||
| PyErr_NoMemory(); | ||
|
|
@@ -129,7 +138,11 @@ void * | |
| find_frame_in_chunks(StackChunkList *chunks, uintptr_t remote_ptr) | ||
| { | ||
| for (size_t i = 0; i < chunks->count; ++i) { | ||
| assert(chunks->chunks[i].size > offsetof(_PyStackChunk, data)); | ||
| // Validate size: reject garbage that would cause underflow | ||
| if (chunks->chunks[i].size <= offsetof(_PyStackChunk, data)) { | ||
| // Skip this chunk - corrupted size from remote memory | ||
| continue; | ||
| } | ||
| uintptr_t base = chunks->chunks[i].remote_addr + offsetof(_PyStackChunk, data); | ||
| size_t payload = chunks->chunks[i].size - offsetof(_PyStackChunk, data); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.