Skip to content

Commit 3428030

Browse files
amir73ilMiklos Szeredi
authored andcommitted
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. 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. Fixes: dab5ca8 ("ovl: add lsattr/chattr support") Cc: <stable@vger.kernel.org> # v4.19 Signed-off-by: Amir Goldstein <amir73il@gmail.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent e93c9c9 commit 3428030

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

‎fs/overlayfs/copy_up.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,14 +909,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
909909
return true;
910910
}
911911

912-
int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags)
912+
int ovl_maybe_copy_up(struct dentry *dentry, int flags)
913913
{
914914
int err = 0;
915915

916-
if (ovl_open_need_copy_up(dentry, file_flags)) {
916+
if (ovl_open_need_copy_up(dentry, flags)) {
917917
err = ovl_want_write(dentry);
918918
if (!err) {
919-
err = ovl_copy_up_flags(dentry, file_flags);
919+
err = ovl_copy_up_flags(dentry, flags);
920920
ovl_drop_write(dentry);
921921
}
922922
}

‎fs/overlayfs/file.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)
116116

117117
static int ovl_open(struct inode *inode, struct file *file)
118118
{
119-
struct dentry *dentry = file_dentry(file);
120119
struct file *realfile;
121120
int err;
122121

123-
err = ovl_open_maybe_copy_up(dentry, file->f_flags);
122+
err = ovl_maybe_copy_up(file_dentry(file), file->f_flags);
124123
if (err)
125124
return err;
126125

@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
390389
if (ret)
391390
return ret;
392391

393-
ret = ovl_copy_up_with_data(file_dentry(file));
392+
ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY);
394393
if (!ret) {
395394
ret = ovl_real_ioctl(file, cmd, arg);
396395

‎fs/overlayfs/overlayfs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ extern const struct file_operations ovl_file_operations;
421421
int ovl_copy_up(struct dentry *dentry);
422422
int ovl_copy_up_with_data(struct dentry *dentry);
423423
int ovl_copy_up_flags(struct dentry *dentry, int flags);
424-
int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags);
424+
int ovl_maybe_copy_up(struct dentry *dentry, int flags);
425425
int ovl_copy_xattr(struct dentry *old, struct dentry *new);
426426
int ovl_set_attr(struct dentry *upper, struct kstat *stat);
427427
struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);

0 commit comments

Comments
 (0)