From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: Fix potential memory leak in sys_swapon
Date: Wed, 30 Sep 2020 08:32:21 -0700 [thread overview]
Message-ID: <20200930153221.GE49559@magnolia> (raw)
In-Reply-To: <20200930101803.53884-1-linmiaohe@huawei.com>
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
>
prev parent reply other threads:[~2020-09-30 15:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 10:18 Miaohe Lin
2020-09-30 15:32 ` Darrick J. Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200930153221.GE49559@magnolia \
--to=darrick.wong@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox