Skip to content

Commit

Permalink
btrfs: fix extent map use-after-free when adding pages to compressed bio
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
fdmanana authored and kdave committed Jul 11, 2024
1 parent 320d8dc commit 8e78605
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
put_page(page);
break;
}
add_size = min(em->start + em->len, page_end + 1) - cur;
free_extent_map(em);

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

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

0 comments on commit 8e78605

Please sign in to comment.