From d2acb8049bd87af48ec0a2982a786abc739e1a20 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 28 Aug 2023 14:58:02 +0200 Subject: [PATCH] Terminal: Support yama/ptrace_scope=1 We set "PR_SET_PTRACER" to "PR_SET_PTRACER_ANY" which will allow the debugger to attach to the inferior in both mode 0 and mode 1 of yama/ptrace_scope. Mode 2 and 3 are still not supported. Fixes: QTCREATORBUG-29554 Change-Id: I61d9ef3d9128f03769436010c6f250ccdada52bc Reviewed-by: hjk --- src/tools/process_stub/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tools/process_stub/main.cpp b/src/tools/process_stub/main.cpp index 702450f8b7f..c54480af4c1 100644 --- a/src/tools/process_stub/main.cpp +++ b/src/tools/process_stub/main.cpp @@ -25,6 +25,7 @@ #ifdef Q_OS_LINUX #include #include +#include #endif #include @@ -260,7 +261,11 @@ void setupUnixInferior() }); #else // PTRACE_TRACEME will stop execution of the child process as soon as execve is called. - inferiorProcess.setChildProcessModifier([] { ptrace(PTRACE_TRACEME, 0, 0, 0); }); + inferiorProcess.setChildProcessModifier([] { + ptrace(PTRACE_TRACEME, 0, 0, 0); + // Disable attachment restrictions so we are not bound by yama/ptrace_scope mode 1 + prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY); + }); #endif } #endif