GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-148178: Validate remote debug offset tables on load by pablogsal · Pull Request #148187 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Apr 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Harden validation of remote debugging offset tables #148178

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 6, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 6, 2026
Harden validation of remote debugging offset tables #148178
Closed
@pablogsal
pablogsal force-pushed the 148178 branch 2 times, most recently from b8dcd8f to e1f980e Compare April 6, 2026 21:08
@pablogsal pablogsal mentioned this pull request Apr 6, 2026
gh-148178: Validate async debug offsets read from remote process #148179
Closed
@pablogsal
pablogsal requested review from gpshead and sethmlarson April 6, 2026 21:40
maurycy
maurycy reviewed Apr 7, 2026
View reviewed changes

@maurycy maurycy left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pablogsal

pablogsal commented Apr 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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

gpshead reacted with thumbs up emoji maurycy reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

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 don't think so. But if you have a specific suggestion code suggestion happy to consider it ;)

maurycy reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pythongh-148178: Validate remote debug offset tables on load
f6f2faf
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.
@pablogsal
pablogsal force-pushed the 148178 branch 2 times, most recently from e5e1f21 to f6f2faf Compare April 8, 2026 12:58
gpshead
gpshead approved these changes Apr 12, 2026
View reviewed changes
Comment thread Modules/_remote_debugging/debug_offsets_validation.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_remote_debugging/debug_offsets_validation.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_remote_debugging/debug_offsets_validation.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Apr 12, 2026
@maurycy

maurycy commented Apr 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@pablogsal

I think the easiest would be:

-#define GET_MEMBER(type, obj, offset) (*(type*)((char*)(obj) + (offset)))
+#define GET_MEMBER(type, obj, offset) (*(const type *)memcpy(&(type){0}, (const char *)(obj) + (offset), sizeof(type)))

I did not test it, but looks the least disruptive. I was only able to confirm the issue w/ UBSan

You already do use memcpy:)

https://github.com/python/cpython/blob/30c698a655ba/Modules/_remote_debugging/binary_io_reader.c#L47-L51

I'd love to submit a PR but I think it should be based on yours, not the main branch. I'd definitely include some fail-fast in validate_field() and add field_alignment next to field_size. If you're ok, should be under gh-148178?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal @gpshead
Apply suggestions from code review
215390a
Co-authored-by: Gregory P. Smith <[email protected]>
@pablogsal
pablogsal force-pushed the 148178 branch from 49a423c to 215390a Compare April 12, 2026 18:14
@pablogsal

pablogsal commented Apr 12, 2026

Copy link
Copy Markdown
Member Author

@maurycy you can create a pr targetting this branch in my fork if you want

maurycy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maurycy
bring back https://github.com/python/cpython/compare/f12f6c4f0467837e…
d3b0fb0
…25a445339f2e5a24388a317d..b8dcd8fa2b3be846b1dad6d2afb1dccd968789b3
@maurycy maurycy mentioned this pull request Apr 12, 2026
gh-148178: Harden remote debug alignment checks pablogsal/cpython#125
Merged
maurycy and others added 7 commits April 12, 2026 21:06
@maurycy
demonstrate the bug?
dac7c75
@maurycy
now?
4a5345a
@maurycy
fail fast w/ RuntimeError
0a372d2
@maurycy
Revert "bring back https://github.com/python/cpython/compare/f12f6c4f…
bff8f8a
…0467837e25a445339f2e5a24388a317d..b8dcd8fa2b3be846b1dad6d2afb1dccd968789b3"

This reverts commit d3b0fb0.
@maurycy
Revert "demonstrate the bug?"
174853d
This reverts commit dac7c75.
@pablogsal
Merge pull request #125 from maurycy/maurycy-memcpy-get-member
6657166
pythongh-148178: Harden remote debug alignment checks
@pablogsal
fixup! Merge pull request #125 from maurycy/maurycy-memcpy-get-member
eccbc15
@pablogsal
pablogsal enabled auto-merge (squash) April 13, 2026 21:58
@pablogsal
pablogsal merged commit 289fd2c into python:main Apr 13, 2026
54 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal deleted the 148178 branch April 13, 2026 22:22
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 13, 2026
@pablogsal pablogsal added the needs backport to 3.14 bugs and security fixes label Apr 14, 2026
@miss-islington-app

miss-islington-app Bot commented Apr 14, 2026

Copy link
Copy Markdown

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Apr 14, 2026

Copy link
Copy Markdown

Sorry, @pablogsal, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 289fd2c97a7e5aecb8b69f94f5e838ccfeee7e67 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned pablogsal Apr 14, 2026
@bedevere-app

bedevere-app Bot commented Apr 14, 2026

Copy link
Copy Markdown

GH-148577 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Apr 14, 2026
@github-actions github-actions Bot mentioned this pull request Apr 15, 2026
[Candidate] CVE-2026-5713 Stefan0x03/fissure#290
Closed
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@pablogsal @ljfp
pythongh-148178: Validate remote debug offset tables on load (python#…
e030841
…148187)

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.
pablogsal added a commit that referenced this pull request May 4, 2026
@pablogsal
[3.14] gh-148178: Validate remote debug offset tables on load (GH-148187
316f626
) (#148577)

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.
(cherry picked from commit 289fd2c)
@taegyunkim taegyunkim mentioned this pull request Oct 21, 2026
Make asyncio debug offsets reachable from _PyRuntime and give them a cookie, version and size #160107
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes
@sethmlarson sethmlarson Awaiting requested review from sethmlarson
+1 more reviewer
@maurycy maurycy maurycy left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@pablogsal pablogsal

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@pablogsal @maurycy @gpshead
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.