Commit 8b1e6694 authored by Amir Goldstein's avatar Amir Goldstein Committed by Greg Kroah-Hartman

ovl: fix missing upper fs freeze protection on copy up for ioctl

commit 3428030d upstream.

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: dab5ca8f ("ovl: add lsattr/chattr support")
Cc: <stable@vger.kernel.org> # v4.19
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Acked-by: default avatarVivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 62b91cdf
...@@ -909,14 +909,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags) ...@@ -909,14 +909,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
return true; 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; 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); err = ovl_want_write(dentry);
if (!err) { if (!err) {
err = ovl_copy_up_flags(dentry, file_flags); err = ovl_copy_up_flags(dentry, flags);
ovl_drop_write(dentry); ovl_drop_write(dentry);
} }
} }
......
...@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real) ...@@ -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) static int ovl_open(struct inode *inode, struct file *file)
{ {
struct dentry *dentry = file_dentry(file);
struct file *realfile; struct file *realfile;
int err; 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) if (err)
return err; return err;
...@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (ret) if (ret)
return ret; return ret;
ret = ovl_copy_up_with_data(file_dentry(file)); ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY);
if (!ret) { if (!ret) {
ret = ovl_real_ioctl(file, cmd, arg); ret = ovl_real_ioctl(file, cmd, arg);
......
...@@ -421,7 +421,7 @@ extern const struct file_operations ovl_file_operations; ...@@ -421,7 +421,7 @@ extern const struct file_operations ovl_file_operations;
int ovl_copy_up(struct dentry *dentry); int ovl_copy_up(struct dentry *dentry);
int ovl_copy_up_with_data(struct dentry *dentry); int ovl_copy_up_with_data(struct dentry *dentry);
int ovl_copy_up_flags(struct dentry *dentry, int flags); 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_copy_xattr(struct dentry *old, struct dentry *new);
int ovl_set_attr(struct dentry *upper, struct kstat *stat); int ovl_set_attr(struct dentry *upper, struct kstat *stat);
struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment