gh-148178: Validate remote debug offset tables on load#148187
gh-148178: Validate remote debug offset tables on load#148187pablogsal wants to merge 1 commit intopython:mainfrom
Conversation
b8dcd8f to
e1f980e
Compare
There was a problem hiding this comment.
Also add Linux poison tests that corrupt both the main and asyncio offset tables and assert that RemoteUnwinder fails with an invalid-offset error instead of walking into bad accesses or misleading late failures.
Where are they?
I'm also wondering about char[] buffers and GET_MEMBER? I'm thinking about alignment of offsets for a given type. Perhaps there's a risk of undefined behaviour there as well. Do we care about it?
I decided to remove the tests because there were stupidly long, verbose (as I am basically parsing elf by hand in Python), only worked on Linux and has reduced value (just one way to trigger it not all of them) and the Pr is already quite big but I didn't update the commit message You can see them in the diff here https://github.com/python/cpython/compare/f12f6c4f0467837e25a445339f2e5a24388a317d..b8dcd8fa2b3be846b1dad6d2afb1dccd968789b3 |
I don't think so. But if you have a specific suggestion code suggestion happy to consider it ;) |
Treat the debug offset tables read from a target process as untrusted input and validate them before the unwinder uses any reported sizes or offsets. Add a shared validator in debug_offsets_validation.h and run it once when _Py_DebugOffsets is loaded and once when AsyncioDebug is loaded. The checks cover section sizes used for fixed local buffers and every offset that is later dereferenced against a local buffer or local object view. This keeps the bounds checks out of the sampling hot path while rejecting malformed tables up front.
e5e1f21 to
f6f2faf
Compare
Treat the debug offset tables read from a target process as untrusted input and validate them before the unwinder uses any reported sizes or offsets.
Add a shared validator in debug_offsets_validation.h and run it once when _Py_DebugOffsets is loaded and once when AsyncioDebug is loaded. The checks cover section sizes used for fixed local buffers and every offset that is later dereferenced against a local buffer or local object view. This keeps the bounds checks out of the sampling hot path while rejecting malformed tables up front.