dm writecache: fix data corruption when reloading the target
authorMikulas Patocka <mpatocka@redhat.com>
Wed, 15 Apr 2020 15:01:38 +0000 (11:01 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 May 2020 06:15:10 +0000 (08:15 +0200)
commitbeed763ab9349e96273154d361416a410e9c199f
tree553ca84815cc6a7ab6ef1cd223af37ced735e7b6
parent969b9cb1209b2fd6fb3e1b6cda006e26dfeec51e
dm writecache: fix data corruption when reloading the target

commit 31b22120194b5c0d460f59e0c98504de1d3f1f14 upstream.

The dm-writecache reads metadata in the target constructor. However, when
we reload the target, there could be another active instance running on
the same device. This is the sequence of operations when doing a reload:

1. construct new target
2. suspend old target
3. resume new target
4. destroy old target

Metadata that were written by the old target between steps 1 and 2 would
not be visible by the new target.

Fix the data corruption by loading the metadata in the resume handler.

Also, validate block_size is at least as large as both the devices'
logical block size and only read 1 block from the metadata during
target constructor -- no need to read entirety of metadata now that it
is done during resume.

Fixes: 48debafe4f2f ("dm: add writecache target")
Cc: stable@vger.kernel.org # v4.18+
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-writecache.c