]> git.hungrycats.org Git - linux/commit
Btrfs: fix race between device replace and read repair
authorFilipe Manana <fdmanana@suse.com>
Fri, 27 May 2016 21:21:27 +0000 (22:21 +0100)
committerZygo Blaxell <zblaxell@waya.furryterror.org>
Wed, 17 Aug 2016 02:39:18 +0000 (22:39 -0400)
commit18e5be388ae319c0cb766ed52c93dadbb990807c
treee179ac740d4b3db25db17a76923db4257f0be88d
parent042d51bebcf0c4d76f4d08c2f390cf298dfef1c5
Btrfs: fix race between device replace and read repair

While we are finishing a device replace operation we can have a concurrent
task trying to do a read repair operation, in which case it will call
btrfs_map_block() to get a struct btrfs_bio which can have a stripe that
points to the source device of the device replace operation. This allows
for the read repair task to dereference the stripe's device pointer after
the device replace operation has freed the source device, resulting in
an invalid memory access. This is similar to the problem solved by my
previous patch in the same series and named "Btrfs: fix race between
device replace and discard".

So fix this by surrounding the call to btrfs_map_block() and the code
that uses the returned struct btrfs_bio with calls to
btrfs_bio_counter_inc_blocked() and btrfs_bio_counter_dec(), giving the
proper serialization with the finishing phase of the device replace
operation.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
(cherry picked from commit b5de8d0df80fa87f1f97fbcc4bbc8cad0a018802)
fs/btrfs/extent_io.c