Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp223020pxx; Wed, 28 Oct 2020 03:17:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3/OO8rLLwOWsqko+DAMT95q5VXT7pYRQvS66XdUIrf1dxG8Fpeuahvq7rZAKuX3AfbhU3 X-Received: by 2002:aa7:c948:: with SMTP id h8mr6661683edt.171.1603880267141; Wed, 28 Oct 2020 03:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880267; cv=none; d=google.com; s=arc-20160816; b=F7I2KjAPEnzlhEI3VSRW76WUxiT9T67uS8ccNk2V05e3maaOs+qYthdo2d4iEUHXCN iE5nPum+bFwsBaQvAd4kIKhVf5XwASlgRJ2YNcsgyjwkmeOrIQGH4LjO2dP6nVcbtCrb f+tOPE5TuCmPnxvhNtk59Tysw23fcJE+Chz9MkPAe8Ivu4JXVInZYhwDIpyT6RZuabYf ien5wgoasrYghYMc1+8EU5mvkvqyDMXRqQmC0gv2sTiz0T2MC7YHB8/MFCIAEH3+xvoA vCSYh0CEIQuKb+AJ9dwvRH5H2HerYVULtvUUyT7ZfeG3Prvrx1801uQzWE1HY+qWNpSt o58g== 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=nmxUAYWAMJtHxXUPgHvip8CwwJ4TuI2RD+BqYfZUnKc=; b=OVoj+gyCYY6ZJ0slYLT5CARL/Y+NcMr5iqZHc9/raUsgQ0qZ1VHL+aATGpukcA3Iw0 bkHdYkJ8Qw1LlELRUbEs17CFY2uY3A3QrukYD7hOu52nqzVnFoNPqzwAKylU9e7hRfzj nQ4q9iYD+v+ssrDp6WV8Jg1T+vKK8db1sTOKXMQTx1VoHV6qTc3lNdo4Cs0j4L6CXE1K nNaiN67uV9MmizJ0grPnQasrhcEcjWKOqgYpXIhKJoQjpOQyBnqV53BnfGvTZofTgS8d eckLq3D5dliPzxS4a1VYaU1naUZ3S3uJxFn8W7E9U4C14hahWHck7at4N8i26rRYwIrx 8asg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jlvOnQ7k; 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 x26si2664388eds.99.2020.10.28.03.17.24; Wed, 28 Oct 2020 03:17:47 -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=jlvOnQ7k; 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 S1760925AbgJ0OhE (ORCPT + 99 others); Tue, 27 Oct 2020 10:37:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:35918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758649AbgJ0OhD (ORCPT ); Tue, 27 Oct 2020 10:37:03 -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 33F5A2225E; Tue, 27 Oct 2020 14:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809422; bh=PahXq6/N5/uraeLROJKcnKZLcuVN559gvYkSccDVgWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jlvOnQ7k2F37+GvlUeOYw1ExLxSpmjj6wgc0icTJ1vK7BQTmq9v3u0jPkHh1TD/yW ZJuo+BOPZFNhbDxth/3CY+5YoH2qmVbwD7W3pU+54qAsMAk1+cTvFyP2NiSL7dq6gb 6ks5xAtDkqvccIA5T4U0LjndoQoEnicK3i1itzNo= 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.4 191/408] mm/swapfile.c: fix potential memory leak in sys_swapon Date: Tue, 27 Oct 2020 14:52:09 +0100 Message-Id: <20201027135503.952005751@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 cf62bdb7b3045..ff83ffe7a9108 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3284,7 +3284,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); @@ -3309,6 +3309,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