graphene icon indicating copy to clipboard operation
graphene copied to clipboard

[LibOS] sendfile does not work correctly

Open boryspoplawski opened this issue 6 years ago • 5 comments
trafficstars

E.g. doing sendfile from a directory to stdout first writes names of all files in that directory, and then fails with some error. Related: #909

boryspoplawski avatar Aug 26 '19 17:08 boryspoplawski

@boryspoplawski, can you verify that #1000 fixes your test case? Also, can you post your test case?

dimakuv avatar Sep 17 '19 01:09 dimakuv

We just merged #1000 so this issue is fixed. If #1000 doesn't fix all problems with sendfile, please reopen this.

dimakuv avatar Sep 19 '19 00:09 dimakuv

int main(void) {
    int fd = open("/", O_RDONLY);
    if (fd < 0) {
        puts("open fail");
        return 1;
    }

    sendfile(1, fd, NULL, 0x1000);
    printf("\n%m\n");

    return 0;
}

Prints content of '/' directory (file names separated by null bytes) and only then fails with EINVAL Seems that I don't have appropriate permissions to reopen this.

boryspoplawski avatar Sep 24 '19 18:09 boryspoplawski

sendfile() calls handle_copy(). This function is really bad and needs to be re-written.

We found yet one more issue with handle_copy(). It wants to change the offset in the file using seek() FS callback: https://github.com/oscarlab/graphene/blob/5a80ab150ea9b3947a9fd0217ce05fcf3fe436e4/LibOS/shim/src/sys/shim_fs.c#L301

But there is no check of the return value. And seek() can easily fail, e.g. see chroot_seek() callback: https://github.com/oscarlab/graphene/blob/5a80ab150ea9b3947a9fd0217ce05fcf3fe436e4/LibOS/shim/src/fs/chroot/fs.c#L722

There are several places like this in handle_copy(). This breaks some LTP tests.

dimakuv avatar May 10 '21 12:05 dimakuv

We rewrote sendfile implementation but there are quite a few TODOs and corner cases: https://github.com/oscarlab/graphene/pull/2500. So keeping this issue open.

dimakuv avatar Jul 14 '21 14:07 dimakuv