* [PATCH] ntfs3: fix under/overflow in kernel2nt() due to unset sb->s_time_min/max
@ 2026-11-16 23:05 koraynilay
0 siblings, 0 replies; only message in thread
From: koraynilay @ 2026-11-16 23:05 UTC (permalink / raw)
To: Konstantin Komarov, ntfs3; +Cc: linux-kernel, koraynilay, Sashiko
Because ntfs_fill_super() initializes sb->s_time_gran to NTFS_TIME_GRAN
(100 ns) without setting sb->s_time_min and sb->s_time_max, the superblock
bounds remain at their alloc_super() defaults of TIME64_MIN and TIME64_MAX.
When a user updates timestamps through notify_change(),
timestamp_truncate() does not clamp ts->tv_sec to the range representable
by 64-bit 100-nanosecond NTFS intervals.
When ni_write_inode() subsequently converts the unclamped inode
timestamps via kernel2nt(), multiplying by _100ns2seconds overflows or
underflows and wraps around, writing corrupted timestamps to the on-disk
MFT standard information and directory filename attributes and causing a
mismatch between in-memory and on-disk timestamps across inode eviction.
Fix this by setting sb->s_time_min and sb->s_time_max to the smallest
possible and largest possible values respectively using nt2kernel() like
other filesystems (e.g. CIFS) do.
Reproducer, with /dev/loop0 formatted as NTFS and mounted at /mnt:
mount -t ntfs3 /dev/loop0 /mnt
touch -d "@1000000000000" /mnt/test.txt
stat -c 'in memory: %Y (%y)' /mnt/test.txt
# remount to evict caches
umount /mnt
mount -t ntfs3 /dev/loop0 /mnt
stat -c 'from disk: %Y (%y)' /mnt/test.txt
output before fix:
in memory: 1000000000000 (33658-09-27 01:46:40.000000000 +0000)
from disk: -844674407371 (-24797-05-02 20:10:29.044838400 +0000)
output after fix:
in memory: 910692730085 (30828-09-14 02:48:05.000000000 +0000)
from disk: 910692730085 (30828-09-14 02:48:05.000000000 +0000)
The reproducer for the underflow is the same, but with "@-1000000000000"
instead of "@1000000000000" in the touch command:
output before fix:
in memory: -1000000000000 (-29719-04-05 22:13:20.000000000 +0000)
from disk: 844674407370 (28736-09-01 03:49:30.955161600 +0000)
output after fix:
in memory: -11644473600 (1601-01-01 00:00:00.000000000 +0000)
from disk: -11644473600 (1601-01-01 00:00:00.000000000 +0000)
[ First paragraph of this commit message is by Sashiko, see Closes: tag ]
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-11bcb274-4eb7-4a14-af1a-ed7ab6b0b769
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/ntfs3/super.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 29aabdc8a801..915722abef5d 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -1325,6 +1325,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
struct ntfs_mount_options *options = NULL;
struct inode *inode;
struct ntfs_inode *ni;
+ struct timespec64 ts;
size_t i, tt, bad_len, bad_frags;
CLST vcn, lcn, len;
struct ATTRIB *attr;
@@ -1361,6 +1362,10 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_op = &ntfs_sops;
sb->s_export_op = &ntfs_export_ops;
sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec
+ nt2kernel(0, &ts);
+ sb->s_time_min = ts.tv_sec;
+ nt2kernel(cpu_to_le64(S64_MAX), &ts);
+ sb->s_time_max = ts.tv_sec;
sb->s_xattr = ntfs_xattr_handlers;
set_default_d_op(sb, options->nocase ? &ntfs_dentry_ops : NULL);
base-commit: 0c895b1f6ab37a7c72a437818f307ef6e629051c
prerequisite-patch-id: 26605e50ebd4bbfcfd30aca746348b6f79bc83e0
--
2.56.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 23:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 23:05 [PATCH] ntfs3: fix under/overflow in kernel2nt() due to unset sb->s_time_min/max koraynilay
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®