Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1596336

[PATCH 23/27] afs: Fix page leak in afs_write_begin()

Path csiph.com!1.us.feeder.erje.net!feeder.erje.net!2.eu.feeder.erje.net!news.szaf.org!news.albasani.net!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From David Howells <dhowells@redhat.com>
Newsgroups linux.kernel
Subject [PATCH 23/27] afs: Fix page leak in afs_write_begin()
Date Thu, 09 Mar 2017 20:00:04 +0100
Message-ID <tjbs8-I0-73@gated-at.bofh.it> (permalink)
References <tjbs6-I0-7@gated-at.bofh.it>
X-Original-To viro@ZenIV.linux.org.uk
Organization Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903
User-Agent StGit/0.17.1-dirty
MIME-Version 1.0
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding 7bit
X-Scanned-By MIMEDefang 2.74 on 10.5.11.28
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 09 Mar 2017 18:58:30 +0000 (UTC)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 38
X-Original-Cc dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
X-Original-Date Thu, 09 Mar 2017 18:58:27 +0000
X-Original-Message-ID <148908590776.16794.7230863874143141245.stgit@warthog.procyon.org.uk>
X-Original-References <148908574888.16794.14109877851518811944.stgit@warthog.procyon.org.uk>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1596336

Show key headers only | View raw


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 <dhowells@redhat.com>
---

 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 f1450ea09406..6e13e96c3db0 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -154,12 +154,12 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
 		kfree(candidate);
 		return -ENOMEM;
 	}
-	*pagep = page;
-	/* page won't leak in error case: it eventually gets cleaned off LRU */
 
 	if (!PageUptodate(page) && len != PAGE_SIZE) {
 		ret = afs_fill_page(vnode, key, pos & PAGE_MASK, PAGE_SIZE, page);
 		if (ret < 0) {
+			unlock_page(page);
+			put_page(page);
 			kfree(candidate);
 			_leave(" = %d [prep]", ret);
 			return ret;
@@ -167,6 +167,9 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
 		SetPageUptodate(page);
 	}
 
+	/* page won't leak in error case: it eventually gets cleaned off LRU */
+	*pagep = page;
+
 try_again:
 	spin_lock(&vnode->writeback_lock);
 

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH 23/27] afs: Fix page leak in afs_write_begin() David Howells <dhowells@redhat.com> - 2017-03-09 20:00 +0100

csiph-web