summaryrefslogtreecommitdiffstats
path: root/fs/block_dev.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-08-20 16:55:16 +0200
committerDarrick J. Wong <darrick.wong@oracle.com>2019-08-20 16:55:16 +0200
commitdc617f29dbe5ef0c8ced65ce62c464af1daaab3d (patch)
tree3596eb0d334f04f87088c735748bba8e66a71cad /fs/block_dev.c
parentmm: set S_SWAPFILE on blockdev swap devices (diff)
downloadlinux-dc617f29dbe5ef0c8ced65ce62c464af1daaab3d.tar.xz
linux-dc617f29dbe5ef0c8ced65ce62c464af1daaab3d.zip
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 <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r--fs/block_dev.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index c2a85b587922..d9bab63a9b81 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1978,6 +1978,9 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (bdev_read_only(I_BDEV(bd_inode)))
return -EPERM;
+ if (IS_SWAPFILE(bd_inode))
+ return -ETXTBSY;
+
if (!iov_iter_count(from))
return 0;