Probable ksmbd bug causing Create Response to show bad timestamps
Subsystems (2)
Hi Namjae,
I think I've found a bug in ksmbd. Using the attached program to create a file, stat it, do a DIO write to it and stat it again:
~/write /xfstest.test/foo 0 4K
sleep 1
stat /xfstest.test/foo
~/write -d /xfstest.test/foo 0 4K
stat /xfstest.test/foo
and having mounted a ksmbd share with cache=strict and actimeo=1, I see mtime and ctime getting corrupted:
File: /xfstest.test/foo
Size: 4096 Blocks: 8 IO Block: 1048576 regular file
Device: 0,65 Inode: 2033391 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:cifs_t:s0
Access: 2025-07-23 22:15:30.136051900 +0100
Modify: 2025-07-23 22:15:30.136051900 +0100
Change: 2025-07-23 22:15:30.136051900 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100
File: /xfstest.test/foo
Size: 4096 Blocks: 8 IO Block: 1048576 regular file
Device: 0,65 Inode: 2033391 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:cifs_t:s0
Access: 2025-07-23 22:15:30.136051900 +0100
Modify: 1970-01-01 01:00:00.000000000 +0100
Change: 1970-01-01 01:00:00.000000000 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100
I've also attached a PCAP file. Frames 16 and 19 show Create Response messages with bad Last Write and Last Change timestamps and I think this is being reflected in the stat output, possibly due to deferred close. Doing another stat a bit later shows the correct timestamps:
Access: 2025-07-23 22:15:32.279094100 +0100
Modify: 2025-07-23 22:15:32.279094100 +0100
Change: 2025-07-23 22:15:32.279094100 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100
I've also added a kernel trace as requested by Steve.
David
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#define OSERROR(X, Y) do { if ((long)(X) == -1) { perror(Y); exit(1); } } while(0)
static unsigned long parseval(char *p)
{
unsigned long val;
char *end;
val = strtoul(p, &end, 0);
switch (*end) {
case 0: break;
case 'k': case 'K': val *= 1024; break;
case 'm': case 'M': val *= 1024 * 1024; break;
case 'p': case 'P': val *= 4096; break;
}
return val;
}static void format(void)
{
printf("Format: write [-dD] <file> <off> <len> [<off> <len>]*\n");
exit(2);
}int main(int argc, char *argv[])
{
const char *filename;
unsigned int flags = O_CREAT|O_WRONLY;
ssize_t wrote;
size_t size;
off_t pos;
void *buf = NULL;
int fd, opt;
while ((opt = getopt(argc, argv, "dD")) && opt != -1) {
switch (opt) {
case 'd':
flags |= O_DIRECT;
break;
case 'D':
flags |= O_DSYNC;
break;
}
}
argc -= optind;
argv += optind;
if (argc < 3)
format();
filename = argv[0];
argc--;
argv++;
if (argc & 1)
format();
fd = open(filename, flags, 0666);
OSERROR(fd, filename);
do {
pos = parseval(argv[0]);
size = parseval(argv[1]);
if (size) {
buf = mmap(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANON, -1, 0);
OSERROR(buf, "mmap");
} else {
buf = "";
}
wrote = pwrite(fd, buf, size, pos);
argv += 2;
argc -= 2;
OSERROR(wrote, filename);
if (wrote < size)
fprintf(stderr, "Wrote %zx not %zx\n", wrote, size);
if (size)
OSERROR(munmap(buf, size), "munmap");
} while (argc >= 2);
OSERROR(close(fd), "close");
return 0;
}Namjae Jeon
maintainerQuoted 3 lines · David Howells
Hi Namjae,
Hi David,
Quoted 3 lines
I think I've found a bug in ksmbd. Using the attached program to create a file, stat it, do a DIO write to it and stat it again:
Okay, I will take a look:)
Thanks for your report!
Quoted 43 lines
~/write /xfstest.test/foo 0 4K
sleep 1
stat /xfstest.test/foo
~/write -d /xfstest.test/foo 0 4K
stat /xfstest.test/fooand having mounted a ksmbd share with cache=strict and actimeo=1, I see mtime and ctime getting corrupted:
File: /xfstest.test/foo
Size: 4096 Blocks: 8 IO Block: 1048576 regular file
Device: 0,65 Inode: 2033391 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:cifs_t:s0
Access: 2025-07-23 22:15:30.136051900 +0100
Modify: 2025-07-23 22:15:30.136051900 +0100
Change: 2025-07-23 22:15:30.136051900 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100
File: /xfstest.test/foo
Size: 4096 Blocks: 8 IO Block: 1048576 regular file
Device: 0,65 Inode: 2033391 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:cifs_t:s0
Access: 2025-07-23 22:15:30.136051900 +0100
Modify: 1970-01-01 01:00:00.000000000 +0100
Change: 1970-01-01 01:00:00.000000000 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100I've also attached a PCAP file. Frames 16 and 19 show Create Response messages with bad Last Write and Last Change timestamps and I think this is being reflected in the stat output, possibly due to deferred close. Doing another stat a bit later shows the correct timestamps:
Access: 2025-07-23 22:15:32.279094100 +0100
Modify: 2025-07-23 22:15:32.279094100 +0100
Change: 2025-07-23 22:15:32.279094100 +0100
Birth: 2025-07-23 22:15:30.136051900 +0100I've also added a kernel trace as requested by Steve.
David