]> git.karo-electronics.de Git - karo-tx-linux.git/commit
dm: free dm_io before bio_endio not after
authorMikulas Patocka <mpatocka@redhat.com>
Sat, 6 Mar 2010 02:32:29 +0000 (02:32 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 15 Mar 2010 16:07:08 +0000 (09:07 -0700)
commitf64089821be953b9b5b5ff49172780c929786614
tree12b07bd20d6ed2bfb364a55d3679faaf44112a24
parent53165f58afaf5045a52057f32b5b8dd67e90fe1c
dm: free dm_io before bio_endio not after

commit a97f925a32aad2a37971d7bfb657006acf04e42d upstream.

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>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/md/dm.c