Skip to contentSkip to conversation

ovl: fix timestamp limits

PATCH In review Amir Goldstein 3 participants 9 messages Nov 11, 2019 – Nov 13, 2019

Subsystems (2)
lore
Share & tools
lore

Amir Goldstein

author maintainer
#0 lore raw

PATCH 1/1 ovl: fix timestamp limits

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

This change fixes xfstest generic/402 (verify filesystem timestamps for supported ranges).

---

(*) generic/402 currently does 'notrun' on overlayfs and need
a small fix that I will post shortly

 fs/overlayfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/overlayfs/super.c +2 -0
index 5d4faab57ba0..44915874fccb 100644
@@ -1621,6 +1621,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 
 		sb->s_stack_depth = ofs->upper_mnt->mnt_sb->s_stack_depth;
 		sb->s_time_gran = ofs->upper_mnt->mnt_sb->s_time_gran;
+		sb->s_time_min = ofs->upper_mnt->mnt_sb->s_time_min;
+		sb->s_time_max = ofs->upper_mnt->mnt_sb->s_time_max;
 
 	}
 	oe = ovl_get_lowerstack(sb, ofs);
Signature · 1 line
2.17.1
maintainer
#2 lore raw
In reply to Amir Goldstein
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Thanks,
Miklos

author maintainer
#3 lore raw
Quoted 12 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

clamping seems to happen when user sets the times, so setting the overlay limits to those of upper fs seems correct anyway.

Thanks,
Amir.

#4 lore raw
Quoted 12 lines · Amir Goldstein
Quoted 10 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

Quoted 5 lines
Quoted 2 lines

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

Clamping also happens as part of current_time(). If this is called on an inode belonging to the upper fs, then the timestamps are clamped to those limits.

-Deepa

author maintainer
#5 lore raw
Quoted 17 lines · Deepa Dinamani
Quoted 15 lines · Amir Goldstein
Quoted 12 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Quoted 7 lines
Quoted 2 lines

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

Clamping also happens as part of current_time(). If this is called on an inode belonging to the upper fs, then the timestamps are clamped to those limits.

OK, but from utimes syscall they do not get clamped inside filesystem only in syscall itself. Right?

Thanks,
Amir.

#6 lore raw
Quoted 22 lines · Amir Goldstein
Quoted 20 lines · Deepa Dinamani
Quoted 17 lines · Amir Goldstein
Quoted 12 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

Quoted 7 lines
Quoted 4 lines

Clamping also happens as part of current_time(). If this is called on an inode belonging to the upper fs, then the timestamps are clamped to those limits.

OK, but from utimes syscall they do not get clamped inside filesystem only in syscall itself. Right?

Yes, that's right.

-Deepa

maintainer
#7 lore raw
In reply to Amir Goldstein
Quoted 12 lines · Amir Goldstein
Quoted 10 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

Quoted 5 lines
Quoted 2 lines

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

Ah. How about moving the timestamp_truncate() inside notify_change()?

Quoted 3 lines

clamping seems to happen when user sets the times, so setting the overlay limits to those of upper fs seems correct anyway.

It does seem correct, I just think moving the truncation into the right layer would make more sense.

Thanks,
Miklos

maintainer
#8 lore raw
Quoted 13 lines · Miklos Szeredi
Quoted 12 lines · Amir Goldstein
Quoted 10 lines · Miklos Szeredi
Quoted 7 lines · Amir Goldstein

Overlayfs timestamp overflow limits should be inherrited from upper filesystem.

The current behavior, when overlayfs is over an underlying filesystem that does not support post 2038 timestamps (e.g. xfs), is that overlayfs overflows post 2038 timestamps instead of clamping them.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

How? Isn't the clamping supposed to happen in the underlying filesystem anyway?

Not sure if it is supposed to be it doesn't.
It happens in do_utimes() -> utimes_common()

Ah. How about moving the timestamp_truncate() inside notify_change()?

Untested patch below.

BTW overlayfs isn't the only one calling notify_change(). There's knfsd and ecryptfs, neither of which seems to clamp timestamps according on the underlying filesystem.

Thanks,
Miklos

fs/attr.c +5 -0
index df28035aa23e..e8de5e636e66 100644
@@ -268,8 +268,13 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
 	attr->ia_ctime = now;
 	if (!(ia_valid & ATTR_ATIME_SET))
 		attr->ia_atime = now;
+	else
+		attr->ia_atime = timestamp_truncate(attr->ia_atime, inode);
 	if (!(ia_valid & ATTR_MTIME_SET))
 		attr->ia_mtime = now;
+	else
+		attr->ia_mtime = timestamp_truncate(attr->ia_mtime, inode);
+
 	if (ia_valid & ATTR_KILL_PRIV) {
 		error = security_inode_need_killpriv(dentry);
 		if (error < 0)
fs/utimes.c +2 -6
index 1ba3f7883870..df483207da4e 100644
@@ -35,17 +35,13 @@ static int utimes_common(const struct path *path, struct timespec64 *times)
 	if (times) {
 		if (times[0].tv_nsec == UTIME_OMIT)
 			newattrs.ia_valid &= ~ATTR_ATIME;
-		else if (times[0].tv_nsec != UTIME_NOW) {
-			newattrs.ia_atime = timestamp_truncate(times[0], inode);
+		else if (times[0].tv_nsec != UTIME_NOW)
 			newattrs.ia_valid |= ATTR_ATIME_SET;
-		}
 
 		if (times[1].tv_nsec == UTIME_OMIT)
 			newattrs.ia_valid &= ~ATTR_MTIME;
-		else if (times[1].tv_nsec != UTIME_NOW) {
-			newattrs.ia_mtime = timestamp_truncate(times[1], inode);
+		else if (times[1].tv_nsec != UTIME_NOW)
 			newattrs.ia_valid |= ATTR_MTIME_SET;
-		}
 		/*
 		 * Tell setattr_prepare(), that this is an explicit time
 		 * update, even if neither ATTR_ATIME_SET nor ATTR_MTIME_SET