Skip to content

Commit cfb82e1

Browse files
committed
Merge tag 'y2038-vfs' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground
Pull y2038 vfs updates from Arnd Bergmann: "Add inode timestamp clamping. This series from Deepa Dinamani adds a per-superblock minimum/maximum timestamp limit for a file system, and clamps timestamps as they are written, to avoid random behavior from integer overflow as well as having different time stamps on disk vs in memory. At mount time, a warning is now printed for any file system that can represent current timestamps but not future timestamps more than 30 years into the future, similar to the arbitrary 30 year limit that was added to settimeofday(). This was picked as a compromise to warn users to migrate to other file systems (e.g. ext4 instead of ext3) when they need the file system to survive beyond 2038 (or similar limits in other file systems), but not get in the way of normal usage" * tag 'y2038-vfs' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground: ext4: Reduce ext4 timestamp warnings isofs: Initialize filesystem timestamp ranges pstore: fs superblock limits fs: omfs: Initialize filesystem timestamp ranges fs: hpfs: Initialize filesystem timestamp ranges fs: ceph: Initialize filesystem timestamp ranges fs: sysv: Initialize filesystem timestamp ranges fs: affs: Initialize filesystem timestamp ranges fs: fat: Initialize filesystem timestamp ranges fs: cifs: Initialize filesystem timestamp ranges fs: nfs: Initialize filesystem timestamp ranges ext4: Initialize timestamps limits 9p: Fill min and max timestamps in sb fs: Fill in max and min timestamps in superblock utimes: Clamp the timestamps before update mount: Add mount warning for impending timestamp expiry timestamp_truncate: Replace users of timespec64_trunc vfs: Add timestamp_truncate() api vfs: Add file timestamp range support
2 parents b41dae0 + cba465b commit cfb82e1

47 files changed

Lines changed: 294 additions & 72 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎fs/9p/vfs_super.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
6969
if (v9fs_proto_dotl(v9ses)) {
7070
sb->s_op = &v9fs_super_ops_dotl;
7171
sb->s_xattr = v9fs_xattr_handlers;
72-
} else
72+
} else {
7373
sb->s_op = &v9fs_super_ops;
74+
sb->s_time_max = U32_MAX;
75+
}
76+
77+
sb->s_time_min = 0;
7478

7579
ret = super_setup_bdi(sb);
7680
if (ret)

‎fs/affs/amigaffs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ affs_secs_to_datestamp(time64_t secs, struct affs_date *ds)
375375
u32 minute;
376376
s32 rem;
377377

378-
secs -= sys_tz.tz_minuteswest * 60 + ((8 * 365 + 2) * 24 * 60 * 60);
378+
secs -= sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
379379
if (secs < 0)
380380
secs = 0;
381381
days = div_s64_rem(secs, 86400, &rem);

‎fs/affs/amigaffs.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#define AFFS_ROOT_BMAPS 25
3434

35+
/* Seconds since Amiga epoch of 1978/01/01 to UNIX */
36+
#define AFFS_EPOCH_DELTA ((8 * 365 + 2) * 86400LL)
37+
3538
struct affs_date {
3639
__be32 days;
3740
__be32 mins;

‎fs/affs/inode.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ struct inode *affs_iget(struct super_block *sb, unsigned long ino)
150150
}
151151

152152
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec
153-
= (be32_to_cpu(tail->change.days) * (24 * 60 * 60) +
153+
= (be32_to_cpu(tail->change.days) * 86400LL +
154154
be32_to_cpu(tail->change.mins) * 60 +
155155
be32_to_cpu(tail->change.ticks) / 50 +
156-
((8 * 365 + 2) * 24 * 60 * 60)) +
156+
AFFS_EPOCH_DELTA) +
157157
sys_tz.tz_minuteswest * 60;
158158
inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_atime.tv_nsec = 0;
159159
affs_brelse(bh);

‎fs/affs/super.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
355355
sb->s_op = &affs_sops;
356356
sb->s_flags |= SB_NODIRATIME;
357357

358+
sb->s_time_gran = NSEC_PER_SEC;
359+
sb->s_time_min = sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
360+
sb->s_time_max = 86400LL * U32_MAX + 86400 + sb->s_time_min;
361+
358362
sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
359363
if (!sbi)
360364
return -ENOMEM;

‎fs/attr.c‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,18 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)
183183
inode->i_uid = attr->ia_uid;
184184
if (ia_valid & ATTR_GID)
185185
inode->i_gid = attr->ia_gid;
186-
if (ia_valid & ATTR_ATIME)
187-
inode->i_atime = timespec64_trunc(attr->ia_atime,
188-
inode->i_sb->s_time_gran);
189-
if (ia_valid & ATTR_MTIME)
190-
inode->i_mtime = timespec64_trunc(attr->ia_mtime,
191-
inode->i_sb->s_time_gran);
192-
if (ia_valid & ATTR_CTIME)
193-
inode->i_ctime = timespec64_trunc(attr->ia_ctime,
194-
inode->i_sb->s_time_gran);
186+
if (ia_valid & ATTR_ATIME) {
187+
inode->i_atime = timestamp_truncate(attr->ia_atime,
188+
inode);
189+
}
190+
if (ia_valid & ATTR_MTIME) {
191+
inode->i_mtime = timestamp_truncate(attr->ia_mtime,
192+
inode);
193+
}
194+
if (ia_valid & ATTR_CTIME) {
195+
inode->i_ctime = timestamp_truncate(attr->ia_ctime,
196+
inode);
197+
}
195198
if (ia_valid & ATTR_MODE) {
196199
umode_t mode = attr->ia_mode;
197200

‎fs/befs/linuxvfs.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
893893
sb_set_blocksize(sb, (ulong) befs_sb->block_size);
894894
sb->s_op = &befs_sops;
895895
sb->s_export_op = &befs_export_operations;
896+
sb->s_time_min = 0;
897+
sb->s_time_max = 0xffffffffffffll;
896898
root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->root_dir)));
897899
if (IS_ERR(root)) {
898900
ret = PTR_ERR(root);

‎fs/bfs/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
324324
return -ENOMEM;
325325
mutex_init(&info->bfs_lock);
326326
s->s_fs_info = info;
327+
s->s_time_min = 0;
328+
s->s_time_max = U32_MAX;
327329

328330
sb_set_blocksize(s, BFS_BSIZE);
329331

‎fs/ceph/super.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,8 @@ static int ceph_set_super(struct super_block *s, void *data)
979979
s->s_export_op = &ceph_export_ops;
980980

981981
s->s_time_gran = 1;
982+
s->s_time_min = 0;
983+
s->s_time_max = U32_MAX;
982984

983985
ret = set_anon_super(s, NULL); /* what is that second arg for? */
984986
if (ret != 0)

‎fs/cifs/cifsfs.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@
5656
#include "dfs_cache.h"
5757
#endif
5858

59+
/*
60+
* DOS dates from 1980/1/1 through 2107/12/31
61+
* Protocol specifications indicate the range should be to 119, which
62+
* limits maximum year to 2099. But this range has not been checked.
63+
*/
64+
#define SMB_DATE_MAX (127<<9 | 12<<5 | 31)
65+
#define SMB_DATE_MIN (0<<9 | 1<<5 | 1)
66+
#define SMB_TIME_MAX (23<<11 | 59<<5 | 29)
67+
5968
int cifsFYI = 0;
6069
bool traceSMB;
6170
bool enable_oplocks = true;
@@ -142,6 +151,7 @@ cifs_read_super(struct super_block *sb)
142151
struct inode *inode;
143152
struct cifs_sb_info *cifs_sb;
144153
struct cifs_tcon *tcon;
154+
struct timespec64 ts;
145155
int rc = 0;
146156

147157
cifs_sb = CIFS_SB(sb);
@@ -161,6 +171,18 @@ cifs_read_super(struct super_block *sb)
161171
/* BB FIXME fix time_gran to be larger for LANMAN sessions */
162172
sb->s_time_gran = 100;
163173

174+
if (tcon->unix_ext) {
175+
ts = cifs_NTtimeToUnix(0);
176+
sb->s_time_min = ts.tv_sec;
177+
ts = cifs_NTtimeToUnix(cpu_to_le64(S64_MAX));
178+
sb->s_time_max = ts.tv_sec;
179+
} else {
180+
ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MIN), 0, 0);
181+
sb->s_time_min = ts.tv_sec;
182+
ts = cnvrtDosUnixTm(cpu_to_le16(SMB_DATE_MAX), cpu_to_le16(SMB_TIME_MAX), 0);
183+
sb->s_time_max = ts.tv_sec;
184+
}
185+
164186
sb->s_magic = CIFS_MAGIC_NUMBER;
165187
sb->s_op = &cifs_super_ops;
166188
sb->s_xattr = cifs_xattr_handlers;

0 commit comments

Comments
 (0)