From e0db274ee61913026c0981d3995c849b4154824d Mon Sep 17 00:00:00 2001 From: Daniel Burgener Date: Thu, 16 Jul 2026 17:32:05 -0400 Subject: [PATCH] Open user_events_data with O_CLOEXEC When we open /sys/kernel/tracing/user_events_data, we get a fd that we keep alive for future tracing. Without O_CLOEXEC, this fd is inherited by all child processes. In some situations, this could cause security issues if a child process is not authorized to write trace events, but has a file descriptor available to do so, since many access control systems only check permissions on open(). O_CLOEXEC prevents this by ensuring that the fd is closed prior to any exec() to a child process. --- tracepoint/src/native.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracepoint/src/native.rs b/tracepoint/src/native.rs index 0a50213..b49b34f 100644 --- a/tracepoint/src/native.rs +++ b/tracepoint/src/native.rs @@ -36,11 +36,11 @@ fn clear_errno() { unsafe { *linux::__errno_location() = 0 }; } -/// linux::open(path0, O_WRONLY) +/// linux::open(path0, O_WRONLY | O_CLOEXEC) #[cfg(all(target_os = "linux", feature = "user_events"))] fn open_wronly(path0: &[u8]) -> ffi::c_int { assert!(path0.ends_with(&[0])); - return unsafe { linux::open(path0.as_ptr().cast::(), linux::O_WRONLY) }; + return unsafe { linux::open(path0.as_ptr().cast::(), linux::O_WRONLY | linux::O_CLOEXEC) }; } struct UserEventsDataFile {