[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); LLDB_LOG(log, "pid = {0:x}", pid); if (status.Fail()) { +auto error = CanTrace(); LLDB_LOG(log, "failed to launch process: {0}", status); +if (status.Fail()) + return error.ToError(); DavidSpickett wrote: FYI I fixed a mistake here - https://github.com/llvm/llvm-project/commit/73b2d672c1c8318cd16a02812c39ae3997b9dbcd The rest look correct to me. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen closed https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662 >From e2da8be542e7116369ab91cb0ce25163e18e76f3 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks if lldb can trace/attach/set a breakpoint a process or load a file to debug on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 39 --- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff..9c620e4807e344 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); LLDB_LOG(log, "pid = {0:x}", pid); if (status.Fail()) { +auto error = CanTrace(); LLDB_LOG(log, "failed to launch process: {0}", status); +if (status.Fail()) + return error.ToError(); return status.ToError(); } @@ -392,8 +410,11 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); - if (ret == -1) -error.SetErrorToErrno(); + if (ret == -1) { +error = CanTrace(); +if (error.Success()) + error.SetErrorToErrno(); + } if (result) *result = ret; @@ -707,8 +728,12 @@ Status NativeProcessFreeBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size, Status NativeProcessFreeBSD::GetLoadedModuleFileSpec(const char *module_path, FileSpec _spec) { Status error = PopulateMemoryRegionCache(); - if (error.Fail()) + if (error.Fail()) { +auto status = CanTrace(); +if (status.Fail()) + return status; return error; + } FileSpec module_file_spec(module_path); FileSystem::Instance().Resolve(module_file_spec); @@ -729,8 +754,12 @@ NativeProcessFreeBSD::GetFileLoadAddress(const llvm::StringRef _name, lldb::addr_t _addr) { load_addr = LLDB_INVALID_ADDRESS; Status error = PopulateMemoryRegionCache(); - if (error.Fail()) + if (error.Fail()) { +auto status = CanTrace(); +if (status.Fail()) + return status; return error; + } FileSpec file(file_name); for (const auto : m_mem_region_cache) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
emaste wrote: commit message probably needs updating for the logic change (no longer beforehand) Another reason to defer the check until failure occurs - if the user happens to be running lldb as root ptrace will be able to attach independent of the state of that sysctl https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/emaste approved this pull request. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/bulbazord approved this pull request. LGTM but I'm not really an expert on FreeBSD. @emaste ? https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
devnexen wrote: ping :) https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662 >From 7cfed8b3440d9257598fe94e02adc4d926692850 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 39 --- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff..9c620e4807e344 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); LLDB_LOG(log, "pid = {0:x}", pid); if (status.Fail()) { +auto error = CanTrace(); LLDB_LOG(log, "failed to launch process: {0}", status); +if (status.Fail()) + return error.ToError(); return status.ToError(); } @@ -392,8 +410,11 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); - if (ret == -1) -error.SetErrorToErrno(); + if (ret == -1) { +error = CanTrace(); +if (error.Success()) + error.SetErrorToErrno(); + } if (result) *result = ret; @@ -707,8 +728,12 @@ Status NativeProcessFreeBSD::SetBreakpoint(lldb::addr_t addr, uint32_t size, Status NativeProcessFreeBSD::GetLoadedModuleFileSpec(const char *module_path, FileSpec _spec) { Status error = PopulateMemoryRegionCache(); - if (error.Fail()) + if (error.Fail()) { +auto status = CanTrace(); +if (status.Fail()) + return status; return error; + } FileSpec module_file_spec(module_path); FileSystem::Instance().Resolve(module_file_spec); @@ -729,8 +754,12 @@ NativeProcessFreeBSD::GetFileLoadAddress(const llvm::StringRef _name, lldb::addr_t _addr) { load_addr = LLDB_INVALID_ADDRESS; Status error = PopulateMemoryRegionCache(); - if (error.Fail()) + if (error.Fail()) { +auto status = CanTrace(); +if (status.Fail()) + return status; return error; + } FileSpec file(file_name); for (const auto : m_mem_region_cache) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662 >From 746a6959e270b086184ce095b11eb4df691dc4c9 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 27 --- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff..24726832fa4598 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,20 +48,38 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); LLDB_LOG(log, "pid = {0:x}", pid); if (status.Fail()) { +auto error = CanTrace(); LLDB_LOG(log, "failed to launch process: {0}", status); +if (status.Fail()) + return error.ToError(); return status.ToError(); } @@ -392,8 +410,11 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); - if (ret == -1) -error.SetErrorToErrno(); + if (ret == -1) { +error = CanTrace(); +if (error.Success()) + error.SetErrorToErrno(); + } if (result) *result = ret; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); bulbazord wrote: Thanks for the explanation. Consider my concerns addressed, don't let my "Requested Changes" block this from going in after another approval. :) https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
emaste wrote: Thanks for picking this up -- I was starting to take a look but was sidetracked with a lot of yak shaving. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,36 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + + status = CanTrace(); emaste wrote: I might suggest moving these checks into the Fail case below, avoiding the extra syscall that's not necessary in the common case. Also, we may have other cases we could start checking for. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); emaste wrote: It's had the current name for over 2 decades, https://github.com/freebsd/freebsd-src/commit/e409590d0e0e57c6ec37d95bcb9fa3728051ebb1 The sysctl existed prior to that with a different name; I didn't bother looking to see when that was introduced. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662 >From 7fccec625677e8cabe8c69ac2651c37716dc30bf Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 28 ++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff6..9692670e851c77a 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,14 +48,36 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return {}; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + + status = CanTrace(); + + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); @@ -388,6 +410,10 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, Status error; int ret; + error = CanTrace(); + if (error.Fail()) +return error; + errno = 0; ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; devnexen wrote: true https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); devnexen wrote: since a long time :) e.g. even 9.0, EOL since more than a decade, had it. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); bulbazord wrote: How long has FreeBSD had `security.bsd.unprivileged_proc_debug`? If you're debugging an older FreeBSD system that does not have it, this will prevent it from debugging anything. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
@@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; bulbazord wrote: Suggestion: You can remove this and just return {} below. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/bulbazord edited https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/bulbazord requested changes to this pull request. https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79662 >From 52618e6e6e028ea4a65728eda0c877dce176ccfa Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 29 ++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff6..b676d536ca89495 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); + if (ret != 0) +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + + if (proc_debug < 1) +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); + + return status; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + + status = CanTrace(); + + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); @@ -388,6 +411,10 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, Status error; int ret; + error = CanTrace(); + if (error.Fail()) +return error; + errno = 0; ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff e4afffbe8cc31278a9006712e7323d49eae9dbb6 492521e66288a497bf5b4a4a8ce554dffeb35727 -- lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 7540ba2965..a2062bd3a9 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -52,13 +52,15 @@ static Status CanTrace() { Status status; int proc_debug, ret; size_t len = sizeof(proc_debug); - ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, , nullptr, 0); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, + , nullptr, 0); if (ret != 0) { return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); } if (proc_debug < 1) { -return Status("process debug disabled by security.bsd.unprivileged_proc_debug oid"); +return Status( +"process debug disabled by security.bsd.unprivileged_proc_debug oid"); } return status; `` https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: David CARLIER (devnexen) Changes before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- Full diff: https://github.com/llvm/llvm-project/pull/79662.diff 1 Files Affected: - (modified) lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp (+28-1) ``diff diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff6..7540ba296517821 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, , nullptr, 0); + if (ret != 0) { +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + } + + if (proc_debug < 1) { +return Status("process debug disabled by security.bsd.unprivileged_proc_debug oid"); + } + + return status; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + + status = CanTrace(); + + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); @@ -388,6 +411,10 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, Status error; int ret; + error = CanTrace(); + if (error.Fail()) +return error; + errno = 0; ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); `` https://github.com/llvm/llvm-project/pull/79662 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. (PR #79662)
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/79662 before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 >From 492521e66288a497bf5b4a4a8ce554dffeb35727 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 26 Jan 2024 22:47:15 + Subject: [PATCH] [lldb] checks beforehand if lldb can trace/attach a process on FreeBSD. before having the generic EINVAL message, we check if the `security.bsd.unprivileged_proc_debug` allows process debugging. close #79634 --- .../Process/FreeBSD/NativeProcessFreeBSD.cpp | 29 ++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp index 19e0986ace31ff..7540ba29651782 100644 --- a/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/NativeProcessFreeBSD.cpp @@ -48,14 +48,37 @@ static Status EnsureFDFlags(int fd, int flags) { return error; } +static Status CanTrace() { + Status status; + int proc_debug, ret; + size_t len = sizeof(proc_debug); + ret = ::sysctlbyname("security.bsd.unprivileged_proc_debug", _debug, , nullptr, 0); + if (ret != 0) { +return Status("sysctlbyname() security.bsd.unprivileged_proc_debug failed"); + } + + if (proc_debug < 1) { +return Status("process debug disabled by security.bsd.unprivileged_proc_debug oid"); + } + + return status; +} + // Public Static Methods llvm::Expected> NativeProcessFreeBSD::Manager::Launch(ProcessLaunchInfo _info, NativeDelegate _delegate) { Log *log = GetLog(POSIXLog::Process); - Status status; + + status = CanTrace(); + + if (status.Fail()) { +LLDB_LOG(log, "failed to launch process: {0}", status); +return status.ToError(); + } + ::pid_t pid = ProcessLauncherPosixFork() .LaunchProcess(launch_info, status) .GetProcessId(); @@ -388,6 +411,10 @@ Status NativeProcessFreeBSD::PtraceWrapper(int req, lldb::pid_t pid, void *addr, Status error; int ret; + error = CanTrace(); + if (error.Fail()) +return error; + errno = 0; ret = ptrace(req, static_cast<::pid_t>(pid), static_cast(addr), data); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits