From ae2e864941cbe4dc8e42da54b6e5410f7e4dfa0d Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 18:06:59 +0000 Subject: [PATCH] fix(portal): report a path leading out of the granted directory as denied openat2 reports a resolution that would leave the directory as EXDEV, which reached clients as an invalid cross-device link. --- crates/weft-file-portal/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/weft-file-portal/src/main.rs b/crates/weft-file-portal/src/main.rs index 8b4815f..efb7cbf 100644 --- a/crates/weft-file-portal/src/main.rs +++ b/crates/weft-file-portal/src/main.rs @@ -217,7 +217,18 @@ fn open_beneath( Mode::empty(), ResolveFlags::BENEATH | ResolveFlags::NO_MAGICLINKS, ) - .map_err(std::io::Error::from) + .map_err(|e| { + // The kernel reports a resolution that would leave the directory as + // EXDEV. + if e == rustix::io::Errno::XDEV { + std::io::Error::new( + std::io::ErrorKind::PermissionDenied, + "access denied: the path leads out of the granted directory", + ) + } else { + e.into() + } + }) } #[cfg(target_os = "linux")] @@ -521,6 +532,10 @@ mod tests { } // A write to a name that is a link replaces the link, inside the // directory, rather than writing where it points. + match handle_request(read_req(&granted.join("root/etc/passwd")), &roots) { + Response::Err { error } => assert!(error.contains("leads out"), "{error}"), + _ => panic!("read through a link out of the directory"), + } assert!(matches!( handle_request(write_req(&granted.join("up"), b"x"), &roots), Response::Ok