Skip to content

Commit 97b1917

Browse files
naotakdave
authored andcommitted
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: 67b07bd ("Btrfs: reuse cmp workspace in EXTENT_SAME ioctl") Signed-off-by: Naohiro Aota <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 20c5bbc commit 97b1917

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,11 +3327,13 @@ static void btrfs_cmp_data_free(struct cmp_pages *cmp)
33273327
if (pg) {
33283328
unlock_page(pg);
33293329
put_page(pg);
3330+
cmp->src_pages[i] = NULL;
33303331
}
33313332
pg = cmp->dst_pages[i];
33323333
if (pg) {
33333334
unlock_page(pg);
33343335
put_page(pg);
3336+
cmp->dst_pages[i] = NULL;
33353337
}
33363338
}
33373339
}

0 commit comments

Comments
 (0)