mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH] ntfs3: fix under/overflow in kernel2nt() due to unset sb->s_time_min/max
Date: Tue, 17 Nov 2026 00:05:26 +0100	[thread overview]
Message-ID: <20261116230526.945330-1-koray.fra@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-16 23:05 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=20261116230526.945330-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 \
    --cc=sashiko-bot@kernel.org \
    /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®