]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
f2fs: fix potential use-after-free issue
authorChao Yu <yuchao0@huawei.com>
Thu, 23 Apr 2020 09:57:33 +0000 (17:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jun 2020 15:48:43 +0000 (17:48 +0200)
[ Upstream commit f3494345ce9999624b36109252a4bf5f00e51a46 ]

In error path of f2fs_read_multi_pages(), it should let last referrer
release decompress io context memory, otherwise, other referrer will
cause use-after-free issue.

Fixes: 4c8ff7095bef ("f2fs: support data compression")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/data.c

index cdf2f626bea7abc896a5379a1fa815b5367f0afc..10491ae1cb8502959f7d70a2c8c965753f13a8e3 100644 (file)
@@ -2130,16 +2130,16 @@ submit_and_realloc:
                                        page->index, for_write);
                        if (IS_ERR(bio)) {
                                ret = PTR_ERR(bio);
-                               bio = NULL;
                                dic->failed = true;
                                if (refcount_sub_and_test(dic->nr_cpages - i,
-                                                       &dic->ref))
+                                                       &dic->ref)) {
                                        f2fs_decompress_end_io(dic->rpages,
                                                        cc->cluster_size, true,
                                                        false);
-                               f2fs_free_dic(dic);
+                                       f2fs_free_dic(dic);
+                               }
                                f2fs_put_dnode(&dn);
-                               *bio_ret = bio;
+                               *bio_ret = NULL;
                                return ret;
                        }
                }