-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release 9.0.0 branch: fix directory open rights (#6479)
* fix the directory base & inheriting rights in order to work with wasi-testsuite, it needs to be possible to path_open(dirfd, ".", ...) with the same rights reported in the fdstat of that dirfd. When we report the Rights::all() set, both FD_READ and FD_WRITE are set in the base rights, which results in unix rejecting an openat2(dirfd, ".", O_RDWR) with EISDIR. By not having the FD_READ and FD_WRITE rights present in the base rights, the open syscall defaults to O_RDONLY, which is the only access mode allowed for opening directories. * path_open of a directory with read and write succeeds on windows * fix test introduced as part of 9.0.2
- Loading branch information
Pat Hickey
authored
May 31, 2023
1 parent
0aa0047
commit 61cc2fa
Showing
3 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
crates/test-programs/wasi-tests/src/bin/path_open_preopen.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const FIRST_PREOPEN: u32 = 3; | ||
|
||
unsafe fn path_open_preopen() { | ||
let prestat = wasi::fd_prestat_get(FIRST_PREOPEN).expect("fd 3 is a preopen"); | ||
assert_eq!( | ||
prestat.tag, | ||
wasi::PREOPENTYPE_DIR.raw(), | ||
"prestat is a directory" | ||
); | ||
let mut dst = Vec::with_capacity(prestat.u.dir.pr_name_len); | ||
wasi::fd_prestat_dir_name(FIRST_PREOPEN, dst.as_mut_ptr(), dst.capacity()) | ||
.expect("get preopen dir name"); | ||
dst.set_len(prestat.u.dir.pr_name_len); | ||
|
||
let fdstat = wasi::fd_fdstat_get(FIRST_PREOPEN).expect("get fdstat"); | ||
|
||
println!( | ||
"preopen dir: {:?} base {:?} inheriting {:?}", | ||
String::from_utf8_lossy(&dst), | ||
fdstat.fs_rights_base, | ||
fdstat.fs_rights_inheriting | ||
); | ||
|
||
// Open with same rights it has now: | ||
let _ = wasi::path_open( | ||
FIRST_PREOPEN, | ||
0, | ||
".", | ||
0, | ||
fdstat.fs_rights_base, | ||
fdstat.fs_rights_inheriting, | ||
0, | ||
) | ||
.expect("open with same rights"); | ||
|
||
// Open with an empty set of rights: | ||
let _ = wasi::path_open(FIRST_PREOPEN, 0, ".", 0, 0, 0, 0).expect("open with empty rights"); | ||
|
||
// Open OFLAGS_DIRECTORY with an empty set of rights: | ||
let _ = wasi::path_open(FIRST_PREOPEN, 0, ".", wasi::OFLAGS_DIRECTORY, 0, 0, 0) | ||
.expect("open with O_DIRECTORY empty rights"); | ||
|
||
// Open OFLAGS_DIRECTORY with just the read right: | ||
let _ = wasi::path_open( | ||
FIRST_PREOPEN, | ||
0, | ||
".", | ||
wasi::OFLAGS_DIRECTORY, | ||
wasi::RIGHTS_FD_READ, | ||
0, | ||
0, | ||
) | ||
.expect("open with O_DIRECTORY and read right"); | ||
|
||
if !wasi_tests::TESTCONFIG.errno_expect_windows() { | ||
// Open OFLAGS_DIRECTORY and read/write rights should fail with isdir: | ||
let err = wasi::path_open( | ||
FIRST_PREOPEN, | ||
0, | ||
".", | ||
wasi::OFLAGS_DIRECTORY, | ||
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE, | ||
0, | ||
0, | ||
) | ||
.err() | ||
.expect("open with O_DIRECTORY and read/write should fail"); | ||
assert_eq!( | ||
err, | ||
wasi::ERRNO_ISDIR, | ||
"opening directory read/write should fail with ISDIR" | ||
); | ||
} else { | ||
// Open OFLAGS_DIRECTORY and read/write rights will succeed, only on windows: | ||
let _ = wasi::path_open( | ||
FIRST_PREOPEN, | ||
0, | ||
".", | ||
wasi::OFLAGS_DIRECTORY, | ||
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE, | ||
0, | ||
0, | ||
) | ||
.expect("open with O_DIRECTORY and read/write should succeed on windows"); | ||
} | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
path_open_preopen(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters