https://github.com/python/cpython/commit/c533f180e0e50fd9bb0cd4ca0a73bd03df69bb62
commit: c533f180e0e50fd9bb0cd4ca0a73bd03df69bb62
branch: 3.14
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-07-28T22:53:39+01:00
summary:

[3.14] gh-149619: Fix `_remote_debugging` permissions error on Linux 
(GH-150012) (#154825)

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 0563890872b3c63f94953e983fe396615b708540)

Co-authored-by: ivonastojanovic 
<[email protected]>

files:
M Python/remote_debug.h

diff --git a/Python/remote_debug.h b/Python/remote_debug.h
index 38dee987e2f5032..bacba2ed5f000f6 100644
--- a/Python/remote_debug.h
+++ b/Python/remote_debug.h
@@ -159,7 +159,9 @@ _Py_RemoteDebug_ValidatePyRuntimeCookie(proc_handle_t 
*handle, uintptr_t address
     }
     char buf[sizeof(_Py_Debug_Cookie) - 1];
     if (_Py_RemoteDebug_ReadRemoteMemory(handle, address, sizeof(buf), buf) != 
0) {
-        PyErr_Clear();
+        if (!_Py_RemoteDebug_HasPermissionError()) {
+            PyErr_Clear();
+        }
         return 0;
     }
     return memcmp(buf, _Py_Debug_Cookie, sizeof(buf)) == 0;
@@ -1062,12 +1064,14 @@ _Py_RemoteDebug_GetPyRuntimeAddress(proc_handle_t* 
handle)
     address = search_linux_map_for_section(handle, "PyRuntime", "python",
                                            
_Py_RemoteDebug_ValidatePyRuntimeCookie);
     if (address == 0) {
-        // Error out: 'python' substring covers both executable and DLL
-        PyObject *exc = PyErr_GetRaisedException();
-        PyErr_Format(PyExc_RuntimeError,
-            "Failed to find the PyRuntime section in process %d on Linux 
platform",
-            handle->pid);
-        _PyErr_ChainExceptions1(exc);
+        if (!_Py_RemoteDebug_HasPermissionError()) {
+            // Error out: 'python' substring covers both executable and DLL
+            PyObject *exc = PyErr_GetRaisedException();
+            PyErr_Format(PyExc_RuntimeError,
+                "Failed to find the PyRuntime section in process %d on Linux 
platform",
+                handle->pid);
+            _PyErr_ChainExceptions1(exc);
+        }
     }
 #elif defined(__APPLE__) && defined(TARGET_OS_OSX) && TARGET_OS_OSX
     // On macOS, try libpython first, then fall back to python

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to