Skip to content

Commit 8e78605

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: [email protected] Link: https://lore.kernel.org/linux-btrfs/[email protected]/ Fixes: 6a40491 ("btrfs: subpage: make add_ra_bio_pages() compatible") CC: [email protected] # 6.1+ Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 320d8dc commit 8e78605

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)