]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fs/ntfs3: Support timestamps prior to epoch
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Mon, 1 Sep 2025 08:48:48 +0000 (11:48 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:42 +0000 (13:09 +0100)
[ Upstream commit 5180138604323895b5c291eca6aa7c20be494ade ]

Before it used an unsigned 64-bit type, which prevented proper handling
of timestamps earlier than 1970-01-01. Switch to a signed 64-bit type to
support pre-epoch timestamps. The issue was caught by xfstests.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ntfs3/ntfs_fs.h

index 69d1442eea623a55effa4a58adb2dcce046ff8fb..d93cba03a65aae607e14ebb2c798a3caf8835c1e 100644 (file)
@@ -975,11 +975,12 @@ static inline __le64 kernel2nt(const struct timespec64 *ts)
  */
 static inline void nt2kernel(const __le64 tm, struct timespec64 *ts)
 {
-       u64 t = le64_to_cpu(tm) - _100ns2seconds * SecondsToStartOf1970;
+       s32 t32;
+       /* use signed 64 bit to support timestamps prior to epoch. xfstest 258. */
+       s64 t = le64_to_cpu(tm) - _100ns2seconds * SecondsToStartOf1970;
 
-       // WARNING: do_div changes its first argument(!)
-       ts->tv_nsec = do_div(t, _100ns2seconds) * 100;
-       ts->tv_sec = t;
+       ts->tv_sec = div_s64_rem(t, _100ns2seconds, &t32);
+       ts->tv_nsec = t32 * 100;
 }
 
 static inline struct ntfs_sb_info *ntfs_sb(struct super_block *sb)