generic: add test for garbled stat output from negative nanoseconds
PATCH v2 1/1 generic: add test for garbled stat output from negative nanoseconds
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].
---
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
tests/generic/812 new file +48 -0
@@ -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
tests/generic/812.out new file +3 -0
@@ -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
Signature · 1 line
2.56.0
Quoted 69 lines · 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 +0000after 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: Thetv_nsecpart is always in the range of 0 <=tv_nsec<
*NSEC_PER_SEC.
* For negative values only thetv_secfield is negative ! */Example patches that fix the problem[1][2].
Signed-off-by koraynilay <[email protected]>---
v2 changes:
- use_fixed_by_fs_commitfor ksmbd and cifs
- add_fixed_by_fs_commitfor ntfs3
- fix cleanup function
- remove useless comment
- wrap more the other comments so they're easier to readThanks.
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.outtests/generic/812 new file +26
-0@@ -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
tests/generic/812 line 36
Quoted 10 lines
tests/generic/812 new file +10
-0+# 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...
Quoted 26 lines
tests/generic/812 new file +12
-0+# 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 0tests/generic/812.out new file +3
-0@@ -0,0 +1,3 @@ +QA output created by 812 +1960-01-01 01:01:01.123456700 +0000 +1960-01-01 01:01:01.123456700 +0000base-commit:
71641219a506ac62bfa231592394265ca812670eSignature · 1 line
2.56.0
Quoted 78 lines · Zorro Lang
Quoted 77 lines · 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 +0000after 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: Thetv_nsecpart is always in the range of 0 <=tv_nsec<
*NSEC_PER_SEC.
* For negative values only thetv_secfield is negative ! */Example patches that fix the problem[1][2].
Signed-off-by koraynilay <[email protected]>---
v2 changes:
- use_fixed_by_fs_commitfor ksmbd and cifs
- add_fixed_by_fs_commitfor ntfs3
- fix cleanup function
- remove useless comment
- wrap more the other comments so they're easier to readThanks.
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.outtests/generic/812 new file +34
-0@@ -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"
Quoted 8 lines
tests/generic/812 line 36
Quoted 2 lines
tests/generic/812 new file +2
-0+} +Haha, I probably didn't explain that clearly. I didn't mean changing the
rmline in_cleanup. What I meant forcefully runningrm -f $TESTFILEright before touch -d below, so that any existing file doesn't interfere with the test, since we don't strictly requireTEST_DIRto 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.
Quoted 4 lines
Don't worry about sending a new version, I'll fix it when I merge. Then...
Reviewed-by Zorro Lang <[email protected]>
Thank you.
Best,
koraynilay
Quoted 26 lines
Quoted 26 lines
tests/generic/812 new file +12
-0+# 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 0tests/generic/812.out new file +3
-0@@ -0,0 +1,3 @@ +QA output created by 812 +1960-01-01 01:01:01.123456700 +0000 +1960-01-01 01:01:01.123456700 +0000base-commit:
71641219a506ac62bfa231592394265ca812670eSignature · 1 line
2.56.0