Skip to content
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

Operation not permitted ? #4265

Open
orangeC23 opened this issue Oct 21, 2023 · 1 comment
Open

Operation not permitted ? #4265

orangeC23 opened this issue Oct 21, 2023 · 1 comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs 🕵️ needs investigation The issue/PR needs further investigation priority-medium Medium priority issue
Milestone

Comments

@orangeC23
Copy link

orangeC23 commented Oct 21, 2023

Steps to reproduce

(1)The c file is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/stat.h>

int main() {
    const char* file_name = "Data/hello.txt";
    int open_style= O_RDONLY;
    int fd = get_fd(file_name, open_style);
    fd_preadPGADzrDXHK(fd);
    snapshot(fd);
    return 0;
}

int fd_preadPGADzrDXHK (int fd){
    int buffer_size = 0;
    int start_value = 0;
    off_t offset_value = 17;
    return fd_pread(fd, buffer_size, start_value, offset_value);
}

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 fd_pread(int fd, int buffer_size, int start_value, off_t offset_value) {
    printf("Enter fd_pread\n");
    
    char buffer1[buffer_size];

    struct iovec iov[1];
    iov[0].iov_base = buffer1;
    iov[0].iov_len = sizeof(buffer1);

    off_t new_offset = offset_value; 
    
    if (lseek(fd, new_offset, SEEK_SET) == -1) {
        perror("Error setting new offset");
        close(fd);
        return 1;
    }

    off_t current_offset = lseek(fd, 0, SEEK_CUR);
    if (current_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld\\n", (long long)current_offset);

    ssize_t bytes_read = preadv(fd, iov, 1, start_value);
    if (bytes_read == -1) {
        perror("Error reading the file");
        close(fd);
        return 1;
    }

    printf("Read %zd bytes:\\n", bytes_read);
    printf("Buffer 1: %.*s\\n", (int)iov[0].iov_len, (char*)iov[0].iov_base);

    printf("Leave fd_pread\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);
    printf("File Permissions: %o \n", file_info.st_mode & ~S_IFMT); 
    printf("File Owner UID: %d \n", file_info.st_uid);
    printf("File Group GID: %d \n", file_info.st_gid); 
    
    off_t cur_offset = lseek(myfd, 0, SEEK_CUR);
    if (cur_offset == -1) {
        perror("Error getting current offset");
    }
    printf("Current offset: %lld \n", (long long)cur_offset);

    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
}

(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 test.c -o test.wasm
(3)exeute open.wasm
wasmer run --dir=./Data test.wasm
The permission of Data/hello.txt is 0500 or 0400, user1 create the Data/hello.txt file and user1 execute the Wasm file.

Expected behavior

wasmtime, wazero, wamr print:

Enter fd_pread
Current offset: 17\nRead 0 bytes:\nBuffer 1: \nLeave fd_pread
Enter snapshot
File Size: 30 bytes 
File Permissions: 0 
File Owner UID: 0 
File Group GID: 0 
Current offset: 17 
Leave snapshot

And ubuntu(compile the cfile directly into native code through gcc) prints:

Enter fd_pread
Current offset: 17\nRead 0 bytes:\nBuffer 1: \nLeave fd_pread
Enter snapshot
File Size: 30 bytes 
File Permissions: 500 
File Owner UID: 1002 
File Group GID: 1002 
Current offset: 17 
Leave snapshot

Actual behavior

wasmer prints:

Failed to open the file: Operation not permitted
Enter fd_pread
Error setting new offset: Permission denied
Error getting file attributes: Bad file descriptor

version

wasmer 4.2.2

ubuntu 20.04

@Arshia001
Copy link
Member

Probably related to #4257, #4259 and #4270.

@Arshia001 Arshia001 added bug Something isn't working 🕵️ needs investigation The issue/PR needs further investigation 📦 lib-vfs About wasmer-vfs priority-medium Medium priority issue labels Oct 24, 2023
@Arshia001 Arshia001 added this to the v4.3 milestone Oct 24, 2023
This was referenced Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs 🕵️ needs investigation The issue/PR needs further investigation priority-medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

2 participants