graphene
graphene copied to clipboard
[LibOS] sendfile does not work correctly
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, can you verify that #1000 fixes your test case? Also, can you post your test case?
We just merged #1000 so this issue is fixed. If #1000 doesn't fix all problems with sendfile, please reopen this.
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.
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.
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.