btrfs: fix use-after-free of cmp workspace pages
authorNaohiro Aota <naota@elisp.net>
Fri, 13 Jul 2018 14:07:20 +0000 (23:07 +0900)
committerDavid Sterba <dsterba@suse.com>
Fri, 13 Jul 2018 15:31:35 +0000 (17:31 +0200)
commit97b191702b05a7cb9fa6d846adba68419cbbc7a6
tree00bfe21efca70c8504eac5e36715e940efbff446
parent20c5bbc640cdf8e23947990ab98f5ba950a3e1b0
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>
fs/btrfs/ioctl.c