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.
This commit is contained in:
Marco Allegretti 2026-10-09 18:06:59 +00:00
parent f519832af1
commit ae2e864941
No known key found for this signature in database

View file

@ -217,7 +217,18 @@ fn open_beneath(
Mode::empty(), Mode::empty(),
ResolveFlags::BENEATH | ResolveFlags::NO_MAGICLINKS, 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")] #[cfg(target_os = "linux")]
@ -521,6 +532,10 @@ mod tests {
} }
// A write to a name that is a link replaces the link, inside the // A write to a name that is a link replaces the link, inside the
// directory, rather than writing where it points. // 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!( assert!(matches!(
handle_request(write_req(&granted.join("up"), b"x"), &roots), handle_request(write_req(&granted.join("up"), b"x"), &roots),
Response::Ok Response::Ok