Browse Source

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 <naota@elisp.net>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Naohiro Aota 7 years ago
parent
commit
97b191702b
1 changed files with 2 additions and 0 deletions
  1. 2 0
      fs/btrfs/ioctl.c

+ 2 - 0
fs/btrfs/ioctl.c

@@ -3327,11 +3327,13 @@ static void btrfs_cmp_data_free(struct cmp_pages *cmp)
 		if (pg) {
 		if (pg) {
 			unlock_page(pg);
 			unlock_page(pg);
 			put_page(pg);
 			put_page(pg);
+			cmp->src_pages[i] = NULL;
 		}
 		}
 		pg = cmp->dst_pages[i];
 		pg = cmp->dst_pages[i];
 		if (pg) {
 		if (pg) {
 			unlock_page(pg);
 			unlock_page(pg);
 			put_page(pg);
 			put_page(pg);
+			cmp->dst_pages[i] = NULL;
 		}
 		}
 	}
 	}
 }
 }