Skip to content

Commit 79bbefb

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix NULL pointer dereference in f2fs_verity_work()
If both compression and fsverity feature is on, generic/572 will report below NULL pointer dereference bug. BUG: kernel NULL pointer dereference, address: 0000000000000018 RIP: 0010:f2fs_verity_work+0x60/0x90 [f2fs] #PF: supervisor read access in kernel mode Workqueue: fsverity_read_queue f2fs_verity_work [f2fs] RIP: 0010:f2fs_verity_work+0x60/0x90 [f2fs] Call Trace: process_one_work+0x16c/0x3f0 worker_thread+0x4c/0x440 ? rescuer_thread+0x350/0x350 kthread+0xf8/0x130 ? kthread_unpark+0x70/0x70 ret_from_fork+0x35/0x40 There are two issue in f2fs_verity_work(): - it needs to traverse and verify all pages in bio. - if pages in bio belong to non-compressed cluster, accessing decompress IO context stored in page private will cause NULL pointer dereference. Fix them. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 23c51be commit 79bbefb

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

fs/f2fs/compress.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
477477
out_vunmap_rbuf:
478478
vunmap(dic->rbuf);
479479
out_free_dic:
480+
if (verity)
481+
refcount_add(dic->nr_cpages - 1, &dic->ref);
480482
if (!verity)
481483
f2fs_decompress_end_io(dic->rpages, dic->cluster_size,
482484
ret, false);

fs/f2fs/data.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,37 @@ static void f2fs_verify_pages(struct page **rpages, unsigned int cluster_size)
187187

188188
static void f2fs_verify_bio(struct bio *bio)
189189
{
190-
struct page *page = bio_first_page_all(bio);
191-
struct decompress_io_ctx *dic =
192-
(struct decompress_io_ctx *)page_private(page);
190+
struct bio_vec *bv;
191+
struct bvec_iter_all iter_all;
192+
193+
bio_for_each_segment_all(bv, bio, iter_all) {
194+
struct page *page = bv->bv_page;
195+
struct decompress_io_ctx *dic;
196+
197+
dic = (struct decompress_io_ctx *)page_private(page);
198+
199+
if (dic) {
200+
if (refcount_dec_not_one(&dic->ref))
201+
continue;
202+
f2fs_verify_pages(dic->rpages,
203+
dic->cluster_size);
204+
f2fs_free_dic(dic);
205+
continue;
206+
}
207+
208+
if (bio->bi_status || PageError(page))
209+
goto clear_uptodate;
193210

194-
f2fs_verify_pages(dic->rpages, dic->cluster_size);
195-
f2fs_free_dic(dic);
211+
if (fsverity_verify_page(page)) {
212+
SetPageUptodate(page);
213+
goto unlock;
214+
}
215+
clear_uptodate:
216+
ClearPageUptodate(page);
217+
ClearPageError(page);
218+
unlock:
219+
unlock_page(page);
220+
}
196221
}
197222
#endif
198223

0 commit comments

Comments
 (0)