diff options
author | Jordan Rupprecht <rupprecht@google.com> | 2023-03-02 13:51:30 -0800 |
---|---|---|
committer | Jordan Rupprecht <rupprecht@google.com> | 2023-03-02 13:51:30 -0800 |
commit | 6db44e52ce474bbeb66042073a6e3c6c586f78a2 (patch) | |
tree | 4ac9a857e4c6ab01b2b63095700d34008c25ba91 /lldb/unittests | |
parent | 9679075a1ae6a20ed102597bf166b3f3adc95499 (diff) | |
download | llvm-6db44e52ce474bbeb66042073a6e3c6c586f78a2.tar.gz |
[Linux] Add kernel.yama.ptrace_scope note when ptrace fails to attach.
A common reason for LLDB failing to attach to an already-running process on Linux is the Yama security module: https://www.kernel.org/doc/Documentation/security/Yama.txt. This patch adds an explaination and suggested fix when it detects that case happening.
This was previously proposed in D106226, but hasn't been updated in a while. The last request was to put the check in a target-specific location, which is the approach this patch takes. I believe Yama only exists on Linux, so it's put in that package.
This has no end-to-end test because I'm not sure how to set `ptrace_scope` in a test environment -- if there are suggestions on how to do that, I'd be happy to add it. (Also, setting it to `3` is comically irreversible). I tested this locally.
Reviewed By: DavidSpickett, labath
Differential Revision: https://reviews.llvm.org/D144904
Diffstat (limited to 'lldb/unittests')
-rw-r--r-- | lldb/unittests/Process/Linux/ProcfsTests.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lldb/unittests/Process/Linux/ProcfsTests.cpp b/lldb/unittests/Process/Linux/ProcfsTests.cpp index c069091b7b06..d95de649ed57 100644 --- a/lldb/unittests/Process/Linux/ProcfsTests.cpp +++ b/lldb/unittests/Process/Linux/ProcfsTests.cpp @@ -102,3 +102,19 @@ TEST(Perf, RealLogicalCoreIDs) { ASSERT_TRUE((bool)cpu_ids); ASSERT_GT((int)cpu_ids->size(), 0) << "We must see at least one core"; } + +TEST(Perf, RealPtraceScope) { + // We first check we can read /proc/sys/kernel/yama/ptrace_scope + auto buffer_or_error = + errorOrToExpected(getProcFile("sys/kernel/yama/ptrace_scope")); + if (!buffer_or_error) + GTEST_SKIP() << toString(buffer_or_error.takeError()); + + // At this point we shouldn't fail parsing the ptrace_scope value. + Expected<int> ptrace_scope = GetPtraceScope(); + ASSERT_TRUE((bool)ptrace_scope) << ptrace_scope.takeError(); + ASSERT_GE(*ptrace_scope, 0) + << "Sensible values of ptrace_scope are between 0 and 3"; + ASSERT_LE(*ptrace_scope, 3) + << "Sensible values of ptrace_scope are between 0 and 3"; +} |