From dc617f29dbe5ef0c8ced65ce62c464af1daaab3d Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 20 Aug 2019 07:55:16 -0700 Subject: vfs: don't allow writes to swap files Don't let userspace write to an active swap file because the kernel effectively has a long term lease on the storage and things could get seriously corrupted if we let this happen. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- mm/filemap.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mm/filemap.c') diff --git a/mm/filemap.c b/mm/filemap.c index d0cf700bf201..40667c2f3383 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2988,6 +2988,9 @@ inline ssize_t generic_write_checks(struct kiocb *iocb, struct iov_iter *from) loff_t count; int ret; + if (IS_SWAPFILE(inode)) + return -ETXTBSY; + if (!iov_iter_count(from)) return 0; -- cgit v1.2.3