All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: Fix reading of extended tv_sec (bug 23732)
@ 2013-11-07  7:16 David Turner
  2013-11-07 16:03 ` Jan Kara
  0 siblings, 1 reply; 39+ messages in thread
From: David Turner @ 2013-11-07  7:16 UTC (permalink / raw)
  To: linux-ext4; +Cc: linux-kernel, Andreas Dilger, Theodore Ts'o

In ext4, the bottom two bits of {a,c,m}time_extra are used to extend
the {a,c,m}time fields, deferring the year 2038 problem to the year
2446.  The representation (which this patch does not alter) is a bit
hackish, in that the most-significant bit is no longer (alone)
sufficient to indicate the sign.  That's because we're representing an
asymmetric range, with seven times as many positive values as
negative.

When decoding these extended fields, for times whose bottom 32 bits
would represent a negative number, sign extension causes the 64-bit
extended timestamp to be negative as well, which is not what's
intended.  This patch corrects that issue, so that the only negative
{a,c,m}times are those between 1901 and 1970 (as per 32-bit signed
timestamps).

Signed-off-by: David Turner <novalis@novalis.org>
Reported-by: Mark Harris <mh8928@yahoo.com>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=23732
---
 fs/ext4/ext4.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index af815ea..7b73c26 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -722,10 +722,15 @@ static inline __le32 ext4_encode_extra_time(struct timespec *time)
 
 static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
 {
-       if (sizeof(time->tv_sec) > 4)
-	       time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK)
-			       << 32;
-       time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS;
+	if (sizeof(time->tv_sec) > 4) {
+		u64 extra_bits = (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK);
+		if (time->tv_sec > 0 || extra_bits != EXT4_EPOCH_MASK) {
+			time->tv_sec &= 0xFFFFFFFF;
+			time->tv_sec |= extra_bits << 32;
+		}
+		time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >>
+			EXT4_EPOCH_BITS;
+	}
 }
 
 #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode)			       \
-- 
1.8.1.2




^ permalink raw reply related	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2014-02-14 22:11 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-07  7:16 [PATCH] ext4: Fix reading of extended tv_sec (bug 23732) David Turner
2013-11-07 16:03 ` Jan Kara
2013-11-07 22:54   ` [PATCH v2] " David Turner
2013-11-07 23:14     ` Jan Kara
2013-11-07 23:26       ` [PATCH v3] " David Turner
2013-11-08  5:17         ` Theodore Ts'o
2013-11-08 21:37         ` Andreas Dilger
2013-11-09  7:19           ` [PATCH] ext4: explain encoding of 34-bit a,c,mtime values David Turner
2013-11-09  7:19             ` David Turner
2013-11-09 23:51             ` Mark Harris
2013-11-09 23:51               ` Mark Harris
2013-11-10  7:56               ` David Turner
2013-11-12  0:30                 ` Theodore Ts'o
2013-11-12 21:35                   ` Andreas Dilger
2013-11-13  7:00                     ` [PATCH v4 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2013-11-13  8:19                       ` Darrick J. Wong
2013-11-13  7:00                     ` [PATCH v4 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2013-11-13  7:56                       ` Andreas Dilger
2013-11-14  8:38                         ` [PATCH v5 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2013-11-14  8:44                         ` [PATCH v5 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2013-11-14 10:15                           ` Mark Harris
2013-11-14 21:06                             ` [PATCH v6] " David Turner
2013-11-29 21:54                               ` David Turner
2013-11-29 22:11                                 ` Andreas Dilger
2013-12-07 20:02                                   ` [PATCH v7 1/2] " David Turner
2013-12-07 22:33                                     ` Andreas Dilger
2013-12-08  0:53                                     ` Theodore Ts'o
2013-12-08  2:58                                       ` David Turner
2013-12-08  3:21                                         ` Theodore Ts'o
2013-12-07 20:02                                   ` [PATCH v7 2/2] debugfs: Decode {a,c,cr,m}time_extra fields in stat David Turner
2013-11-12 23:03                   ` [PATCH] ext4: explain encoding of 34-bit a,c,mtime values Darrick J. Wong
2013-11-13  2:36                     ` David Turner
2014-01-22  6:22                   ` Darrick J. Wong
2014-02-11  5:12                     ` David Turner
2014-02-11  7:07                       ` Andreas Dilger
2014-02-14  3:47                         ` [PATCH v8 1/2] ext4: Fix handling of extended tv_sec (bug 23732) David Turner
2014-02-14  3:47                         ` [PATCH v8 2/2] e2fsck: Correct ext4 dates generated by old kernels David Turner
2014-02-14  5:40                           ` Andreas Dilger
2014-02-14 22:11                             ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.