Skip to content

gh-149619: Fix _remote_debugging permissions error on Linux#150012

Merged
pablogsal merged 1 commit into
python:mainfrom
ivonastojanovic:fix_permission_error
May 24, 2026
Merged

gh-149619: Fix _remote_debugging permissions error on Linux#150012
pablogsal merged 1 commit into
python:mainfrom
ivonastojanovic:fix_permission_error

Conversation

@ivonastojanovic
Copy link
Copy Markdown
Contributor

@ivonastojanovic ivonastojanovic commented May 18, 2026

When running profiling on Linux without sudo, attempts to read process memory would fail with the misleading error 'Failed to find the PyRuntime section in process on Linux platform'.

The actual issue is a permissions error because profiling was not run with sudo. We were clearing the exception on Linux when trying to read memory, instead, we should bubble up the permissions error and show it properly.

@ivonastojanovic ivonastojanovic changed the title gh-149619 Fix _remote_debugging permissions error on Linux gh-149619 Fix _remote_debugging permissions error on Linux May 18, 2026
When running profiling on Linux without sudo, attempts to read
process memory would fail with the misleading error 'Failed to find
the PyRuntime section in process <pid> on Linux platform'.

The actual issue is a permissions error because profiling was not
run with sudo. We were clearing the exception on Linux when trying
to read memory, instead, we should bubble up the permissions error
and show it properly.
@ivonastojanovic
Copy link
Copy Markdown
Contributor Author

cc @maurycy

Copy link
Copy Markdown
Contributor

@maurycy maurycy left a comment

Choose a reason for hiding this comment

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

@ivonastojanovic

I cannot click "Approve" but it's great. 🎉 The issue is gone. 🌬️

Two side comments!

My hunch is that there's still something subtle around error propagation (likely: EACCES propagation) but I cannot catch any!

I spent some time thinking on how to test it. What do you think about:

@unittest.skipUnless(
    sys.platform == "linux"
    and Path("/proc/sys/kernel/yama/ptrace_scope").exists()
    and int(Path("/proc/sys/kernel/yama/ptrace_scope").read_text()) >= 1,
    "needs Linux with ptrace_scope >= 1"
)

This feels so fragile!

@picnixz picnixz changed the title gh-149619 Fix _remote_debugging permissions error on Linux gh-149619: Fix _remote_debugging permissions error on Linux May 19, 2026
@pablogsal
Copy link
Copy Markdown
Member

I spent some time thinking on how to test it. What do you think about:

@unittest.skipUnless(
    sys.platform == "linux"
    and Path("/proc/sys/kernel/yama/ptrace_scope").exists()
    and int(Path("/proc/sys/kernel/yama/ptrace_scope").read_text()) >= 1,
    "needs Linux with ptrace_scope >= 1"
)

This feels so fragile!

Yeah, I think this will haunt us in the future. For now I tested manually. We can make a future PR if we find more problems in the future in this area but it wold be great to do some big audit of this.

@pablogsal pablogsal merged commit 0563890 into python:main May 24, 2026
58 checks passed
@pablogsal pablogsal added awaiting merge needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels May 24, 2026
@miss-islington-app
Copy link
Copy Markdown

Thanks @ivonastojanovic for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 24, 2026

GH-150339 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label May 24, 2026
@pablogsal
Copy link
Copy Markdown
Member

Thanks a lot @ivonastojanovic !

pablogsal pushed a commit that referenced this pull request May 24, 2026
…H-150012) (#150339)

gh-149619: Fix `_remote_debugging` permissions error on Linux (GH-150012)

When running profiling on Linux without sudo, attempts to read
process memory would fail with the misleading error 'Failed to find
the PyRuntime section in process <pid> on Linux platform'.

The actual issue is a permissions error because profiling was not
run with sudo. We were clearing the exception on Linux when trying
to read memory, instead, we should bubble up the permissions error
and show it properly.
(cherry picked from commit 0563890)

Co-authored-by: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com>
@pablogsal
Copy link
Copy Markdown
Member

Spent some time auditing all error paths of the remote debugging module and found a bunch of stuff. See #150349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants