Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp272111pxx; Wed, 28 Oct 2020 04:40:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn8K5WfWxDrhWwYUTOJ+eWrQ5FkAdSF71XvgEaGYFWNirR6tD5Vxk0GY0NjuXv/NnTbysX X-Received: by 2002:a17:906:4803:: with SMTP id w3mr6842719ejq.406.1603885241943; Wed, 28 Oct 2020 04:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603885241; cv=none; d=google.com; s=arc-20160816; b=kE6rebcoy7nok2jsFo27VqszkPLZyTl7eZC3gf+aBng9Wxg+am321wy/MaUVaY3/+W 7zgsy2L45UrkxjV2I4O1tgUy+d5+FpHwZwKaSPZ2zRUIfJvwxOp8RxkoXKGS2HtOClIl QgiFQMgvzanAxvVsY5XW5JcVHarCaRJffurmzAV49AdNbdbzTtM9rZJLyX+8jYIlqFQW duCkKU6UtoM+oljhO4iicfv2D616EsO1B60Co4XO0bCGQggRV5PoN6UJBozn6CqIEhiz Kv925Td30G79u5QI+29WCzxVKAU7tJlmdaM3hhCXuHlF3VRU1G7aHxfvA6fIQDCk+oRM 5xXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3Kip8ujIKKappcHhVp7+ubc2uuTi4BgTP4Q6FupN8nU=; b=I9t1FEUtuXA0I5dLQOCXIcnGadGsq+K8S+Vrt9ryRwa7XA72yAxhDZNT+fHUp8h8uo CZ3vCxP1xz3Q57hvWeji1ggtXatsw5Kzfkq6LpD1M73Fgbtd5jLrTLT7qCEHwvKMOSBV NHBCsxEKKfPmXbOrgxFLSlTEjpJNZVMRkleRqdAeKzWnO2/9de7NyKBNi045+KsQ2EGK 96DLZlG7FV7PrzRM93E0CnW6aUQHVj3ZZKgCN594ou9I5DAXgzP/txUGJ6v8xuBBQKxH uffIRdep2JdZ8BO2dxtlGiHSnC+/dX+OH0Y/6GU3/3540KROixirpl2Ssghr/8wjbvLk lCSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XtWhozHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si2654785ede.591.2020.10.28.04.40.20; Wed, 28 Oct 2020 04:40:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XtWhozHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368699AbgJ0PJx (ORCPT + 99 others); Tue, 27 Oct 2020 11:09:53 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: -- 2.25.1