diff options
author | Amir Goldstein <amir73il@gmail.com> | 2019-01-22 00:01:39 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2019-05-06 07:54:50 -0400 |
commit | 3428030da004a1128cbdcf93dc03e16f184d845b (patch) | |
tree | fa8bdd8c7fa12a50499519fe18123e4b271263d1 | |
parent | e93c9c99a629c61837d5a7fc2120cd2b6c70dbdd (diff) |
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: dab5ca8fd9dd ("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>
-rw-r--r-- | fs/overlayfs/copy_up.c | 6 | ||||
-rw-r--r-- | fs/overlayfs/file.c | 5 | ||||
-rw-r--r-- | fs/overlayfs/overlayfs.h | 2 |
3 files changed, 6 insertions, 7 deletions
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 68b3303e4b46..56feaa739979 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c | |||
@@ -909,14 +909,14 @@ static bool ovl_open_need_copy_up(struct dentry *dentry, int flags) | |||
909 | return true; | 909 | return true; |
910 | } | 910 | } |
911 | 911 | ||
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) |
913 | { | 913 | { |
914 | int err = 0; | 914 | int err = 0; |
915 | 915 | ||
916 | if (ovl_open_need_copy_up(dentry, file_flags)) { | 916 | if (ovl_open_need_copy_up(dentry, flags)) { |
917 | err = ovl_want_write(dentry); | 917 | err = ovl_want_write(dentry); |
918 | if (!err) { | 918 | if (!err) { |
919 | err = ovl_copy_up_flags(dentry, file_flags); | 919 | err = ovl_copy_up_flags(dentry, flags); |
920 | ovl_drop_write(dentry); | 920 | ovl_drop_write(dentry); |
921 | } | 921 | } |
922 | } | 922 | } |
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 84dd957efa24..50e4407398d8 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c | |||
@@ -116,11 +116,10 @@ static int ovl_real_fdget(const struct file *file, struct fd *real) | |||
116 | 116 | ||
117 | static int ovl_open(struct inode *inode, struct file *file) | 117 | static int ovl_open(struct inode *inode, struct file *file) |
118 | { | 118 | { |
119 | struct dentry *dentry = file_dentry(file); | ||
120 | struct file *realfile; | 119 | struct file *realfile; |
121 | int err; | 120 | int err; |
122 | 121 | ||
123 | err = ovl_open_maybe_copy_up(dentry, file->f_flags); | 122 | err = ovl_maybe_copy_up(file_dentry(file), file->f_flags); |
124 | if (err) | 123 | if (err) |
125 | return err; | 124 | return err; |
126 | 125 | ||
@@ -390,7 +389,7 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
390 | if (ret) | 389 | if (ret) |
391 | return ret; | 390 | return ret; |
392 | 391 | ||
393 | ret = ovl_copy_up_with_data(file_dentry(file)); | 392 | ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY); |
394 | if (!ret) { | 393 | if (!ret) { |
395 | ret = ovl_real_ioctl(file, cmd, arg); | 394 | ret = ovl_real_ioctl(file, cmd, arg); |
396 | 395 | ||
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 9c6018287d57..d26efed9f80a 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h | |||
@@ -421,7 +421,7 @@ extern const struct file_operations ovl_file_operations; | |||
421 | int ovl_copy_up(struct dentry *dentry); | 421 | int ovl_copy_up(struct dentry *dentry); |
422 | int ovl_copy_up_with_data(struct dentry *dentry); | 422 | int ovl_copy_up_with_data(struct dentry *dentry); |
423 | int ovl_copy_up_flags(struct dentry *dentry, int flags); | 423 | 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); |
425 | int ovl_copy_xattr(struct dentry *old, struct dentry *new); | 425 | int ovl_copy_xattr(struct dentry *old, struct dentry *new); |
426 | int ovl_set_attr(struct dentry *upper, struct kstat *stat); | 426 | int ovl_set_attr(struct dentry *upper, struct kstat *stat); |
427 | struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); | 427 | struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool is_upper); |