Commit 822bca52 authored by Miaohe Lin's avatar Miaohe Lin Committed by Linus Torvalds

mm/swapfile.c: fix potential memory leak in sys_swapon

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

Fixes: dc617f29 ("vfs: don't allow writes to swap files")
Signed-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Link: https://lkml.kernel.org/r/20200930101803.53884-1-linmiaohe@huawei.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7a3d52e4
...@@ -3342,7 +3342,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3342,7 +3342,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
error = inode_drain_writes(inode); error = inode_drain_writes(inode);
if (error) { if (error) {
inode->i_flags &= ~S_SWAPFILE; inode->i_flags &= ~S_SWAPFILE;
goto bad_swap_unlock_inode; goto free_swap_address_space;
} }
mutex_lock(&swapon_mutex); mutex_lock(&swapon_mutex);
...@@ -3367,6 +3367,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3367,6 +3367,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
error = 0; error = 0;
goto out; goto out;
free_swap_address_space:
exit_swap_address_space(p->type);
bad_swap_unlock_inode: bad_swap_unlock_inode:
inode_unlock(inode); inode_unlock(inode);
bad_swap: bad_swap:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment