On Tue, Nov 09, 2021 at 10:26:59AM +0100, Julian Sikorski wrote:
Am 09.11.21 um 09:10 schrieb Steve French:
Yes - here is a trivial reproducer (excuse the ugly sample cut-n-paste)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
char *str = "Text to be added";
int fd, ret, fsyncrc, fsyncr_rc, openrc, closerc, close2rc;
fd = creat("test.txt", S_IWUSR | S_IRUSR);
if (fd < 0) {
perror("creat()");
exit(1);
}
ret = write(fd, str, strlen(str));
if (ret < 0) {
perror("write()");
exit(1);
}
openrc = open("test.txt", O_RDONLY);
if (openrc < 0) {
perror("creat()");
exit(1);
}
fsyncr_rc = fsync(openrc);
if (fsyncr_rc < 0)
perror("fsync()");
fsyncrc = fsync(fd);
closerc = close(fd);
close2rc = close(openrc);
printf("read fsync rc=%d, write fsync rc=%d, close rc=%d, RO close
rc=%d\n", fsyncr_rc, fsyncrc, closerc, close2rc);
}
I can confirm this fails on my machine without nostrictsync:
$ ./test
fsync(): Permission denied
read fsync rc=-1, write fsync rc=0, close rc=0, RO close rc=0
and works with nostrictsync:
$ ./test
read fsync rc=0, write fsync rc=0, close rc=0, RO close rc=0
So is the bug in the Linux kernel?
Yes, it's in the kernel cifsfs module which is forwarding an SMB_FLUSH request
(which the spec says must fail on a non-writable handle) to
a handle opened as non-writable. Steve hopefully will fix :-).