FS/XFS testing framework
 help / color / mirror / Atom feed
From: Zorro Lang <zlang@kernel.org>
To: koraynilay <koray.fra@gmail.com>
Cc: fstests@vger.kernel.org
Subject: Re: [PATCH v2] generic: add test for garbled stat output from negative nanoseconds
Date: Sun, 22 Nov 2026 01:31:58 +0800	[thread overview]
Message-ID: <awHTU6F4imBlRW7p@zlang-mailbox> (raw)
In-Reply-To: <20261121162003.234307-1-koray.fra@gmail.com>

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
> 

  reply	other threads:[~2026-11-21 17:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-21 17:35   ` koraynilay

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=awHTU6F4imBlRW7p@zlang-mailbox \
    --to=zlang@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=koray.fra@gmail.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