summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2019-06-05 11:04:49 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2019-06-09 13:06:19 -0400
commite38f7f53c35213b1cbce70eee5de7ced17f40d4a (patch)
tree16dc10d9c6ad567b4626798612688c586e86e71d
parent96e6e8f4a68df2d94800311163faa67124df24e5 (diff)
vfs: introduce file_modified() helper
The combination of file_remove_privs() and file_update_mtime() is quite common in filesystem ->write_iter() methods. Modelled after the helper file_accessed(), introduce file_modified() and use it from generic_remap_file_range_prep(). Note that the order of calling file_remove_privs() before file_update_mtime() in the helper was matched to the more common order by filesystems and not the current order in generic_remap_file_range_prep(). Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/inode.c20
-rw-r--r--fs/read_write.c21
-rw-r--r--include/linux/fs.h2
3 files changed, 25 insertions, 18 deletions
diff --git a/fs/inode.c b/fs/inode.c
index df6542ec3b88..4348cfb14562 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1899,6 +1899,26 @@ int file_update_time(struct file *file)
1899} 1899}
1900EXPORT_SYMBOL(file_update_time); 1900EXPORT_SYMBOL(file_update_time);
1901 1901
1902/* Caller must hold the file's inode lock */
1903int file_modified(struct file *file)
1904{
1905 int err;
1906
1907 /*
1908 * Clear the security bits if the process is not being run by root.
1909 * This keeps people from modifying setuid and setgid binaries.
1910 */
1911 err = file_remove_privs(file);
1912 if (err)
1913 return err;
1914
1915 if (unlikely(file->f_mode & FMODE_NOCMTIME))
1916 return 0;
1917
1918 return file_update_time(file);
1919}
1920EXPORT_SYMBOL(file_modified);
1921
1902int inode_needs_sync(struct inode *inode) 1922int inode_needs_sync(struct inode *inode)
1903{ 1923{
1904 if (IS_SYNC(inode)) 1924 if (IS_SYNC(inode))
diff --git a/fs/read_write.c b/fs/read_write.c
index b0fb1176b628..cec7e7b1f693 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1980,25 +1980,10 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
1980 return ret; 1980 return ret;
1981 1981
1982 /* If can't alter the file contents, we're done. */ 1982 /* If can't alter the file contents, we're done. */
1983 if (!(remap_flags & REMAP_FILE_DEDUP)) { 1983 if (!(remap_flags & REMAP_FILE_DEDUP))
1984 /* Update the timestamps, since we can alter file contents. */ 1984 ret = file_modified(file_out);
1985 if (!(file_out->f_mode & FMODE_NOCMTIME)) {
1986 ret = file_update_time(file_out);
1987 if (ret)
1988 return ret;
1989 }
1990 1985
1991 /* 1986 return ret;
1992 * Clear the security bits if the process is not being run by
1993 * root. This keeps people from modifying setuid and setgid
1994 * binaries.
1995 */
1996 ret = file_remove_privs(file_out);
1997 if (ret)
1998 return ret;
1999 }
2000
2001 return 0;
2002} 1987}
2003EXPORT_SYMBOL(generic_remap_file_range_prep); 1988EXPORT_SYMBOL(generic_remap_file_range_prep);
2004 1989
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e4d382c4342a..79ffa2958bd8 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2177,6 +2177,8 @@ static inline void file_accessed(struct file *file)
2177 touch_atime(&file->f_path); 2177 touch_atime(&file->f_path);
2178} 2178}
2179 2179
2180extern int file_modified(struct file *file);
2181
2180int sync_inode(struct inode *inode, struct writeback_control *wbc); 2182int sync_inode(struct inode *inode, struct writeback_control *wbc);
2181int sync_inode_metadata(struct inode *inode, int wait); 2183int sync_inode_metadata(struct inode *inode, int wait);
2182 2184