Skip to contentSkip to conversation

squashfs: fix mtime underflow on 64 bit system

PATCH In review zhengbin 1 participant 3 messages Jan 17, 2019 – Jan 23, 2019 SquashFS file system

lore
Share & tools
lore

zhengbin

author
#0 lore raw

PATCH 1/1 squashfs: fix mtime underflow on 64 bit system

If we change the file mtime to 1969, mksquashfs and mount, the atime/mtime of this file will be underflow. The reason is treating timestamps with the high bit set as positive times(before 1970), which should be set as negative times just like on 32 bit system. After this, the poissble range of timestamps will be 1901-2038(prev is 1970-2106) on 64 bit system.

---
 fs/squashfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/squashfs/inode.c +1 -1
index e9793b1e49a5..03a6ef77a2d2 100644
@@ -72,7 +72,7 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode,
 	i_uid_write(inode, i_uid);
 	i_gid_write(inode, i_gid);
 	inode->i_ino = le32_to_cpu(sqsh_ino->inode_number);
-	inode->i_mtime.tv_sec = le32_to_cpu(sqsh_ino->mtime);
+	inode->i_mtime.tv_sec = (signed int)le32_to_cpu(sqsh_ino->mtime);
 	inode->i_atime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_ctime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_mode = le16_to_cpu(sqsh_ino->mode);

--
2.16.2.dirty

#1 lore raw

hi Phillip, when you have time, help to confirm it?

Looking forward to your reply.

Quoted 32 lines · zhengbin

If we change the file mtime to 1969, mksquashfs and mount, the atime/mtime of this file will be underflow. The reason is treating timestamps with the high bit set as positive times(before 1970), which should be set as negative times just like on 32 bit system. After this, the poissble range of timestamps will be 1901-2038(prev is 1970-2106) on 64 bit system.

---
 fs/squashfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/squashfs/inode.c +1 -2
index e9793b1e49a5..03a6ef77a2d2 100644
@@ -72,7 +72,7 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode,
 	i_uid_write(inode, i_uid);
 	i_gid_write(inode, i_gid);
 	inode->i_ino = le32_to_cpu(sqsh_ino->inode_number);
-	inode->i_mtime.tv_sec = le32_to_cpu(sqsh_ino->mtime);
+	inode->i_mtime.tv_sec = (signed int)le32_to_cpu(sqsh_ino->mtime);
 	inode->i_atime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_ctime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_mode = le16_to_cpu(sqsh_ino->mode);
--

2.16.2.dirty

.

#2 lore raw
In reply to zhengbin

Ping?

Quoted 32 lines · zhengbin

If we change the file mtime to 1969, mksquashfs and mount, the atime/mtime of this file will be underflow. The reason is treating timestamps with the high bit set as positive times(before 1970), which should be set as negative times just like on 32 bit system. After this, the poissble range of timestamps will be 1901-2038(prev is 1970-2106) on 64 bit system.

---
 fs/squashfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/squashfs/inode.c +1 -2
index e9793b1e49a5..03a6ef77a2d2 100644
@@ -72,7 +72,7 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode,
 	i_uid_write(inode, i_uid);
 	i_gid_write(inode, i_gid);
 	inode->i_ino = le32_to_cpu(sqsh_ino->inode_number);
-	inode->i_mtime.tv_sec = le32_to_cpu(sqsh_ino->mtime);
+	inode->i_mtime.tv_sec = (signed int)le32_to_cpu(sqsh_ino->mtime);
 	inode->i_atime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_ctime.tv_sec = inode->i_mtime.tv_sec;
 	inode->i_mode = le16_to_cpu(sqsh_ino->mode);
--

2.16.2.dirty

.