Commit e41f3029 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Ben Hutchings

dm snapshot: fix a possible invalid memory access on unload

commit 22aa66a3 upstream.

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: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 67a57692
...@@ -1444,8 +1444,6 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success) ...@@ -1444,8 +1444,6 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
full_bio->bi_end_io = pe->full_bio_end_io; full_bio->bi_end_io = pe->full_bio_end_io;
full_bio->bi_private = pe->full_bio_private; full_bio->bi_private = pe->full_bio_private;
} }
free_pending_exception(pe);
increment_pending_exceptions_done_count(); increment_pending_exceptions_done_count();
up_write(&s->lock); up_write(&s->lock);
...@@ -1462,6 +1460,8 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success) ...@@ -1462,6 +1460,8 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
} }
retry_origin_bios(s, origin_bios); retry_origin_bios(s, origin_bios);
free_pending_exception(pe);
} }
static void commit_callback(void *context, int success) static void commit_callback(void *context, int success)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment