PermissionError when attaching to a remote process despite elevated privileges (file permission)
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Documentation
Description
According to the documentation of the permission requirements for remote debugging (via sys.remote_exec), the tracer process must have elevated privileges (or CAP_SYS_PTRACE).
But I get a PermissionError in the "remote" process when it tries to open the "debugger script" after I execute the tracer program with sudo on Linux. It works if I also run the app with elevated privileges.
Reproducible example
- Create a virtual environment with Python 3.14.2 and activate it
- Create the following script
app.py
# app.py
import os
import time
print("PID:", os.getpid())
print("Waiting for interrupt", end="")
while True:
print(".", end="", flush=True)
time.sleep(1)
- Run the script above via
python app.py - Create the debugger script
debug.py
# debug.py
import sys
import textwrap
from tempfile import NamedTemporaryFile
assert len(sys.argv) >= 2, "Pass PID as first argument"
pid = int(sys.argv[1])
script = 'print("Injected!")'
with NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
script_path = f.name
f.write(script)
print("Injecting...")
sys.remote_exec(pid, script_path)
print("Done :)")
- Run the debug script (in a new shell) via
sudo .venv/bin/python debug.py <pid-from-other-process>
Output of debug.py
Injecting...
Done :)
Output of app.py
PID: 27796
Waiting for interrupt.........Can't open debugger script /tmp/tmpsjqnnjw6.py:
Traceback (most recent call last):
File "/home/rafael/repos/rafaelwo/python-remote-exec-sudo/app.py", line 9, in <module>
time.sleep(1)
PermissionError: [Errno 13] Permission denied: '/tmp/tmpsjqnnjw6.py'
Expected output of app.py
PID: 27796
Waiting for interrupt............Injected!
....
What confuses me is that sudo .venv/bin/python -m pdb -p works when running the app as non-root. Doesn't pdb also create a temporary file and use sys.remote_exec to let the app run the debug attachment script?
Or is this a documentation issue, i.e. the app-to-be-traced also needs elevated privileges?
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-143575
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にリンクされているリモートデバッグのドキュメントを読み、指定された Python 3.14 のセットアップを使って Linux 上で app.py と debug.py により動作を再現してください。ドキュメントに記載された権限要件を sys.remote_exec および pdb -p の動作と比較してください。完了条件は、トレース対象のアプリにも昇格された権限が必要かどうかを、ドキュメントまたは報告された動作が明確に説明していることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools, documentation, operating-systems
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100