All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Fix potential memory leak in sys_swapon
@ 2020-09-30 10:18 Miaohe Lin
  2020-09-30 15:32 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Miaohe Lin @ 2020-09-30 10:18 UTC (permalink / raw)
  To: akpm, darrick.wong; +Cc: linux-mm, linux-kernel, linmiaohe

If we failed to drain inode, we would forget to free the swap address space
allocated by init_swap_address_space() above.

Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swapfile.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2b0c5fc1b0e6..4522b458a814 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3342,7 +3342,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 	error = inode_drain_writes(inode);
 	if (error) {
 		inode->i_flags &= ~S_SWAPFILE;
-		goto bad_swap_unlock_inode;
+		goto free_swap_address_space;
 	}
 
 	mutex_lock(&swapon_mutex);
@@ -3367,6 +3367,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 
 	error = 0;
 	goto out;
+free_swap_address_space:
+	exit_swap_address_space(p->type);
 bad_swap_unlock_inode:
 	inode_unlock(inode);
 bad_swap:
-- 
2.19.1


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

* Re: [PATCH] mm: Fix potential memory leak in sys_swapon
  2020-09-30 10:18 [PATCH] mm: Fix potential memory leak in sys_swapon Miaohe Lin
@ 2020-09-30 15:32 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2020-09-30 15:32 UTC (permalink / raw)
  To: Miaohe Lin; +Cc: akpm, linux-mm, linux-kernel

On Wed, Sep 30, 2020 at 06:18:03AM -0400, Miaohe Lin wrote:
> If we failed to drain inode, we would forget to free the swap address space
> allocated by init_swap_address_space() above.
> 
> Fixes: dc617f29dbe5 ("vfs: don't allow writes to swap files")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

LGTM,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  mm/swapfile.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 2b0c5fc1b0e6..4522b458a814 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -3342,7 +3342,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  	error = inode_drain_writes(inode);
>  	if (error) {
>  		inode->i_flags &= ~S_SWAPFILE;
> -		goto bad_swap_unlock_inode;
> +		goto free_swap_address_space;
>  	}
>  
>  	mutex_lock(&swapon_mutex);
> @@ -3367,6 +3367,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>  
>  	error = 0;
>  	goto out;
> +free_swap_address_space:
> +	exit_swap_address_space(p->type);
>  bad_swap_unlock_inode:
>  	inode_unlock(inode);
>  bad_swap:
> -- 
> 2.19.1
> 

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

end of thread, other threads:[~2020-09-30 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 10:18 [PATCH] mm: Fix potential memory leak in sys_swapon Miaohe Lin
2020-09-30 15:32 ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.