From c65e3412df11e5fb668dfcbee21765a8ff6d75e6 Mon Sep 17 00:00:00 2001 From: Blagovest Kolenichev Date: Tue, 14 Jul 2020 22:08:04 -0700 Subject: [PATCH] Revert "FROMLIST: f2fs: fix use-after-free when accessing bio->bi_crypt_context" This reverts commit ec877350d0e8c1dba4ec7809a87000e3f0f17911. This is a preparation change for merging android-5.4-stable.50 into msm-5.4 branch. Newer version of the imported change is committed already as: 4c9af3eb8e f2fs: fix use-after-free when accessing bio->bi_crypt_context Change-Id: Ie0ff68e50ad1cfe8a3a257b2d24e55a000bbe5c2 Signed-off-by: Blagovest Kolenichev --- fs/f2fs/data.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 8cbfc7ea5d3d..a5d48e3626f9 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -797,10 +797,9 @@ static void del_bio_entry(struct bio_entry *be) kmem_cache_free(bio_entry_slab, be); } -static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio, +static int add_ipu_page(struct f2fs_sb_info *sbi, struct bio **bio, struct page *page) { - struct f2fs_sb_info *sbi = fio->sbi; enum temp_type temp; bool found = false; int ret = -EAGAIN; @@ -817,18 +816,13 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio, found = true; - if (page_is_mergeable(sbi, *bio, *fio->last_block, - fio->new_blkaddr) && - f2fs_crypt_mergeable_bio(*bio, - fio->page->mapping->host, - fio->page->index, fio) && - bio_add_page(*bio, page, PAGE_SIZE, 0) == - PAGE_SIZE) { + if (bio_add_page(*bio, page, PAGE_SIZE, 0) == + PAGE_SIZE) { ret = 0; break; } - /* page can't be merged into bio; submit the bio */ + /* bio is full */ del_bio_entry(be); __submit_bio(sbi, *bio, DATA); break; @@ -913,6 +907,11 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) trace_f2fs_submit_page_bio(page, fio); f2fs_trace_ios(fio, 0); + if (bio && (!page_is_mergeable(fio->sbi, bio, *fio->last_block, + fio->new_blkaddr) || + !f2fs_crypt_mergeable_bio(bio, fio->page->mapping->host, + fio->page->index, fio))) + f2fs_submit_merged_ipu_write(fio->sbi, &bio, NULL); alloc_new: if (!bio) { bio = __bio_alloc(fio, BIO_MAX_PAGES); @@ -924,7 +923,7 @@ alloc_new: add_bio_entry(fio->sbi, bio, page, fio->temp); } else { - if (add_ipu_page(fio, &bio, page)) + if (add_ipu_page(fio->sbi, &bio, page)) goto alloc_new; }