Skip to content

Commit

Permalink
dm snapshot: fix a possible invalid memory access on unload
Browse files Browse the repository at this point in the history
When the snapshot target is unloaded, snapshot_dtr() waits until
pending_exceptions_count drops to zero.  Then, it destroys the snapshot.
Therefore, the function that decrements pending_exceptions_count
should not touch the snapshot structure after the decrement.

pending_complete() calls free_pending_exception(), which decrements
pending_exceptions_count, and then it performs up_write(&s->lock) and it
calls retry_origin_bios() which dereferences  s->origin.  These two
memory accesses to the fields of the snapshot may touch the dm_snapshot
struture after it is freed.

This patch moves the call to free_pending_exception() to the end of
pending_complete(), so that the snapshot will not be destroyed while
pending_complete() is in progress.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
  • Loading branch information
Mikulas Patocka authored and Mike Snitzer committed Feb 18, 2015
1 parent 2bec1f4 commit 22aa66a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/md/dm-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,8 +1432,6 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
full_bio->bi_private = pe->full_bio_private;
atomic_inc(&full_bio->bi_remaining);
}
free_pending_exception(pe);

increment_pending_exceptions_done_count();

up_write(&s->lock);
Expand All @@ -1450,6 +1448,8 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
}

retry_origin_bios(s, origin_bios);

free_pending_exception(pe);
}

static void commit_callback(void *context, int success)
Expand Down

0 comments on commit 22aa66a

Please sign in to comment.