Skip to content

Commit

Permalink
dm: fix use after free crash due to incorrect cleanup sequence
Browse files Browse the repository at this point in the history
Linux 4.2-rc1 Commit 0f20972 ("dm: factor out a common
cleanup_mapped_device()") moved a common cleanup code to a separate
function.  Unfortunately, that commit incorrectly changed the order of
cleanup, so that it destroys the mapped_device's srcu structure
'io_barrier' before destroying its workqueue.

The function that is executed on the workqueue (dm_wq_work) uses the srcu
structure, thus it may use it after being freed.  That results in a
crash in the LVM test suite's mirror-vgreduce-removemissing.sh test.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 0f20972 ("dm: factor out a common cleanup_mapped_device()")
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Mikulas Patocka authored and Mike Snitzer committed Jul 13, 2015
1 parent 621739b commit b06075a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2277,8 +2277,6 @@ static void dm_init_old_md_queue(struct mapped_device *md)

static void cleanup_mapped_device(struct mapped_device *md)
{
cleanup_srcu_struct(&md->io_barrier);

if (md->wq)
destroy_workqueue(md->wq);
if (md->kworker_task)
Expand All @@ -2290,6 +2288,8 @@ static void cleanup_mapped_device(struct mapped_device *md)
if (md->bs)
bioset_free(md->bs);

cleanup_srcu_struct(&md->io_barrier);

if (md->disk) {
spin_lock(&_minor_lock);
md->disk->private_data = NULL;
Expand Down

0 comments on commit b06075a

Please sign in to comment.