]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mm/swapfile.c: fix potential memory leak in sys_swapon
authorMiaohe Lin <linmiaohe@huawei.com>
Tue, 13 Oct 2020 23:52:30 +0000 (16:52 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:11:36 +0000 (10:11 +0100)
[ Upstream commit 822bca52ee7eb279acfba261a423ed7ac47d6f73 ]

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>
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>
mm/swapfile.c

index debc94155f74dd8b8f3be8fa32cc8f64fa4ff53a..b877c1504e00bc3715e8c590c7e350fa2286a9ee 100644 (file)
@@ -3343,7 +3343,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);
@@ -3368,6 +3368,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: