From patchwork Tue Oct 27 13:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 289843 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=ham 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 44293C55178 for ; Tue, 27 Oct 2020 15:07:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8270223FB for ; Tue, 27 Oct 2020 15:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811236; bh=LGwsaEU/vCW1w8rIqeoh0Z85x0b832Nyw5LMC9pOKSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oD7jDJmuJ25aWD9+wjLvX++PdsXhvBtvEH+uucyFCybGqd4XFSDLywmofaS5/ulRY QYYOUZkr5I26KyDzukGuSfvgNARIDRMfBoaMVF0jIrCLCWrOMHE92nN3huHjCO2jz8 emkl9nYUiR5/87Q7iIcLcE8tC4x+H9K9buC5rOD0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1793570AbgJ0PHM (ORCPT ); Tue, 27 Oct 2020 11:07:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:38226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1790069AbgJ0PDq (ORCPT ); Tue, 27 Oct 2020 11:03:46 -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 0578E20747; Tue, 27 Oct 2020 15:03:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811025; bh=LGwsaEU/vCW1w8rIqeoh0Z85x0b832Nyw5LMC9pOKSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XtWhozHfwnBzwHqpwdw7nyfDViB+0MIBQeggdbE8DervjpkF8YJpNDXqFbFljL8jM Bz4ZOVtEXFozmsTujJIEfLRqYUJkB3OpxeFotaZRR/aaEFQR9v3YxydfUFONjLAEII Z9/r1Op7Ga2Z20CR/HwL07iD91mG9es2d19/NmzA= 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.8 316/633] mm/swapfile.c: fix potential memory leak in sys_swapon Date: Tue, 27 Oct 2020 14:50:59 +0100 Message-Id: <20201027135537.500219645@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 26707c5dc9fce..605294e4df684 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3336,7 +3336,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); @@ -3361,6 +3361,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: