-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fopen
/openat
does not seem to preserve access flags
#415
Comments
Can you please run wasmtime with the environment variable |
|
The behavior changed in Log from |
diff between wasmtime 8 and wasmtime 9, with the same wasm file. |
Thanks. Can you please move this bug over to the wasmtime repository? This appears to be a bug over there, not in wasi-libc. |
Something changed in wasmtime, but I'm not sure Looking at the traces, for the same code, this is what we see without
and with
|
This is the |
Just to make a clarification:
This is referring to how the problem was manifesting in the Zig test suite, where it'd try to open a directory with The reproduction in the OP of this issue does not include that wrinkle and is instead focused on just the flags being passed to the syscall, since I realized the problem is more general than just opening directories for writing. |
This is a bug in Wasmtime 9.0.{0,1}. I have prepared a fix which we will release as 9.0.2. The behavior is the same across wasi-sdk 19 and 20, I did not test any further back but I believe it is the same for a long time. In the original test case given, this line:
will actually open a file read-only. The mode string to open read-write is I made variants of that test for read-only (
|
Awesome! Thank you Pat! |
This seems to have regressed, but AFAICT only when using a non- #include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
mkdirat(AT_FDCWD, "testdir", 0777);
{
// Opening with O_RDWR fails as expected if the dirfd is AT_FDCWD
int dir = openat(AT_FDCWD, "testdir", O_RDWR);
if (dir != -1) return 1;
}
// Open "testdir" for real now since we want to use it as the dirfd for openat
int dir = openat(AT_FDCWD, "testdir", O_RDONLY|O_DIRECTORY);
mkdirat(dir, "subdir", 0777);
// Try to open the subdir with O_RDWR, this should fail with EISDIR but it succeeds
// because the O_RDWR is lost and the openat2 syscall is called with O_RDONLY
// instead
int testdir = openat(dir, "subdir", O_RDWR);
if (testdir != -1) return 1;
return 0;
} $ WASI_SDK=/home/ryan/Downloads/wasi-sdk-23.0-x86_64-linux
$ $WASI_SDK/bin/clang --sysroot=$WASI_SDK/share/wasi-sysroot open-dir-tmpdir-rw.c -o open-dir-tmpdir-rw-sdk-23.wasm
$ strace -e trace=openat2 wasmtime --dir=. open-dir-tmpdir-rw-sdk-23.wasm
openat2(3, "testdir", {flags=O_RDWR|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = -1 EISDIR (Is a directory)
openat2(3, "testdir", {flags=O_RDONLY|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = 11
openat2(11, "subdir", {flags=O_RDONLY|O_LARGEFILE|O_CLOEXEC, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_BENEATH}, 24) = 12
+++ exited with 1 +++ The |
Tested on Linux with
wasmtime
v9.0.1
andwasi-sdk-20.0
.The following code (saved as
open-rw.c
) tries to open a file (that exists) for reading and writing:EDIT: The above code originally used the invalid flags
"rw"
, it has been corrected to use"w"
However, when using
wasi-libc
, the actual syscall (for me it'sopenat2
) is being passedO_RDONLY
instead of the expectedO_WRONLY
. Note: same applies toO_RDWR
,O_RDONLY
is still passed instead.Compiled with
wasi-sdk-20.0
:Note that access flags are preserved in the equivalent Zig code (unless
-lc
to link libc is used in which casewasi-libc
is built/linked and theO_RDONLY
behavior occurs)And are also preserved in the equivalent Rust code:
The text was updated successfully, but these errors were encountered: