mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: koraynilay <koray.fra@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Tom Talpey <tom@talpey.com>,
	ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	Ronnie Sahlberg <lsahlber@redhat.com>,
	linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
	koraynilay <koray.fra@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] ksmbd: fix timestamp corruption on special values
Date: Wed, 11 Nov 2026 23:25:34 +0100	[thread overview]
Message-ID: <20261111222534.839117-1-koray.fra@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-11 22:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111222534.839117-1-koray.fra@gmail.com \
    --to=koray.fra@gmail.com \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=senozhatsky@chromium.org \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®