From patchwork Tue Oct 27 13:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D27AEC63777 for ; Tue, 27 Oct 2020 16:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A02222470 for ; Tue, 27 Oct 2020 16:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603817195; bh=jDNgwTEc4vET+ph5pSJLbxGNYDhaGy2JVa0aFujKAjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KZEU+NYwkPCt55XsazdU8sRDwoBYbe7IHhQFp0dJsBGnKy7sUH2cTRjoAO2JP8LdN 0XPUhJUdwZ9SqU/JupOCqFbm9lCxesDyhOjNarCYL05TPVzIx9OpjvukpJxZB03R5z 6clXO0bqvArD7t5QHPFLaYfnuiAy9yR5vCfF6QxM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368842AbgJ0Ply (ORCPT ); Tue, 27 Oct 2020 11:41:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:54620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800520AbgJ0Pf5 (ORCPT ); Tue, 27 Oct 2020 11:35:57 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 84D1122264; Tue, 27 Oct 2020 15:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812957; bh=jDNgwTEc4vET+ph5pSJLbxGNYDhaGy2JVa0aFujKAjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xfAU9P1dF1DjRxmPvKaLpps9QdO8WANlqu28SU3K/Q8ZhGVT1Mx4rn8htEwxHhnKL GI/i5t4gRpnQBsiHluE2gs1BXg3mXbwGxz2hjAksXGHp3Tijh3w2p6WMFTLUjC48j6 kAqGrLndhJC4u5RLo+IYYimUNxkpzryrndSVwaSA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Andrew Morton , "Darrick J. Wong" , Linus Torvalds , Sasha Levin Subject: [PATCH 5.9 389/757] mm/swapfile.c: fix potential memory leak in sys_swapon Date: Tue, 27 Oct 2020 14:50:39 +0100 Message-Id: <20201027135508.795662818@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Miaohe Lin [ 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 Signed-off-by: Andrew Morton Reviewed-by: Darrick J. Wong Link: https://lkml.kernel.org/r/20200930101803.53884-1-linmiaohe@huawei.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/swapfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index debc94155f74d..b877c1504e00b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -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: