aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2010-03-05 21:32:29 -0500
committerAlasdair G Kergon <agk@redhat.com>2010-03-05 21:32:29 -0500
commita97f925a32aad2a37971d7bfb657006acf04e42d (patch)
tree38c74c60f756dd05611138f864340a31f4fc393f /drivers/md
parent8215d6ec5fee1e76545decea2cd73717efb5cb42 (diff)
dm: free dm_io before bio_endio not after
Free the dm_io structure before calling bio_endio() instead of after it, to ensure that the io_pool containing it is not referenced after it is freed. This partially fixes a problem described here https://www.redhat.com/archives/dm-devel/2010-February/msg00109.html thread 1: bio_endio(bio, io_error); /* scheduling happens */ thread 2: close the device remove the device thread 1: free_io(md, io); Thread 2, when removing the device, sees non-empty md->io_pool (because the io hasn't been freed by thread 1 yet) and may crash with BUG in mempool_free. Thread 1 may also crash, when freeing into a nonexisting mempool. To fix this we must make sure that bio_endio() is the last call and the md structure is not accessed afterwards. There is another bio_endio in process_barrier, but it is called from the thread and the thread is destroyed prior to freeing the mempools, so this call is not affected by the bug. A similar bug exists with module unloads - the module may be unloaded immediately after bio_endio - but that is more difficult to fix. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@kernel.org Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 21222f5193fb..7199846364e9 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -635,8 +635,10 @@ static void dec_pending(struct dm_io *io, int error)
635 if (!md->barrier_error && io_error != -EOPNOTSUPP) 635 if (!md->barrier_error && io_error != -EOPNOTSUPP)
636 md->barrier_error = io_error; 636 md->barrier_error = io_error;
637 end_io_acct(io); 637 end_io_acct(io);
638 free_io(md, io);
638 } else { 639 } else {
639 end_io_acct(io); 640 end_io_acct(io);
641 free_io(md, io);
640 642
641 if (io_error != DM_ENDIO_REQUEUE) { 643 if (io_error != DM_ENDIO_REQUEUE) {
642 trace_block_bio_complete(md->queue, bio); 644 trace_block_bio_complete(md->queue, bio);
@@ -644,8 +646,6 @@ static void dec_pending(struct dm_io *io, int error)
644 bio_endio(bio, io_error); 646 bio_endio(bio, io_error);
645 } 647 }
646 } 648 }
647
648 free_io(md, io);
649 } 649 }
650} 650}
651 651