]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: should put a page beyond EOF when preparing a write
authorJaegeuk Kim <jaegeuk@kernel.org>
Mon, 30 Aug 2021 20:30:45 +0000 (13:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:41:57 +0000 (13:41 +0200)
[ Upstream commit 9605f75cf36e0bcc0f4ada07b5be712d30107607 ]

The prepare_compress_overwrite() gets/locks a page to prepare a read, and calls
f2fs_read_multi_pages() which checks EOF first. If there's any page beyond EOF,
we unlock the page and set cc->rpages[i] = NULL, which we can't put the page
anymore. This makes page leak, so let's fix by putting that page.

Fixes: a949dc5f2c5c ("f2fs: compress: fix race condition of overwrite vs truncate")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/data.c

index 3cd509b085f2eccfd0ea998aa92dc2c35e7bc6b3..198e5ad7c98b52f9c9be1f8338162238a3afe2df 100644 (file)
@@ -2151,6 +2151,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
                        continue;
                }
                unlock_page(page);
+               if (for_write)
+                       put_page(page);
                cc->rpages[i] = NULL;
                cc->nr_rpages--;
        }