From 1af3e6b45f561881ab514d383c4630963287aa32 Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Wed, 7 May 2025 11:20:03 -0400 Subject: [PATCH 1/2] Fix Yama blocking child-to-parent ptrace --- tests/common/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2b5499ef..f470f1bb 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -9,6 +9,12 @@ type Error = Box; pub type Result = result::Result; fn build_command() -> Command { + // Anything that needs to spawn a child will need to give it permission to + // ptrace itself, as Yama LSM will normally only allow a parent to debug + // a child, not the other way around. + let rc = unsafe { libc::prctl(libc::PR_SET_PTRACER, libc::PR_SET_PTRACER_ANY) }; + assert_eq!(rc, 0); + let mut cmd; if let Some(binary) = std::env::var_os("TEST_HELPER") { cmd = Command::new(binary); From 9e7d3dbd163a50d3c521cbc3494a2be04f5936ef Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Mon, 12 May 2025 16:05:07 +0200 Subject: [PATCH 2/2] Gate prctl --- tests/common/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index f470f1bb..745e3a9a 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -12,8 +12,11 @@ fn build_command() -> Command { // Anything that needs to spawn a child will need to give it permission to // ptrace itself, as Yama LSM will normally only allow a parent to debug // a child, not the other way around. - let rc = unsafe { libc::prctl(libc::PR_SET_PTRACER, libc::PR_SET_PTRACER_ANY) }; - assert_eq!(rc, 0); + #[cfg(target_os = "linux")] + { + let rc = unsafe { libc::prctl(libc::PR_SET_PTRACER, libc::PR_SET_PTRACER_ANY) }; + assert_eq!(rc, 0); + } let mut cmd; if let Some(binary) = std::env::var_os("TEST_HELPER") {