The Wayback Machine - https://web.archive.org/web/20250530084553/https://github.com/python/cpython/issues/134546
Skip to content

-m pdb -p -- other side cannot read debug script due to too-strict permissions #134546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
asottile opened this issue May 22, 2025 · 2 comments
Closed
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@asottile
Copy link
Contributor

asottile commented May 22, 2025

Bug report

Bug description:

  1. run python3.14
  2. find its pid
  3. sudo python3.14 -m pdb -p $pid

the pdb tab will hang, the other side will display similar to:

Python 3.14.0b1 (main, May  8 2025, 08:57:13) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> Can't open debugger script /tmp/tmpmbdwo7d_:
                                                Traceback (most recent call last):
    File "/usr/lib/python3.14/_pyrepl/unix_console.py", line 422, in wait
                                                                             or bool(self.pollob.poll(timeout))
                               PermissionError: [Errno 13] Permission denied: '/tmp/tmpmbdwo7d_'

the debugger script needs to at least be readable by the unprivileged user to be opened:

$ ls -al /tmp/tmpmbdwo7d_
-rw------- 1 root root 190 May 22 16:51 /tmp/tmpmbdwo7d_

tempfile.NamedTemporaryFile("w", delete_on_close=False)

I believe a patch similar to this fixes it:

diff --git a/Lib/pdb.py b/Lib/pdb.py
index 78ee35f61bb..bb12d1baae8 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -75,6 +75,7 @@
 import code
 import glob
 import json
+import stat
 import token
 import types
 import atexit
@@ -3418,6 +3419,7 @@ def attach(pid, commands=()):
             )
         )
         connect_script.close()
+        os.chmod(connect_script.name, os.stat(connect_script.name).st_mode | stat.S_IRGRP | stat.S_IROTH)
         sys.remote_exec(pid, connect_script.name)
 
         # TODO Add a timeout? Or don't bother since the user can ^C?

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

@asottile asottile added the type-bug An unexpected behavior, bug, or error label May 22, 2025
@gaogaotiantian
Copy link
Member

That looks like the right solution to me. Do you want to make a PR? Or I can do it.

@asottile
Copy link
Contributor Author

I can start one!

@emmatyping emmatyping added 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels May 23, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label May 23, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 24, 2025
gaogaotiantian pushed a commit that referenced this issue May 24, 2025
…134616)

gh-134546: ensure remote pdb script is readable (GH-134552)
(cherry picked from commit 74a9c60)

Co-authored-by: Anthony Sottile <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants