]> git.hungrycats.org Git - linux/commitdiff
afs: Fix page leak in afs_write_begin()
authorDavid Howells <dhowells@redhat.com>
Thu, 16 Mar 2017 16:27:48 +0000 (16:27 +0000)
committerSasha Levin <alexander.levin@microsoft.com>
Wed, 17 Jan 2018 17:55:35 +0000 (12:55 -0500)
[ 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 <dhowells@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
fs/afs/write.c

index cc46e8c1d46eb275e5e65933520d15a7d00760be..d89595155ec9258c1554bb314ea31f800187173c 100644 (file)
@@ -148,12 +148,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_CACHE_SIZE) {
                ret = afs_fill_page(vnode, key, index << PAGE_CACHE_SHIFT, page);
                if (ret < 0) {
+                       unlock_page(page);
+                       put_page(page);
                        kfree(candidate);
                        _leave(" = %d [prep]", ret);
                        return ret;
@@ -161,6 +161,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);