mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 09:16:33 +00:00
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: dc617f29db
("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>
This commit is contained in:
parent
7a3d52e45e
commit
822bca52ee
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user