]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
dm: fix a race condition in dm_get_md
authorMikulas Patocka <mpatocka@redhat.com>
Tue, 17 Feb 2015 19:30:53 +0000 (14:30 -0500)
committerZefan Li <lizefan@huawei.com>
Fri, 19 Jun 2015 03:40:17 +0000 (11:40 +0800)
commit0a9cc6e9a5f5c91273e2a4fc9f1ce9b832e5ae03
tree2a16ef2633b43877782bba836cfd4ddfe4f43e81
parent0dbd8b6b207f284ec35cccba7da5d7de75280406
dm: fix a race condition in dm_get_md

commit 2bec1f4a8832e74ebbe859f176d8a9cb20dd97f4 upstream.

The function dm_get_md finds a device mapper device with a given dev_t,
increases the reference count and returns the pointer.

dm_get_md calls dm_find_md, dm_find_md takes _minor_lock, finds the
device, tests that the device doesn't have DMF_DELETING or DMF_FREEING
flag, drops _minor_lock and returns pointer to the device. dm_get_md then
calls dm_get. dm_get calls BUG if the device has the DMF_FREEING flag,
otherwise it increments the reference count.

There is a possible race condition - after dm_find_md exits and before
dm_get is called, there are no locks held, so the device may disappear or
DMF_FREEING flag may be set, which results in BUG.

To fix this bug, we need to call dm_get while we hold _minor_lock. This
patch renames dm_find_md to dm_get_md and changes it so that it calls
dm_get while holding the lock.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
drivers/md/dm.c