summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-05-21 17:10:01 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2019-06-28 10:57:53 -0700
commit6f90c4ae9df52ba1db7caefca342ab4248977956 (patch)
treee4dab93f72c51604fc50682519f8dd2b5e829ee4 /fs
parentb9a268410f79b0d6d142f184a31208712de038cb (diff)
vfs: flush and wait for io when setting the immutable flag via SETFLAGS
When we're using FS_IOC_SETFLAGS to set the immutable flag on a file, we need to ensure that userspace can't continue to write the file after the file becomes immutable. To make that happen, we have to flush all the dirty pagecache pages to disk to ensure that we can fail a page fault on a mmap'd region, wait for pending directio to complete, and hope the caller locked out any new writes by holding the inode lock. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/inode.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/fs/inode.c b/fs/inode.c
index f08711b34341..65a412af3ffb 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2193,7 +2193,8 @@ EXPORT_SYMBOL(current_time);
/*
* Generic function to check FS_IOC_SETFLAGS values and reject any invalid
- * configurations.
+ * configurations. Once we're done, prepare the inode for whatever changes
+ * are coming down the pipeline.
*
* Note: the caller should be holding i_mutex, or else be sure that they have
* exclusive access to the inode structure.
@@ -2201,6 +2202,8 @@ EXPORT_SYMBOL(current_time);
int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,
unsigned int flags)
{
+ int ret;
+
/*
* The IMMUTABLE and APPEND_ONLY flags can only be changed by
* the relevant capability.
@@ -2211,7 +2214,21 @@ int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,
!capable(CAP_LINUX_IMMUTABLE))
return -EPERM;
- return 0;
+ /*
+ * Now that we're done checking the new flags, flush all pending IO and
+ * dirty mappings before setting S_IMMUTABLE on an inode via
+ * FS_IOC_SETFLAGS. If the flush fails we'll clear the flag before
+ * returning error.
+ */
+ if (!S_ISREG(inode->i_mode) || IS_IMMUTABLE(inode) ||
+ !(flags & FS_IMMUTABLE_FL))
+ return 0;
+
+ inode_set_flags(inode, S_IMMUTABLE, S_IMMUTABLE);
+ ret = inode_drain_writes(inode);
+ if (ret)
+ inode_set_flags(inode, 0, S_IMMUTABLE);
+ return ret;
}
EXPORT_SYMBOL(vfs_ioc_setflags_prepare);