From 5b697bb08c8e16dcaac428f17b4d95efd7862d07 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 Sep 2024 13:05:35 -0700 Subject: [PATCH] QTest::CrashHandler: allow debugging crashed tests on Linux+YAMA The YAMA LSM by default[1] prevents attaching the debugger to any process that isn't a child. Since our backtracer comes from a child process instead (i.e., tracing the parent), we must grant explicit permission. This also makes QTEST_PAUSE_ON_CRASH=1 work. [1] https://codebrowser.dev/linux/linux/security/yama/yama_lsm.c.html#ptrace_scope Change-Id: Ic19d84a7a730c7f8fc0ffffd64e516447e4b1f35 Reviewed-by: Mitch Curtis (cherry picked from commit 731b1159f9da9d0a5f9871ceaef4b82b657b130c) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qtestcrashhandler.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/testlib/qtestcrashhandler.cpp b/src/testlib/qtestcrashhandler.cpp index aabac1c4663..42a715ff865 100644 --- a/src/testlib/qtestcrashhandler.cpp +++ b/src/testlib/qtestcrashhandler.cpp @@ -61,6 +61,7 @@ #include #if defined(Q_OS_LINUX) +#include #include #include #endif @@ -327,6 +328,11 @@ void generateStackTrace() if (debugger == None || alreadyDebugging()) return; +# if defined(Q_OS_LINUX) && defined(PR_SET_PTRACER) + // allow ourselves to be debugged + (void) prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY); +# endif + # if defined(Q_OS_UNIX) && !defined(Q_OS_WASM) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_VXWORKS) writeToStderr("\n=== Stack trace ===\n");