ovl: fix missing upper fs freeze protection on copy up for ioctl
Amir Goldstein
maintainerPATCH 1/1 ovl: fix missing upper fs freeze protection on copy up for ioctl
Generalize the helper ovl_open_maybe_copy_up() and use it to copy up file with data before FS_IOC_SETFLAGS ioctl.
--- fs/overlayfs/copy_up.c | 6 +++--- fs/overlayfs/file.c | 5 ++--- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-)
fs/overlayfs/copy_up.c +3 -3
@@ -885,14 +885,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)return true; } -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags) +int ovl_maybe_copy_up (struct dentry *dentry,int flags) {int err =0 ; -if (ovl_open_need_copy_up (dentry, file_flags)) { +if (ovl_open_need_copy_up (dentry, flags)) { err =ovl_want_write (dentry);if (!err) { - err =ovl_copy_up_flags (dentry, file_flags); + err =ovl_copy_up_flags (dentry, flags);ovl_drop_write (dentry); } }
fs/overlayfs/file.c +2 -3
@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)static int ovl_open (struct inode *inode,struct file *file) { -struct dentry *dentry =file_dentry (file);struct file *realfile;int err; - err =ovl_open_maybe_copy_up (dentry, file->f_flags); + err =ovl_maybe_copy_up (file_dentry (file), file->f_flags);if (err)return err;
@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (ret)return ret; - ret =ovl_copy_up_with_data (file_dentry (file)); + ret =ovl_maybe_copy_up (file_dentry (file),O_WRONLY );if (!ret) { ret =ovl_real_ioctl (file, cmd, arg);
fs/overlayfs/overlayfs.h +1 -1
@@ -419,7 +419,7 @@ extern const struct file_operations ovl_file_operations;int ovl_copy_up (struct dentry *dentry);int ovl_copy_up_with_data (struct dentry *dentry);int ovl_copy_up_flags (struct dentry *dentry,int flags); -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags); +int ovl_maybe_copy_up (struct dentry *dentry,int flags);int ovl_copy_xattr (struct dentry *old,struct dentry *new);int ovl_set_attr (struct dentry *upper,struct kstat *stat);struct ovl_fh *ovl_encode_real_fh (struct dentry *real,bool is_upper);
Signature · 1 line
2.17.1
Quoted 6 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>
What upper fs freeze protection you are referring to. I am unable to see it in this new path.
Vivek
Quoted 70 lines
--- fs/overlayfs/copy_up.c | 6 +++--- fs/overlayfs/file.c | 5 ++--- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-)fs/overlayfs/copy_up.c +3
-3@@ -885,14 +885,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)return true; } -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags) +int ovl_maybe_copy_up (struct dentry *dentry,int flags) {int err =0 ; -if (ovl_open_need_copy_up (dentry, file_flags)) { +if (ovl_open_need_copy_up (dentry, flags)) { err =ovl_want_write (dentry);if (!err) { - err =ovl_copy_up_flags (dentry, file_flags); + err =ovl_copy_up_flags (dentry, flags);ovl_drop_write (dentry); } }fs/overlayfs/file.c +2
-3@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)static int ovl_open (struct inode *inode,struct file *file) { -struct dentry *dentry =file_dentry (file);struct file *realfile;int err; - err =ovl_open_maybe_copy_up (dentry, file->f_flags); + err =ovl_maybe_copy_up (file_dentry (file), file->f_flags);if (err)return err;@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (ret)return ret; - ret =ovl_copy_up_with_data (file_dentry (file)); + ret =ovl_maybe_copy_up (file_dentry (file),O_WRONLY );if (!ret) { ret =ovl_real_ioctl (file, cmd, arg);fs/overlayfs/overlayfs.h +1
-1@@ -419,7 +419,7 @@ extern const struct file_operations ovl_file_operations;int ovl_copy_up (struct dentry *dentry);int ovl_copy_up_with_data (struct dentry *dentry);int ovl_copy_up_flags (struct dentry *dentry,int flags); -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags); +int ovl_maybe_copy_up (struct dentry *dentry,int flags);int ovl_copy_xattr (struct dentry *old,struct dentry *new);int ovl_set_attr (struct dentry *upper,struct kstat *stat);struct ovl_fh *ovl_encode_real_fh (struct dentry *real,bool is_upper);Signature · 1 line
2.17.1
Amir Goldstein
maintainerQuoted 5 lines · Vivek Goyal
Quoted 3 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.
Quoted 7 lines
Quoted 3 lines
Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>What upper fs freeze protection you are referring to. I am unable to see it in this new path.
Changed from calling ovl_copy_up_with_data() to calling ovl_maybe_copy_up().
The former doesn't have ovl_want_write()/ovl_drop_write().
The FS_IOC_SETFLAGS ioctl is a bit of an odd ball in vfs, which probably caused the confusion.
File may be open O_RDONLY, but ioctl modifies the file. VFS does not call mnt_want_write_file() nor lock inode mutex, but fs-specific code for FS_IOC_SETFLAGS does.
So ovl_ioctl() calls mnt_want_write_file() for the overlay file, and fs-specific code calls mnt_want_write_file() for upper fs file, but there was no call for ovl_want_write() for copy up duration which prevents overlayfs from copying up on a frozen upper fs.
Thanks,
Amir.
Vivek Goyal
Acked-byQuoted 18 lines · Amir Goldstein
Quoted 5 lines · Vivek Goyal
Quoted 3 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.Quoted 7 lines
Quoted 3 lines
Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>What upper fs freeze protection you are referring to. I am unable to see it in this new path.
Changed from calling
ovl_copy_up_with_data()to callingovl_maybe_copy_up().
The former doesn't have ovl_want_write()/ovl_drop_write().
Quoted 10 lines
The
FS_IOC_SETFLAGSioctl is a bit of an odd ball in vfs, which probably caused the confusion.
File may be openO_RDONLY, but ioctl modifies the file. VFS does not callmnt_want_write_file()nor lock inode mutex, but fs-specific code forFS_IOC_SETFLAGSdoes.
Soovl_ioctl()callsmnt_want_write_file()for the overlay file, and fs-specific code callsmnt_want_write_file()for upper fs file, but there was no call forovl_want_write()for copy up duration which prevents overlayfs from copying up on a frozen upper fs.
Ok, thanks for the explanaiton. I understand it better now.
Vivek
Amir Goldstein
maintainerQuoted 8 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>---
Miklos,
Ping for this bug fix.
Thanks,
Amir.
Quoted 69 lines
fs/overlayfs/copy_up.c | 6 +++--- fs/overlayfs/file.c | 5 ++--- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-)fs/overlayfs/copy_up.c +3
-3@@ -885,14 +885,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)return true; } -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags) +int ovl_maybe_copy_up (struct dentry *dentry,int flags) {int err =0 ; -if (ovl_open_need_copy_up (dentry, file_flags)) { +if (ovl_open_need_copy_up (dentry, flags)) { err =ovl_want_write (dentry);if (!err) { - err =ovl_copy_up_flags (dentry, file_flags); + err =ovl_copy_up_flags (dentry, flags);ovl_drop_write (dentry); } }fs/overlayfs/file.c +2
-3@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)static int ovl_open (struct inode *inode,struct file *file) { -struct dentry *dentry =file_dentry (file);struct file *realfile;int err; - err =ovl_open_maybe_copy_up (dentry, file->f_flags); + err =ovl_maybe_copy_up (file_dentry (file), file->f_flags);if (err)return err;@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (ret)return ret; - ret =ovl_copy_up_with_data (file_dentry (file)); + ret =ovl_maybe_copy_up (file_dentry (file),O_WRONLY );if (!ret) { ret =ovl_real_ioctl (file, cmd, arg);fs/overlayfs/overlayfs.h +1
-2@@ -419,7 +419,7 @@ extern const struct file_operations ovl_file_operations;int ovl_copy_up (struct dentry *dentry);int ovl_copy_up_with_data (struct dentry *dentry);int ovl_copy_up_flags (struct dentry *dentry,int flags); -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags); +int ovl_maybe_copy_up (struct dentry *dentry,int flags);int ovl_copy_xattr (struct dentry *old,struct dentry *new);int ovl_set_attr (struct dentry *upper,struct kstat *stat);struct ovl_fh *ovl_encode_real_fh (struct dentry *real,bool is_upper); --2.17.1
Amir Goldstein
maintainerQuoted 6 lines · Amir Goldstein
Quoted 4 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.
Quoted 9 lines
Quoted 4 lines
Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>---
Miklos,
Ping for this bug fix.
PING^2
Quoted 72 lines
Thanks,
Amir.Quoted 69 lines
fs/overlayfs/copy_up.c | 6 +++--- fs/overlayfs/file.c | 5 ++--- fs/overlayfs/overlayfs.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-)fs/overlayfs/copy_up.c +3
-3@@ -885,14 +885,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)return true; } -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags) +int ovl_maybe_copy_up (struct dentry *dentry,int flags) {int err =0 ; -if (ovl_open_need_copy_up (dentry, file_flags)) { +if (ovl_open_need_copy_up (dentry, flags)) { err =ovl_want_write (dentry);if (!err) { - err =ovl_copy_up_flags (dentry, file_flags); + err =ovl_copy_up_flags (dentry, flags);ovl_drop_write (dentry); } }fs/overlayfs/file.c +2
-3@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)static int ovl_open (struct inode *inode,struct file *file) { -struct dentry *dentry =file_dentry (file);struct file *realfile;int err; - err =ovl_open_maybe_copy_up (dentry, file->f_flags); + err =ovl_maybe_copy_up (file_dentry (file), file->f_flags);if (err)return err;@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (ret)return ret; - ret =ovl_copy_up_with_data (file_dentry (file)); + ret =ovl_maybe_copy_up (file_dentry (file),O_WRONLY );if (!ret) { ret =ovl_real_ioctl (file, cmd, arg);fs/overlayfs/overlayfs.h +1
-2@@ -419,7 +419,7 @@ extern const struct file_operations ovl_file_operations;int ovl_copy_up (struct dentry *dentry);int ovl_copy_up_with_data (struct dentry *dentry);int ovl_copy_up_flags (struct dentry *dentry,int flags); -int ovl_open_maybe_copy_up (struct dentry *dentry,unsigned int file_flags); +int ovl_maybe_copy_up (struct dentry *dentry,int flags);int ovl_copy_xattr (struct dentry *old,struct dentry *new);int ovl_set_attr (struct dentry *upper,struct kstat *stat);struct ovl_fh *ovl_encode_real_fh (struct dentry *real,bool is_upper); --2.17.1
Quoted 11 lines · Amir Goldstein
Quoted 9 lines · Amir Goldstein
Quoted 7 lines · Amir Goldstein
Generalize the helper
ovl_open_maybe_copy_up()and use it to copy up file with data beforeFS_IOC_SETFLAGSioctl.Fixes dab5ca8fd9dd ("ovl: add lsattr/chattr support")Cc <[email protected]> # v4.19Signed-off-by Amir Goldstein <[email protected]>
Thanks, applied.
Miklos