linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] ovl: keep some file attrubutions after copy-up
@ 2020-12-26 10:46 Chengguang Xu
  2021-01-04  5:04 ` Amir Goldstein
  0 siblings, 1 reply; 4+ messages in thread
From: Chengguang Xu @ 2020-12-26 10:46 UTC (permalink / raw)
  To: miklos; +Cc: linux-unionfs, Chengguang Xu

Currently after copy-up, upper file will lose most of file
attributions except copy-up triggered by setting fsflags.
Because ioctl operation of underlying file systems does not
expect calling from kernel component, it seems hard to
copy fsflags during copy-up.

Overlayfs keeps limited attributions(append-only, etc) in it's
inode flags after successfully updating attributions. so ater
copy-up, lsattr(1) does not show correct result but overlayfs
can still prohibit ramdom write for those files which originally
have append-only attribution. However, recently I found this
protection can be easily broken in below operations.

1, Set append attribution to lower file.
2, Mount overlayfs.
3, Trigger copy-up by data append.
4, Set noatime attributtion to the file.
5, The file is random writable.

This patch tries to keep some file attributions after copy-up
so that overlayfs keeps compatible behavior with local filesystem
as much as possible.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/file.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index efccb7c1f9bc..e0eb055d00a6 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -655,12 +655,24 @@ static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd,
 
 long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
+	unsigned int imask = S_SYNC | S_APPEND | S_NOATIME;
+	unsigned int fsmask = FS_SYNC_FL | FS_APPEND_FL | FS_NOATIME_FL;
+	unsigned int flags, ovl_fsflags;
 	long ret;
 
 	switch (cmd) {
 	case FS_IOC_GETFLAGS:
 	case FS_IOC_FSGETXATTR:
 		ret = ovl_real_ioctl(file, cmd, arg);
+		if (!ret) {
+			if (get_user(flags, (int __user *) arg))
+				return -EFAULT;
+
+			ovl_fsflags = ovl_iflags_to_fsflags(file_inode(file)->i_flags & imask);
+			if ((flags & fsmask) != ovl_fsflags)
+				flags |= ovl_fsflags;
+			ret = put_user(flags, (int __user *)arg);
+		}
 		break;
 
 	case FS_IOC_SETFLAGS:
-- 
2.18.4


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

end of thread, other threads:[~2021-01-04  9:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-26 10:46 [RFC PATCH] ovl: keep some file attrubutions after copy-up Chengguang Xu
2021-01-04  5:04 ` Amir Goldstein
2021-01-04  6:55   ` Chengguang Xu
2021-01-04  9:01     ` Amir Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).