* [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
@ 2026-11-21 16:20 koraynilay
2026-11-21 17:31 ` Zorro Lang
0 siblings, 1 reply; 3+ messages 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] 3+ messages in thread* Re: [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
2026-11-21 16:20 [PATCH v2] generic: add test for garbled stat output from negative nanoseconds koraynilay
@ 2026-11-21 17:31 ` Zorro Lang
2026-11-21 17:35 ` koraynilay
0 siblings, 1 reply; 3+ messages in thread
From: Zorro Lang @ 2026-11-21 17:31 UTC (permalink / raw)
To: koraynilay; +Cc: fstests
On Sat, Nov 21, 2026 at 05:20:03PM +0100, koraynilay wrote:
> 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"
> +}
> +
Haha, I probably didn't explain that clearly. I didn't mean changing the `rm`
line in _cleanup. What I meant forcefully running `rm -f $TESTFILE` right
before touch -d below, so that any existing file doesn't interfere with the
test, since we don't strictly require TEST_DIR to be completely cleaned
up after every test case run.
Don't worry about sending a new version, I'll fix it when I merge. Then...
Reviewed-by: Zorro Lang <zlang@kernel.org>
> +# 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 [flat|nested] 3+ messages in thread* Re: [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
2026-11-21 17:31 ` Zorro Lang
@ 2026-11-21 17:35 ` koraynilay
0 siblings, 0 replies; 3+ messages in thread
From: koraynilay @ 2026-11-21 17:35 UTC (permalink / raw)
To: koraynilay, fstests
[-- Attachment #1: Type: text/plain, Size: 4163 bytes --]
On Sat Nov 21, 2026 at 6:31 PM CET, Zorro Lang wrote:
> On Sat, Nov 21, 2026 at 05:20:03PM +0100, koraynilay wrote:
>> 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"
>> +}
>> +
>
> Haha, I probably didn't explain that clearly. I didn't mean changing the `rm`
> line in _cleanup. What I meant forcefully running `rm -f $TESTFILE` right
> before touch -d below, so that any existing file doesn't interfere with the
> test, since we don't strictly require TEST_DIR to be completely cleaned
> up after every test case run.
Oh, yeah that makes more sense considering the template and other tests
all keep the rm -f $tmp.* ahah.
> Don't worry about sending a new version, I'll fix it when I merge. Then...
>
> Reviewed-by: Zorro Lang <zlang@kernel.org>
>
Thank you.
Best,
koraynilay
>> +# 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
>>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 17:36 UTC | newest]
Thread overview: 3+ messages (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
2026-11-21 17:31 ` Zorro Lang
2026-11-21 17:35 ` koraynilay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox