ksmbd: fix timestamp corruption on special values
Subsystems (3)
PATCH 1/1 ksmbd: fix timestamp corruption on special values
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.
---
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/[email protected]/T/#t
fs/smb/server/smb2pdu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
fs/smb/server/smb2pdu.c +12 -7
@@ -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
Signature · 1 line
2.56.0
Hi,
Quoted 4 lines · koraynilay
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.
Quoted 17 lines · Ian Bridges
Hi,
Quoted 4 lines · koraynilay
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.
Quoted 2 lines
Reviewed-by Ian Bridges <[email protected]>Tested-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!