diff mbox series

vfs: partially revert "don't allow writes to swap files"

Message ID 20200303191023.GD8037@magnolia (mailing list archive)
State Not Applicable, archived
Headers show
Series vfs: partially revert "don't allow writes to swap files" | expand

Commit Message

Darrick J. Wong March 3, 2020, 7:10 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

In commit dc617f29dbe5 we tried to prevent userspace programs from
writing to active swap devices.  However, it turns out that userspace
hibernation requires the ability to write the hibernation image to a
swap device, so revert the write path checks.

Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
Reported-by: Marian Klein <mkleinsoft@gmail.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/block_dev.c |    3 ---
 mm/filemap.c   |    3 ---
 mm/memory.c    |    4 ----
 mm/mmap.c      |    8 ++------
 4 files changed, 2 insertions(+), 16 deletions(-)

Comments

Darrick J. Wong March 4, 2020, 3:48 p.m. UTC | #1
On Tue, Mar 03, 2020 at 11:10:23AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In commit dc617f29dbe5 we tried to prevent userspace programs from
> writing to active swap devices.  However, it turns out that userspace
> hibernation requires the ability to write the hibernation image to a
> swap device, so revert the write path checks.
> 
> Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
> Reported-by: Domenico Andreoli <domenico.andreoli@linux.com>
> Reported-by: Marian Klein <mkleinsoft@gmail.com>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

self-NAK, Domenico Andreoli has taken this on.  Andrew, could you please
drop this patch from your queue?

--D

> ---
>  fs/block_dev.c |    3 ---
>  mm/filemap.c   |    3 ---
>  mm/memory.c    |    4 ----
>  mm/mmap.c      |    8 ++------
>  4 files changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 69bf2fb6f7cd..08b088dac1f0 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -2001,9 +2001,6 @@ 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;
>  
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 1784478270e1..d1b8cd15b2bf 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2920,9 +2920,6 @@ 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;
>  
> diff --git a/mm/memory.c b/mm/memory.c
> index 0bccc622e482..e908490f7034 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2357,10 +2357,6 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf)
>  
>  	vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
>  
> -	if (vmf->vma->vm_file &&
> -	    IS_SWAPFILE(vmf->vma->vm_file->f_mapping->host))
> -		return VM_FAULT_SIGBUS;
> -
>  	ret = vmf->vma->vm_ops->page_mkwrite(vmf);
>  	/* Restore original flags so that caller is not surprised */
>  	vmf->flags = old_flags;
> diff --git a/mm/mmap.c b/mm/mmap.c
> index d681a20eb4ea..77d086139e13 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1461,12 +1461,8 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
>  		case MAP_SHARED_VALIDATE:
>  			if (flags & ~flags_mask)
>  				return -EOPNOTSUPP;
> -			if (prot & PROT_WRITE) {
> -				if (!(file->f_mode & FMODE_WRITE))
> -					return -EACCES;
> -				if (IS_SWAPFILE(file->f_mapping->host))
> -					return -ETXTBSY;
> -			}
> +			if ((prot&PROT_WRITE) && !(file->f_mode&FMODE_WRITE))
> +				return -EACCES;
>  
>  			/*
>  			 * Make sure we don't allow writing to an append-only
diff mbox series

Patch

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 69bf2fb6f7cd..08b088dac1f0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -2001,9 +2001,6 @@  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;
 
diff --git a/mm/filemap.c b/mm/filemap.c
index 1784478270e1..d1b8cd15b2bf 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2920,9 +2920,6 @@  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;
 
diff --git a/mm/memory.c b/mm/memory.c
index 0bccc622e482..e908490f7034 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2357,10 +2357,6 @@  static vm_fault_t do_page_mkwrite(struct vm_fault *vmf)
 
 	vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
 
-	if (vmf->vma->vm_file &&
-	    IS_SWAPFILE(vmf->vma->vm_file->f_mapping->host))
-		return VM_FAULT_SIGBUS;
-
 	ret = vmf->vma->vm_ops->page_mkwrite(vmf);
 	/* Restore original flags so that caller is not surprised */
 	vmf->flags = old_flags;
diff --git a/mm/mmap.c b/mm/mmap.c
index d681a20eb4ea..77d086139e13 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1461,12 +1461,8 @@  unsigned long do_mmap(struct file *file, unsigned long addr,
 		case MAP_SHARED_VALIDATE:
 			if (flags & ~flags_mask)
 				return -EOPNOTSUPP;
-			if (prot & PROT_WRITE) {
-				if (!(file->f_mode & FMODE_WRITE))
-					return -EACCES;
-				if (IS_SWAPFILE(file->f_mapping->host))
-					return -ETXTBSY;
-			}
+			if ((prot&PROT_WRITE) && !(file->f_mode&FMODE_WRITE))
+				return -EACCES;
 
 			/*
 			 * Make sure we don't allow writing to an append-only