wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Revert "libc-wasi: Make rights of STDIN/STDOUT/STDERR fixed and overl…

Open yamt opened this issue 6 months ago • 5 comments

…ook their access modes (#3694)"

This reverts commit 67fa155878861699336380980c3601f733f56194.

because it broke certain use cases while it isn't clear what it fixed.

tested with: https://github.com/yamt/garbage/tree/master/wasm/httpd https://github.com/yamt/garbage/tree/master/wasm/tty

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/4447 https://github.com/bytecodealliance/wasm-micro-runtime/issues/3686#issuecomment-2998903186

yamt avatar Jul 03 '25 07:07 yamt

I mostly agree that STDXXX can have variant st_filetype because of those tricks,

But, are you suggesting that removing read/write bits based on the access mode is acceptable according to STDXX?

switch (access_mode) {
    case WASI_LIBC_ACCESS_MODE_READ_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_WRITE;
        break;
    case WASI_LIBC_ACCESS_MODE_WRITE_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_READ;
        break;
}

lum1n0us avatar Jul 03 '25 07:07 lum1n0us

But, are you suggesting that removing read/write bits based on the access mode is acceptable according to STDXX?

yes. i think it's the most straightforward behavior. what's your concern?

yamt avatar Jul 03 '25 08:07 yamt

@lum1n0us can we decide on this? (and/or https://github.com/bytecodealliance/wasm-micro-runtime/pull/4395) or, do you have some more info? (eg. need a research on something)

yamt avatar Sep 10 '25 00:09 yamt

The main concern is that after this modification, the code below will allow STDIN to be unreadable and STDOUT to be unwritable in some scenarios, which I don't think should be permitted.

switch (access_mode) {
    case WASI_LIBC_ACCESS_MODE_READ_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_WRITE;
        break;
    case WASI_LIBC_ACCESS_MODE_WRITE_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_READ;
        break;
}

In my view, the access mode (fcntl() & O_ACCMODE) of STDIN and STDOUT should remain untouchable. Therefore, the rights of STDIN and STDOUT should also be constant.

lum1n0us avatar Sep 12 '25 01:09 lum1n0us

The main concern is that after this modification, the code below will allow STDIN to be unreadable and STDOUT to be unwritable in some scenarios, which I don't think should be permitted.

switch (access_mode) {
    case WASI_LIBC_ACCESS_MODE_READ_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_WRITE;
        break;
    case WASI_LIBC_ACCESS_MODE_WRITE_ONLY:
        *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_READ;
        break;
}

In my view, the access mode (fcntl() & O_ACCMODE) of STDIN and STDOUT should remain untouchable. Therefore, the rights of STDIN and STDOUT should also be constant.

do you mean that wasi should be different from the most of posix platforms in the regard? why?

yamt avatar Sep 16 '25 03:09 yamt