All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
@ 2026-11-21 16:20 koraynilay
  0 siblings, 0 replies; only message in thread
From: koraynilay @ 2026-11-21 16:20 UTC (permalink / raw)
  To: Zorro Lang; +Cc: fstests, koraynilay

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-21 16:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 16:20 [PATCH v2] generic: add test for garbled stat output from negative nanoseconds koraynilay

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.