]> git.baikalelectronics.ru Git - kernel.git/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)
committerFilipe Manana <fdmanana@suse.com>
Tue, 31 May 2016 00:00:03 +0000 (01:00 +0100)
commit700ae94833052feb7eee1a60c1135b3a477297d0
treede3fd8d94140b60fb49bdcfc675c80ee069aec26
parent6b33efbfdf25fc1e2eb9c96408ac236735184f59
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>
fs/btrfs/extent_io.c