orangeC23 added the bug label to Issue #7347.
orangeC23 opened issue #7347:
Steps to Reproduce
(1) The cfile is :
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <string.h> int path_create_directory(int fd, const char *base_directory, const char *new_directory, mode_t right){ printf("Enter path_create_directory.\n"); if (mkdirat(fd, new_directory, right) == -1) { perror("Error creating new directory"); close(fd); return 1; } printf("Directory '%s' created under '%s'\n", new_directory, base_directory); printf("Leave path_create_directory.\n"); return fd; } int snapshot(int myfd){ printf("Enter snapshot\n"); struct stat file_info; if (fstat(myfd, &file_info) == -1) { perror("Error getting file attributes"); close(myfd); return 1; } printf("File Size: %lld bytes \n", (long long)file_info.st_size); if (close(myfd) == -1) { perror("Error closing file"); return 1; } printf("Leave snapshot\n"); } int get_fd(const char* file_name, int open_style){ int fd = open(file_name, open_style); if (fd == -1) { perror("Failed to open the file"); return 1; } return fd; } int path_create_directoryZOyjKVxmtB (int fd, const char *base_directory){ const char *new_directory = "newdir"; mode_t right = 0200; return path_create_directory(fd, base_directory, new_directory, right); } int main() { const char* file_name = "Data/mydir"; int open_style= O_RDONLY; int fd = get_fd(file_name, open_style); path_create_directoryZOyjKVxmtB(fd, file_name); snapshot(fd); return 0; }
(2)compile the c file into wasm:
./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot createdir.c -o createdir.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data createdir.wasm
The permission of Data/mydir is 0700, user1 create the Data/mydir directory before and user1 execute the Wasm file.Expected Results
Using
gcc createdir.c -o createdir
and./createdir
to execute get the following result:Enter path_create_directory. Directory 'newdir' created under 'Data/mydir' Leave path_create_directory. Enter snapshot File Size: 4096 bytes Leave snapshot
And using 'ls -al' to check the newdir, the result is -w-------,this is the same as the C source code setting "0200".
Actual Results
wasmtime also prints:
Enter path_create_directory. Directory 'newdir' created under 'Data/mydir' Leave path_create_directory. Enter snapshot File Size: 4096 bytes Leave snapshot
However, using 'ls -al' to check the newdir, the result is drwxr-xr-x, which is different from the C source code setting "0200".
I'm not sure whether this could be a bug. Maybe a bug or something different?
Thanks a lot !Versions and Environment
wasmtime 13.0.0
Operating system: Ubuntu 20.04Architecture: x86_64
bjorn3 commented on issue #7347:
Wasi doesn't have a way to get or set permissions for files and directories. Creating a directory is literally
path_create_directory(fd: fd, path: string) -> Result<(), errno>
. It has a permission system called "rights", but those only apply not file descriptors, not the stored files.
pchickey commented on issue #7347:
@bjorn3 is correct - WASI doesn't specify any sort of behavior for the permissions of files and directories on the host filesystem, and none of the WASI Preview 1 functions expose any way to view, set, or change permissions. So, each implementation is free to behave however they see fit with regard to permissions.
pchickey closed issue #7347:
Steps to Reproduce
(1) The cfile is :
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <string.h> int path_create_directory(int fd, const char *base_directory, const char *new_directory, mode_t right){ printf("Enter path_create_directory.\n"); if (mkdirat(fd, new_directory, right) == -1) { perror("Error creating new directory"); close(fd); return 1; } printf("Directory '%s' created under '%s'\n", new_directory, base_directory); printf("Leave path_create_directory.\n"); return fd; } int snapshot(int myfd){ printf("Enter snapshot\n"); struct stat file_info; if (fstat(myfd, &file_info) == -1) { perror("Error getting file attributes"); close(myfd); return 1; } printf("File Size: %lld bytes \n", (long long)file_info.st_size); if (close(myfd) == -1) { perror("Error closing file"); return 1; } printf("Leave snapshot\n"); } int get_fd(const char* file_name, int open_style){ int fd = open(file_name, open_style); if (fd == -1) { perror("Failed to open the file"); return 1; } return fd; } int path_create_directoryZOyjKVxmtB (int fd, const char *base_directory){ const char *new_directory = "newdir"; mode_t right = 0200; return path_create_directory(fd, base_directory, new_directory, right); } int main() { const char* file_name = "Data/mydir"; int open_style= O_RDONLY; int fd = get_fd(file_name, open_style); path_create_directoryZOyjKVxmtB(fd, file_name); snapshot(fd); return 0; }
(2)compile the c file into wasm:
./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot createdir.c -o createdir.wasm
(3)exeute open.wasm
wasmtime run --dir=./Data createdir.wasm
The permission of Data/mydir is 0700, user1 create the Data/mydir directory before and user1 execute the Wasm file.Expected Results
Using
gcc createdir.c -o createdir
and./createdir
to execute get the following result:Enter path_create_directory. Directory 'newdir' created under 'Data/mydir' Leave path_create_directory. Enter snapshot File Size: 4096 bytes Leave snapshot
And using 'ls -al' to check the newdir, the result is -w-------,this is the same as the C source code setting "0200".
Actual Results
wasmtime also prints:
Enter path_create_directory. Directory 'newdir' created under 'Data/mydir' Leave path_create_directory. Enter snapshot File Size: 4096 bytes Leave snapshot
However, using 'ls -al' to check the newdir, the result is drwxr-xr-x, which is different from the C source code setting "0200".
I'm not sure whether this could be a bug. Maybe a bug or something different?
Thanks a lot !Versions and Environment
wasmtime 13.0.0
Operating system: Ubuntu 20.04Architecture: x86_64
pchickey edited a comment on issue #7347:
@bjorn3 is correct - WASI doesn't specify any sort of behavior for the permissions of files and directories on the host filesystem, and none of the WASI Preview 1 functions expose any way to view, set, or change permissions. So, each implementation is free to behave however they see fit with regard to permissions.
In your implementation,
mkdirat
implemented in wasi-libc is doing the actual work of calling a WASI import function. Your C file's functions namedpath_create_directory
have a signature that differs from wasi-libc's import of that function. The actual WASIpath_create_directory
does not have a field for permissions or rights. https://github.com/WebAssembly/wasi-libc/blob/be1704a9568e98ae073f074f7271cae68c23d161/libc-bottom-half/sources/__wasilibc_real.c#L387
Last updated: Nov 22 2024 at 16:03 UTC