[RFC PATCH 2/2] ovl: enhance write permission check for writable open

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check upper file's write permission when open on writable mode.

NOTE: lower files may be shared between differnt overlayfs instances,
so we skip the check of lower file to avoid introducing interferes.

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

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 6e454a294046..1c3c24d07d01 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -144,12 +144,18 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)
 static int ovl_open(struct inode *inode, struct file *file)
 {
 	struct file *realfile;
+	struct inode *upperinode;
 	int err;
 
 	err = ovl_maybe_copy_up(file_dentry(file), file->f_flags);
 	if (err)
 		return err;
 
+	upperinode = ovl_inode_upper(inode);
+	if (((file->f_mode & FMODE_WRITE) || file->f_flags & O_TRUNC) &&
+	    (upperinode && atomic_read(&upperinode->i_writecount) < 0))
+		return -ETXTBSY;
+
 	/* No longer need these flags, so don't pass them on to underlying fs */
 	file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
 
-- 
2.27.0






[Index of Archives]     [Linux Filesystems Devel]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux