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>
This commit is contained in:
Darrick J. Wong
2019-08-20 07:55:16 -07:00
parent 1638045c36
commit dc617f29db
6 changed files with 38 additions and 3 deletions

View File

@@ -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;