btrfs: fix use-after-free of cmp workspace pages
PATCH 1/1 btrfs: fix use-after-free of cmp workspace pages
btrfs_cmp_data_free() puts cmp's src_pages and dst_pages, but leaves their page address intact. Now, if you hit "goto again" in btrfs_extent_same_range() and hit some error in btrfs_cmp_data_prepare(), you'll try to unlock/put already put pages.
This is simple fix to reset the address to avoid use-after-free.
Fixes 67b07bd4bec5 ("Btrfs: reuse cmp workspace in EXTENT_SAME ioctl")
Signed-off-by Naohiro Aota <[email protected]>
--- fs/btrfs/ioctl.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/ioctl.c +2 -0
@@ -3327,11 +3327,13 @@ static void btrfs_cmp_data_free(struct cmp_pages *cmp)if (pg) {unlock_page (pg);put_page (pg); + cmp->src_pages[i] =NULL ; } pg = cmp->dst_pages[i];if (pg) {unlock_page (pg);put_page (pg); + cmp->dst_pages[i] =NULL ; } } }
Signature · 1 line
2.18.0
Quoted 9 lines · Naohiro Aota
btrfs_cmp_data_free()puts cmp'ssrc_pagesanddst_pages, but leaves their page address intact. Now, if you hit "goto again" inbtrfs_extent_same_range()and hit some error inbtrfs_cmp_data_prepare(), you'll try to unlock/put already put pages.This is simple fix to reset the address to avoid use-after-free.
Fixes 67b07bd4bec5 ("Btrfs: reuse cmp workspace in EXTENT_SAME ioctl")Signed-off-by Naohiro Aota <[email protected]>
Thanks for catching it.
Reviewed-by David Sterba <[email protected]>