Stream: git-wasmtime

Topic: wasmtime / issue #7671 `fd_filestat_set_times` with direc...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2023 at 21:43):

yagehu added the bug label to Issue #7671.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2023 at 21:43):

yagehu opened issue #7671:

Not sure this is a bug, but I can't find any previous discussion about this particular case.

Calling fd_filestat_set_times with a directory fd, e.g. a preopened directory fd, returne badf. I'm aware there is a conformance test that assert certain fd_* calls should fail with dir fds, but it's not immediately clear to me why this should be the case for fd_filestat_set_times.

I have a simple fix ready to go if folks think it's reasonable to permit this behavior.

Test Case

Adding this snippet to crates/test-programs/src/bin/preview1_fd_filestat_set.rs should cause the test to fail.

    wasi::fd_filestat_set_times(
        dir_fd,
        new_mtim.as_nanos() as u64,
        new_mtim.as_nanos() as u64,
        wasi::FSTFLAGS_MTIM,
    )
    .expect("fd_filestat_set_times on dirfd");

Steps to Reproduce

With the above snippet, cargo test -p wasmtime-wasi.

Expected Results

It should be possible to set times on a directory.

Actual Results

fd_filestat_set_times return badf.

Versions and Environment

Wasmtime version or commit: 4f2d634ca4291a09003eaba26f989cd544c1a289

Operating system: Darwin, Fedora 39

Architecture: amd64

Extra Info

Anything else you'd like to add?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 10 2023 at 08:18):

yagehu edited issue #7671:

Not sure this is a bug, but I can't find any previous discussion about this particular case.

Calling fd_filestat_set_times with a preopened directory fd returns badf. I'm aware there is a conformance test that assert certain fd_* calls should fail with dir fds, but it's not immediately clear to me why this should be the case for fd_filestat_set_times and preopened directories.

Test Case

#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>

int main() {
    struct timespec times[2];

    times[0].tv_nsec = UTIME_NOW;
    times[1].tv_nsec = UTIME_NOW;

    int ret = futimens(3, times);
    if (ret != 0 ) {
        perror("futimens");
        return 1;
    }

    return 0;
}

Steps to Reproduce

Compile the snippet with wasi-sdk and run with Wasmtime, preopen a directory.

Expected Results

It should be possible to set times on a directory.

Actual Results

fd_filestat_set_times return badf.

Versions and Environment

Wasmtime version or commit: 4f2d634ca4291a09003eaba26f989cd544c1a289

Operating system: Darwin, Fedora 39

Architecture: amd64

Extra Info

Anything else you'd like to add?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 10 2023 at 08:36):

yagehu commented on issue #7671:

This is probably a result of including O_PATH when preopening directories: https://github.com/bytecodealliance/cap-std/blob/3663202c6de1bc440764282524a21e14b924925d/cap-primitives/src/rustix/fs/dir_utils.rs#L117

view this post on Zulip Wasmtime GitHub notifications bot (Dec 11 2023 at 15:49):

yagehu edited a comment on issue #7671:

This is probably a result of including O_PATH when preopening directories: https://github.com/bytecodealliance/cap-std/blob/3663202c6de1bc440764282524a21e14b924925d/cap-primitives/src/rustix/fs/dir_utils.rs#L117

EDIT: I just tested. fd_filestat_set_times indeed works if we omit the O_PATH in cap-std.


Last updated: Oct 23 2024 at 20:03 UTC