From: koraynilay <koray.fra@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
ntfs3@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, koraynilay <koray.fra@gmail.com>
Subject: [PATCH] ntfs3: fix negative timestamps corrupting stat output
Date: Mon, 16 Nov 2026 22:20:06 +0100 [thread overview]
Message-ID: <20261116212006.837097-1-koray.fra@gmail.com> (raw)
When reading a timestamp before epoch with sub-second precision, ntfs3
converts it from on-disk NT format to Unix format without normalizing
it, leading to the nanoseconds field being used as a negative number.
This leads to a garbled stat command output and 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 !
*/
Reproducer, with /dev/loop0 formatted as NTFS and mounted at /mnt:
mount -t ntfs3 /dev/loop0 /mnt
touch -d "1969-07-20 20:17:40.123456789" /mnt/test.txt
stat -c %y /mnt/test.txt
# remount to evict caches
umount /mnt
mount -t ntfs3 /dev/loop0 /mnt
stat -c %y /mnt/test.txt
which prints (stat output is garbled because of negative value):
1969-07-20 20:17:40.123456700 +0000 (from cache)
1969-07-20 20:17:41.()*+,--00 +0000 (from disk, after remount)
Fix this by using set_normalized_timespec64() in nt2kernel().
Fixes: 518013860432 ("fs/ntfs3: Support timestamps prior to epoch")
Cc: stable@vger.kernel.org
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Small bug found by sashiko[1] while implementing ptime[2].
Thanks.
[1]: https://sashiko.dev/#/message/20261115180343.576773-4-koray.fra%40gmail.com
[2]: https://lore.kernel.org/all/20261115180343.576773-1-koray.fra@gmail.com/T/#u
fs/ntfs3/ntfs_fs.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index f400cf94d05b..1f3e5d201767 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -1083,8 +1083,8 @@ static inline void nt2kernel(const __le64 tm, struct timespec64 *ts)
/* use signed 64 bit to support timestamps prior to epoch. xfstest 258. */
s64 t = le64_to_cpu(tm) - _100ns2seconds * SecondsToStartOf1970;
- ts->tv_sec = div_s64_rem(t, _100ns2seconds, &t32);
- ts->tv_nsec = t32 * 100;
+ set_normalized_timespec64(ts, div_s64_rem(t, _100ns2seconds, &t32),
+ (s64)t32 * 100);
}
static inline struct ntfs_sb_info *ntfs_sb(struct super_block *sb)
base-commit: 0c895b1f6ab37a7c72a437818f307ef6e629051c
--
2.56.0
reply other threads:[~2026-11-16 21: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=20261116212006.837097-1-koray.fra@gmail.com \
--to=koray.fra@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/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
all inboxes | Powered by JetHome®