mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
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:
parent
f519832af1
commit
ae2e864941
1 changed files with 16 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue