From: koraynilay <koray.fra@gmail.com>
To: Zorro Lang <zlang@kernel.org>
Cc: fstests@vger.kernel.org, koraynilay <koray.fra@gmail.com>
Subject: [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
Date: Sat, 21 Nov 2026 17:20:03 +0100 [thread overview]
Message-ID: <20261121162003.234307-1-koray.fra@gmail.com> (raw)
Some filesystems don't use set_normalized_timespec64() to handle their
timestamps format conversion, leading to a garbled stat command output
for timestamps.
For example:
from cache: 1960-01-01 01:01:01.123456789 +0000
after remount: 1960-01-01 01:01:02.()*+,--00 +0000
This bug also violates a struct timespec64 invariant, as documented in
the set_normalized_timespec64() kernel-doc:
[...]
* Note: The tv_nsec part is always in the range of 0 <= tv_nsec <
* NSEC_PER_SEC.
* For negative values only the tv_sec field is negative !
*/
Example patches that fix the problem[1][2].
Link: https://lore.kernel.org/linux-cifs/20261112111637.184045-1-koray.fra@gmail.com/ [1]
Link: https://lore.kernel.org/linux-cifs/20261112111637.184045-2-koray.fra@gmail.com/ [2]
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
v2 changes:
- use _fixed_by_fs_commit for ksmbd and cifs
- add _fixed_by_fs_commit for ntfs3
- fix cleanup function
- remove useless comment
- wrap more the other comments so they're easier to read
Thanks.
tests/generic/812 | 48 +++++++++++++++++++++++++++++++++++++++++++
tests/generic/812.out | 3 +++
2 files changed, 51 insertions(+)
create mode 100755 tests/generic/812
create mode 100644 tests/generic/812.out
diff --git a/tests/generic/812 b/tests/generic/812
new file mode 100755
index 00000000..eb76f2e5
--- /dev/null
+++ b/tests/generic/812
@@ -0,0 +1,48 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 koraynilay. All Rights Reserved.
+#
+# FS QA Test No. 812
+#
+# Based on generic/258, but tests timestamps prior to epoch with sub-second
+# precision.
+#
+# ksmbd, cifs, ntfs3 and other filesystem drivers violate timespec64
+# non-negative nanoseconds constraint, garbling output of stat.
+#
+. ./common/preamble
+_begin_fstest auto quick bigtime
+
+_fixed_by_fs_commit cifs 6a75ce0866bb \
+ "smb: client: fix negative timestamps being read from smb"
+_fixed_by_fs_commit cifs f2f961e0983c \
+ "ksmbd: fix negative timestamps being saved to disk"
+_fixed_by_fs_commit ntfs3 xxxxxxxxxxxx \
+ "ntfs3: fix negative timestamps corrupting stat output"
+
+_require_test
+_require_negative_timestamps
+
+TESTFILE=$TEST_DIR/timestamp-test.txt
+# we use 123456700 instead of 123456789 because some
+# filesystems support only 100ns precision
+DATE="1960-01-01 01:01:01.123456700 UTC"
+
+_cleanup()
+{
+ cd /
+ rm -f "$TESTFILE"
+}
+
+# create a file with a timestamp prior to the
+# epoch with nanosecond precision
+touch -d "$DATE" "$TESTFILE"
+
+TZ=UTC stat -c "%y" "$TESTFILE"
+
+# unmount, remount, and check the timestamp
+_test_cycle_mount
+
+TZ=UTC stat -c "%y" "$TESTFILE"
+
+_exit 0
diff --git a/tests/generic/812.out b/tests/generic/812.out
new file mode 100644
index 00000000..f0267fbb
--- /dev/null
+++ b/tests/generic/812.out
@@ -0,0 +1,3 @@
+QA output created by 812
+1960-01-01 01:01:01.123456700 +0000
+1960-01-01 01:01:01.123456700 +0000
base-commit: 71641219a506ac62bfa231592394265ca812670e
--
2.56.0
reply other threads:[~2026-11-21 16:20 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=20261121162003.234307-1-koray.fra@gmail.com \
--to=koray.fra@gmail.com \
--cc=fstests@vger.kernel.org \
--cc=zlang@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.