linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: partially revert "don't allow writes to swap files"
@ 2020-03-03 19:10 Darrick J. Wong
  2020-03-04 15:48 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2020-03-03 19:10 UTC (permalink / raw)
  To: linux-pm, linux-mm, linux-fsdevel
  Cc: domenico.andreoli, mkleinsoft, hch, akpm, rjw, len.brown, pavel, viro

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(-)

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vfs: partially revert "don't allow writes to swap files"
  2020-03-03 19:10 [PATCH] vfs: partially revert "don't allow writes to swap files" Darrick J. Wong
@ 2020-03-04 15:48 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2020-03-04 15:48 UTC (permalink / raw)
  To: akpm; +Cc: linux-pm, linux-mm, linux-fsdevel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-04 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 19:10 [PATCH] vfs: partially revert "don't allow writes to swap files" Darrick J. Wong
2020-03-04 15:48 ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).