Return-Path: Received: from mail-sn1nam01on0125.outbound.protection.outlook.com ([104.47.32.125]:4176 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754866AbeARVGP (ORCPT ); Thu, 18 Jan 2018 16:06:15 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: David Howells , Sasha Levin Subject: [added to the 4.1 stable tree] afs: Fix page leak in afs_write_begin() Date: Thu, 18 Jan 2018 21:01:35 +0000 Message-ID: <20180118205908.3220-246-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: David Howells This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 6d06b0d25209c80e99c1e89700f1e09694a3766b ] afs_write_begin() leaks a ref and a lock on a page if afs_fill_page() fails. Fix the leak by unlocking and releasing the page in the error path. Signed-off-by: David Howells Signed-off-by: Sasha Levin --- fs/afs/write.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index cc46e8c1d46e..d89595155ec9 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -148,12 +148,12 @@ int afs_write_begin(struct file *file, struct address= _space *mapping, kfree(candidate); return -ENOMEM; } - *pagep =3D page; - /* page won't leak in error case: it eventually gets cleaned off LRU */ =20 if (!PageUptodate(page) && len !=3D PAGE_CACHE_SIZE) { ret =3D afs_fill_page(vnode, key, index << PAGE_CACHE_SHIFT, page); if (ret < 0) { + unlock_page(page); + put_page(page); kfree(candidate); _leave(" =3D %d [prep]", ret); return ret; @@ -161,6 +161,9 @@ int afs_write_begin(struct file *file, struct address_s= pace *mapping, SetPageUptodate(page); } =20 + /* page won't leak in error case: it eventually gets cleaned off LRU */ + *pagep =3D page; + try_again: spin_lock(&vnode->writeback_lock); =20 --=20 2.11.0