From b5b7ff1643dc7ddc5f5414e40016e0b302782d2b Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Sat, 27 Dec 2025 18:32:15 +0100 Subject: [PATCH] Allow access to arbitrary files if CAP_DAC_OVERRIDE is set on Linux (#15024) --- helix-stdx/Cargo.toml | 2 +- helix-stdx/src/faccess.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml index 66d02925..7fa471fe 100644 --- a/helix-stdx/Cargo.toml +++ b/helix-stdx/Cargo.toml @@ -26,7 +26,7 @@ unicode-segmentation.workspace = true windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Security", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Threading"] } [target.'cfg(unix)'.dependencies] -rustix = { version = "1.1", features = ["fs"] } +rustix = { version = "1.1", features = ["fs", "thread"] } [dev-dependencies] tempfile.workspace = true diff --git a/helix-stdx/src/faccess.rs b/helix-stdx/src/faccess.rs index b98ae153..d5bb10b2 100644 --- a/helix-stdx/src/faccess.rs +++ b/helix-stdx/src/faccess.rs @@ -29,6 +29,15 @@ mod imp { use std::os::unix::fs::{MetadataExt, PermissionsExt}; pub fn access(p: &Path, mode: AccessMode) -> io::Result<()> { + #[cfg(target_os = "linux")] + { + // If helix has ambient CAP_DAC_OVERRIDE, everything is accessible regardless of mode bits + use rustix::thread::{capability_is_in_ambient_set, CapabilitySet}; + if capability_is_in_ambient_set(CapabilitySet::DAC_OVERRIDE).unwrap_or(false) { + return Ok(()); + } + } + let mut imode = Access::empty(); if mode.contains(AccessMode::EXISTS) { -- 2.51.2