From 1120436b450e0193e0fb1584417ca15141901db4 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 12 Apr 2014 10:07:10 -0400 Subject: [PATCH] add patch disallow-all-fallocate-operation-on-active-swapfile --- ...llow-all-fallocate-operation-on-active-swapfile | 85 ++++++++++++++++++++++ series | 1 + timestamps | 13 +++- 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 disallow-all-fallocate-operation-on-active-swapfile diff --git a/disallow-all-fallocate-operation-on-active-swapfile b/disallow-all-fallocate-operation-on-active-swapfile new file mode 100644 index 00000000..c80e2c53 --- /dev/null +++ b/disallow-all-fallocate-operation-on-active-swapfile @@ -0,0 +1,85 @@ +fs: disallow all fallocate operation on active swapfile + +From: Lukas Czerner + +Currently some file system have IS_SWAPFILE check in their fallocate +implementations and some do not. However we should really prevent any +fallocate operation on swapfile so move the check to vfs and remove the +redundant checks from the file systems fallocate implementations. + +Signed-off-by: Lukas Czerner +Signed-off-by: "Theodore Ts'o" +--- + fs/ceph/file.c | 3 --- + fs/ext4/extents.c | 5 ----- + fs/ext4/inode.c | 5 ----- + fs/open.c | 7 +++++++ + 4 files changed, 7 insertions(+), 13 deletions(-) + +diff --git a/fs/ceph/file.c b/fs/ceph/file.c +index 66075a4..3a69d80 100644 +--- a/fs/ceph/file.c ++++ b/fs/ceph/file.c +@@ -1219,9 +1219,6 @@ static long ceph_fallocate(struct file *file, int mode, + if (!S_ISREG(inode->i_mode)) + return -EOPNOTSUPP; + +- if (IS_SWAPFILE(inode)) +- return -ETXTBSY; +- + mutex_lock(&inode->i_mutex); + + if (ceph_snap(inode) != CEPH_NOSNAP) { +diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c +index ff823b7..517b376 100644 +--- a/fs/ext4/extents.c ++++ b/fs/ext4/extents.c +@@ -5394,11 +5394,6 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len) + goto out_mutex; + } + +- if (IS_SWAPFILE(inode)) { +- ret = -ETXTBSY; +- goto out_mutex; +- } +- + /* Currently just for extent based files */ + if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { + ret = -EOPNOTSUPP; +diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c +index 56f1ff4..d8a270d 100644 +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -3529,11 +3529,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length) + + mutex_lock(&inode->i_mutex); + +- if (IS_SWAPFILE(inode)) { +- ret = -ETXTBSY; +- goto out_mutex; +- } +- + /* No need to punch hole beyond i_size */ + if (offset >= inode->i_size) + goto out_mutex; +diff --git a/fs/open.c b/fs/open.c +index 14af6be..48e3fd0 100644 +--- a/fs/open.c ++++ b/fs/open.c +@@ -266,6 +266,13 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len) + return -EPERM; + + /* ++ * We can not allow to do any fallocate operation on an active ++ * swapfile ++ */ ++ if (IS_SWAPFILE(inode)) ++ ret = -ETXTBSY; ++ ++ /* + * Revalidate the write permissions, in case security policy has + * changed since the files were opened. + */ +-- +1.8.3.1 + diff --git a/series b/series index fc60f0f8..b9fb9def 100644 --- a/series +++ b/series @@ -12,6 +12,7 @@ move-ext4_update_i_disksize-into-mpage_map_and_submit_extent remove-unnecessary-check-for-APPEND-and-IMMUTABLE prevent-doing-ZERO-RANGE-on-append-only-file remove-i_size-check-from-do_fallocate +disallow-all-fallocate-operation-on-active-swapfile ########################################## # unstable patches diff --git a/timestamps b/timestamps index 11c41b9a..e3d1c08e 100755 --- a/timestamps +++ b/timestamps @@ -29,10 +29,15 @@ touch -d @1396882460 note-the-error-in-ext4_end_bio touch -d @1396882461 fix-jbd2-warning-under-heavy-xattr-load touch -d @1396971508 update-PF_MEMALLOC-handling-in-ext4_write_inode touch -d @1397185100 fix-collapse-range-patches-in-data-journalling-mode -touch -d @1397185160 stable-boundary touch -d @1397185423 return-ENOMEM-rather-than-EIO touch -d @1397226917 move-ext4_update_i_disksize-into-mpage_map_and_submit_extent touch -d @1397265374 o_append-debug -touch -d @1397269300 series -touch -d @1397270577 status -touch -d @1397271034 timestamps +touch -d @1397273835 add-O_APPEND-locking +touch -d @1397310420 remove-unnecessary-check-for-APPEND-and-IMMUTABLE +touch -d @1397310694 prevent-doing-ZERO-RANGE-on-append-only-file +touch -d @1397311001 remove-i_size-check-from-do_fallocate +touch -d @1397311489 series +touch -d @1397311537 disallow-all-fallocate-operation-on-active-swapfile +touch -d @1397311597 stable-boundary +touch -d @1397311615 status +touch -d @1397311622 timestamps -- 2.11.4.GIT