* [PATCH] ksmbd: fix timestamp corruption on special values
@ 2026-11-11 22:25 koraynilay
2026-11-12 3:11 ` Ian Bridges
0 siblings, 1 reply; 2+ messages in thread
From: koraynilay @ 2026-11-11 22:25 UTC (permalink / raw)
To: Namjae Jeon
Cc: Sergey Senozhatsky, Tom Talpey, ChenXiaoSong, Hyunchul Lee,
Ronnie Sahlberg, linux-cifs, linux-kernel, koraynilay, stable
When a timestamp is being sent with "-1" or "-2" as its value because it
should be ignored, as specified in MS-FSCC 2.4.7 FileBasicInformation,
ksmbd would clobber it in both the xattr and on-disk value by setting it
to -1.
simple reproducer:
echo test > file.txt
smbclient //127.0.0.1/test -U user%pass -c "put file.txt repro.txt"
smbclient //127.0.0.1/test -U user%pass -c "allinfo repro.txt"
smbclient //127.0.0.1/test -U user%pass -c "setmode repro.txt +h"
stat repro.txt # the actual file on disk behind smb
smbclient //127.0.0.1/test -U user%pass -c "allinfo repro.txt"
which would show, respectively:
altname: REPRO~MQ.TXT
create_time: Wed Nov 11 21:23:16 2026 UTC
access_time: Wed Nov 11 21:23:16 2026 UTC
write_time: Wed Nov 11 21:23:16 2026 UTC
change_time: Wed Nov 11 21:23:16 2026 UTC
attributes: A (20)
File: /tmp/repro.txt
[...]
Access: 1601-01-01 00:00:00.000000000 +0000
Modify: 2026-11-11 21:58:10.145349236 +0000
Change: 2026-11-11 21:58:10.206350216 +0000
Birth: 2026-11-11 21:58:10.144349220 +0000
altname: REPRO~MQ.TXT
create_time: Wed Dec 31 23:59:59 1969 UTC
access_time: Mon Jan 1 00:00:04 1601 UTC
write_time: Wed Nov 11 21:23:16 2026 UTC
change_time: Wed Nov 11 21:23:16 2026 UTC
attributes: HA (22)
This patch also makes the smb2.timestamps.freeze-thaw test from
smbtorture pass.
Cc: stable@vger.kernel.org
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Link: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/16023025-8a78-492f-8b96-c873b042ac50
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.3
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Another small-ish fix I found while implementing ptime[1].
(And probably won't be the last one :c)
Thanks.
[1]: https://lore.kernel.org/all/20261101015551.786044-1-koray.fra@gmail.com/T/#t
fs/smb/server/smb2pdu.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 92843d2944e4..5b046f10e2ce 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -8867,6 +8867,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
const struct mnt_idmap *idmap;
__le32 attrs_mask = FILE_ATTRIBUTE_DIRECTORY_LE |
FILE_ATTRIBUTE_COMPRESSED_LE;
+ s64 crtime, time;
int rc = 0;
if (!(fp->daccess & FILE_WRITE_ATTRIBUTES_LE))
@@ -8882,21 +8883,25 @@ static int set_file_basic_info(struct ksmbd_file *fp,
(file_info->Attributes & FILE_ATTRIBUTE_TEMPORARY_LE))
return -EINVAL;
- if (file_info->CreationTime)
- fp->create_time = le64_to_cpu(file_info->CreationTime);
+ crtime = (s64)le64_to_cpu(file_info->CreationTime);
+ if (crtime > 0)
+ fp->create_time = crtime;
- if (file_info->LastAccessTime) {
+ time = (s64)le64_to_cpu(file_info->LastAccessTime);
+ if (time > 0) {
attrs.ia_atime = ksmbd_NTtimeToUnix(file_info->LastAccessTime);
attrs.ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
}
- if (file_info->ChangeTime) {
- fp->change_time = le64_to_cpu(file_info->ChangeTime);
+ time = (s64)le64_to_cpu(file_info->ChangeTime);
+ if (time > 0) {
+ fp->change_time = time;
inode_set_ctime_to_ts(inode,
ksmbd_NTtimeToUnix(file_info->ChangeTime));
}
- if (file_info->LastWriteTime) {
+ time = (s64)le64_to_cpu(file_info->LastWriteTime);
+ if (time > 0) {
attrs.ia_mtime = ksmbd_NTtimeToUnix(file_info->LastWriteTime);
attrs.ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME);
}
@@ -8915,7 +8920,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
}
if (test_share_config_flag(share, KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) &&
- (file_info->CreationTime || file_info->Attributes)) {
+ (crtime > 0 || file_info->Attributes)) {
struct xattr_dos_attrib da = {0};
da.version = 4;
base-commit: ffde0bdfc69a0f01a081d9c1a213e63d5719e625
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ksmbd: fix timestamp corruption on special values
2026-11-11 22:25 [PATCH] ksmbd: fix timestamp corruption on special values koraynilay
@ 2026-11-12 3:11 ` Ian Bridges
0 siblings, 0 replies; 2+ messages in thread
From: Ian Bridges @ 2026-11-12 3:11 UTC (permalink / raw)
To: koray.fra
Cc: linkinjeon, senozhatsky, tom, chenxiaosong, hyc.lee, linux-cifs,
linux-kernel, stable, Ian Bridges
Hi,
On Wed, Nov 11, 2026 at 11:25:34PM +0100, koraynilay wrote:
> When a timestamp is being sent with "-1" or "-2" as its value because it
> should be ignored, as specified in MS-FSCC 2.4.7 FileBasicInformation,
> ksmbd would clobber it in both the xattr and on-disk value by setting it
> to -1.
I tested this with the ksmbd code from ksmbd-for-next. Before the
patch, setting any of the four times to -1 or -2 stored that value.
The access and write times on disk moved to 1901, and the creation
time in the DOS attribute xattr was overwritten. With the patch, -1
and -2 leave every time unchanged, and valid times are still set as
before. smbtorture confirms the result in the commit message, the rest
of its results are unchanged, and KASAN reports nothing.
Reviewed-by: Ian Bridges <icb@fastmail.org>
Tested-by: Ian Bridges <icb@fastmail.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-12 3:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 22:25 [PATCH] ksmbd: fix timestamp corruption on special values koraynilay
2026-11-12 3:11 ` Ian Bridges
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®