authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-07 18:00:36+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-08 05:48:33+02:00
logb0ee911c2389e507d36a2f9c2442046133c18b93
tree6eabd7a69ee1acffec6b2765b41026a9816bd40e
parent7462b0e5b9d03ed6704c83f444b083a973278da5

wasi: always grant fd_readdir right

Since v0.23 release of Wasmtime, if we want to iterate a directory Y then directory Y needed to have been granted `fd_readdir` right. However, it is now also required for directory X to carry `fd_readdir` right, and so on, up-chain all the way until we reach the preopen (which possesses all rights by default). This caused problems for us since our libstd implementation is more fine-grained and allowed for parent dirs not to carry the right while allow for iterating on its children. My proposal here is to always grant `fd_readdir` right as part of `std.fs.Dir.OpenDirOptions.access_sub_paths`. This seems to be the approach taken by Rust also, plus we should be justified to take this approach since WASI is experimental and snapshot1 will be discontinued eventually and replaced with a new approach to access management that will require a complete rewrite of our libstd anyhow.

3 files changed, 5 insertions(+), 15 deletions(-)

ci/azure/linux_script+2-4
......@@ -25,10 +25,8 @@ wget -nv "https://ziglang.org/deps/$QEMUBASE.tar.xz"
2525tar xf "$QEMUBASE.tar.xz"
2626export PATH="$(pwd)/$QEMUBASE/bin:$PATH"
2727
28# Bump to v0.23 once this issue is resolved:
29# https://github.com/ziglang/zig/issues/8742
30WASMTIME="wasmtime-v0.22.1-x86_64-linux"
31wget -nv "https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/$WASMTIME.tar.xz"
28WASMTIME="wasmtime-v0.26.1-x86_64-linux"
29wget -nv "https://github.com/bytecodealliance/wasmtime/releases/download/v0.26.1/$WASMTIME.tar.xz"
3230tar xf "$WASMTIME.tar.xz"
3331export PATH="$(pwd)/$WASMTIME:$PATH"
3432
lib/std/fs.zig+2-4
......@@ -1264,11 +1264,9 @@ pub const Dir = struct {
12641264 pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
12651265 const w = os.wasi;
12661266 var base: w.rights_t = w.RIGHT_FD_FILESTAT_GET | w.RIGHT_FD_FDSTAT_SET_FLAGS | w.RIGHT_FD_FILESTAT_SET_TIMES;
1267 if (args.iterate) {
1268 base |= w.RIGHT_FD_READDIR;
1269 }
12701267 if (args.access_sub_paths) {
1271 base |= w.RIGHT_PATH_CREATE_DIRECTORY |
1268 base |= w.RIGHT_FD_READDIR |
1269 w.RIGHT_PATH_CREATE_DIRECTORY |
12721270 w.RIGHT_PATH_CREATE_FILE |
12731271 w.RIGHT_PATH_LINK_SOURCE |
12741272 w.RIGHT_PATH_LINK_TARGET |
test/stage2/wasm.zig+1-7
......@@ -56,13 +56,7 @@ pub fn addCases(ctx: *TestContext) !void {
5656 \\}
5757 \\fn bar() void {}
5858 ,
59 // This is what you get when you take the bits of the IEE-754
60 // representation of 42.0 and reinterpret them as an unsigned
61 // integer.
62 // Bug is fixed in wasmtime v0.26 but updating to v0.26 is blocked
63 // on this issue:
64 // https://github.com/ziglang/zig/issues/8742
65 "1109917696\n",
59 "42\n",
6660 );
6761
6862 case.addCompareOutput(