Userzxcvbvnm added the bug label to Issue #8840.
Userzxcvbvnm opened issue #8840:
Test Case
The c test case is:
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int get_fd(const char *filename, int flags) { int fd = open(filename, flags); if (fd == -1) { printf("Get file descriptor of file %s failed!\n", filename); return -1; } else { printf("Get file descriptor of file %s succeed!\n", filename); return fd; } } void closebyfd(int fd) { if (close(fd) == -1) { printf("Close the file %d by descriptor failed!\n", fd); } } void path_link_00001_Nan21() { printf("Enter function path_link_00001_Nan21\n"); int result = linkat(AT_FDCWD, "subdir_1/subdir_3/subfile_1", AT_FDCWD, "HARDLINKFILE", AT_SYMLINK_FOLLOW); if (result == -1) { printf("linkat failed"); } else { printf("Hard link creation successful\n"); } } int main() { printf("Enter function main\n"); path_link_00001_Nan21(); return 0; }
Steps to Reproduce
(1)compile to wasm:
./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm
(2)Running wasm:
(Before run the Wasm file, file subdir_1/subdir_3/subfile_1 exists.)
wasmtime run --dir=. test.wasm
Expected Results
Successfully create the link file and print:
Enter function main Enter function path_link_00001_Nan21 Hard link creation successful
This is what WAMR and WasmEdge do.
Actual Results
wasmtime prints:
Enter function main Enter function path_link_00001_Nan21 linkat failed
However, with the parameter AT_SYMLINK_NOFOLLOW, wasmtime could cucceed, but with parameter AT_SYMLINK_FOLLOW, wasmtime fails.
The parameter AT_SYMLINK_FOLLOW means if the file subdir_1/subdir_3/subfile_1 is a softlink file, the file HARDLINKFILE is expected to points to the source file of subdir_1/subdir_3/subfile_1. In this case, subdir_1/subdir_3/subfile_1 is a not a softlink file, but, I think, in this way,it is expected that HARDLINKFILE points to subdir_1/subdir_3/subfile_1 directly.
I'm not sure whether this is a bug.Versions and Environment
Wasmtime version or commit: 19.0.2
Operating system: Ubuntu 20.04
Architecture: x86_64
bjorn3 commented on issue #8840:
Looks like
AT_SYMLINK_FOLLOW
is explicitly denied: https://github.com/bytecodealliance/wasmtime/blob/95fee6f4bd0b96460dfc5411ff678d0b2967b772/crates/wasi/src/host/filesystem.rs#L483-L485 This is explicitly required by the wasi test suite: https://github.com/WebAssembly/wasi-testsuite/blob/2fec29ea6de1244c124f7fe3bfe9f2946113f66e/tests/rust/src/bin/path_link.rs#L177-L189 (seems to originate from https://github.com/bytecodealliance/wasmtime/commit/17f43d4cc347a54e34e7a0e65a34e5faef92919e) Wasmtime has been rejectingAT_SYMLINK_FOLLOW
onpath_link
since https://github.com/bytecodealliance/wasmtime/commit/fded424e689dd5f5a3f3e1539f4bc2b36a6e324e.
Userzxcvbvnm edited issue #8840:
Test Case
The c test case is:
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int get_fd(const char *filename, int flags) { int fd = open(filename, flags); if (fd == -1) { printf("Get file descriptor of file %s failed!\n", filename); return -1; } else { printf("Get file descriptor of file %s succeed!\n", filename); return fd; } } void closebyfd(int fd) { if (close(fd) == -1) { printf("Close the file %d by descriptor failed!\n", fd); } } void path_link_00001_Nan21() { printf("Enter function path_link_00001_Nan21\n"); int result = linkat(AT_FDCWD, "subdir_1/subdir_3/subfile_1", AT_FDCWD, "HARDLINKFILE", AT_SYMLINK_FOLLOW); if (result == -1) { printf("linkat failed"); } else { printf("Hard link creation successful\n"); } } int main() { printf("Enter function main\n"); path_link_00001_Nan21(); return 0; }
Steps to Reproduce
(1)compile to wasm:
./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm
(2)Running wasm:
(Before run the Wasm file, file subdir_1/subdir_3/subfile_1 exists.)
wasmtime run --dir=. test.wasm
Expected Results
Successfully create the link file and print:
Enter function main Enter function path_link_00001_Nan21 Hard link creation successful
This is what WAMR and WasmEdge do.
Actual Results
wasmtime prints:
Enter function main Enter function path_link_00001_Nan21 linkat failed
However, with the parameter AT_SYMLINK_NOFOLLOW, wasmtime could cucceed, but with parameter AT_SYMLINK_FOLLOW, wasmtime fails.
The parameter AT_SYMLINK_FOLLOW means if the file subdir_1/subdir_3/subfile_1 is a softlink file, the file HARDLINKFILE is expected to points to the source file of subdir_1/subdir_3/subfile_1. In this case, subdir_1/subdir_3/subfile_1 is a not a softlink file, but, I think, in this way,it is expected that HARDLINKFILE points to subdir_1/subdir_3/subfile_1 directly.
I'm not sure whether this is a bug.Versions and Environment
Wasmtime version or commit: 19.0.2 and 13.0.1
Operating system: Ubuntu 20.04
Architecture: x86_64
Last updated: Nov 22 2024 at 17:03 UTC