PermissionError when attaching to a remote process despite elevated privileges (file permission)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Đọc tài liệu về gỡ lỗi từ xa được liên kết trong issue, sau đó tái hiện hành vi bằng app.py và debug.py trên Linux với thiết lập Python 3.14 đã nêu. So sánh các yêu cầu về quyền được ghi trong tài liệu với sys.remote_exec và hành vi của pdb -p; công việc được xem là hoàn tất khi tài liệu hoặc hành vi được báo cáo giải thích rõ liệu ứng dụng được trace cũng cần các đặc quyền nâng cao hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- devtools, documentation, operating-systems
- Loại issue
- Tài liệu
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100