Skip to content

Commit

Permalink
mm/swapfile.c: fix potential memory leak in sys_swapon
Browse files Browse the repository at this point in the history
[ Upstream commit 822bca5 ]

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

Fixes: dc617f2 ("vfs: don't allow writes to swap files")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Link: https://lkml.kernel.org/r/20200930101803.53884-1-linmiaohe@huawei.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
MiaoheLin authored and gregkh committed Oct 29, 2020
1 parent 8194371 commit 04fabdf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,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);
Expand All @@ -3309,6 +3309,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:
Expand Down

0 comments on commit 04fabdf

Please sign in to comment.