summaryrefslogtreecommitdiff
path: root/fs/iomap
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-03-18 20:37:30 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2021-03-18 20:37:30 +0300
commit8ff0f3bf5d6513dfb7462246d9c656da7c02b37e (patch)
tree03e889ee36115d505b2dc822a907f5e4cbed1b91 /fs/iomap
parent6417f03132a6952cd17ddd8eaddbac92b61b17e0 (diff)
parent5808fecc572391867fcd929662b29c12e6d08d81 (diff)
downloadlinux-8ff0f3bf5d6513dfb7462246d9c656da7c02b37e.tar.xz
Merge branch 'iomap-5.12-fixes' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull iomap fix from Darrick Wong: "A single fix to the iomap code which fixes some drama when someone gives us a {de,ma}liciously fragmented swap file" * 'iomap-5.12-fixes' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: iomap: Fix negative assignment to unsigned sis->pages in iomap_swapfile_activate
Diffstat (limited to 'fs/iomap')
-rw-r--r--fs/iomap/swapfile.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/fs/iomap/swapfile.c b/fs/iomap/swapfile.c
index a648dbf6991e..a5e478de1417 100644
--- a/fs/iomap/swapfile.c
+++ b/fs/iomap/swapfile.c
@@ -170,6 +170,16 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
return ret;
}
+ /*
+ * If this swapfile doesn't contain even a single page-aligned
+ * contiguous range of blocks, reject this useless swapfile to
+ * prevent confusion later on.
+ */
+ if (isi.nr_pages == 0) {
+ pr_warn("swapon: Cannot find a single usable page in file.\n");
+ return -EINVAL;
+ }
+
*pagespan = 1 + isi.highest_ppage - isi.lowest_ppage;
sis->max = isi.nr_pages;
sis->pages = isi.nr_pages - 1;