Skip to content

Commit 3b5e995

Browse files
fdmananakdave
authored andcommitted
btrfs: fix extent map use-after-free when adding pages to compressed bio
At add_ra_bio_pages() we are accessing the extent map to calculate 'add_size' after we dropped our reference on the extent map, resulting in a use-after-free. Fix this by computing 'add_size' before dropping our extent map reference. Reported-by: syzbot+853d80cba98ce1157ae6@syzkaller.appspotmail.com Link: https://lore.kernel.org/linux-btrfs/000000000000038144061c6d18f2@google.com/ Fixes: 6a40491 ("btrfs: subpage: make add_ra_bio_pages() compatible") Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com>
1 parent e5bc487 commit 3b5e995

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
515515
put_page(page);
516516
break;
517517
}
518+
add_size = min(em->start + em->len, page_end + 1) - cur;
518519
free_extent_map(em);
519520

520521
if (page->index == end_index) {
@@ -527,7 +528,6 @@ static noinline int add_ra_bio_pages(struct inode *inode,
527528
}
528529
}
529530

530-
add_size = min(em->start + em->len, page_end + 1) - cur;
531531
ret = bio_add_page(orig_bio, page, add_size, offset_in_page(cur));
532532
if (ret != add_size) {
533533
unlock_extent(tree, cur, page_end, NULL);

0 commit comments

Comments
 (0)