summaryrefslogtreecommitdiff
path: root/drivers/md/dm-core.h
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2023-08-09 12:44:20 +0200
committerMike Snitzer <snitzer@kernel.org>2023-09-14 11:18:29 -0400
commitf6007dce0cd35d634d9be91ef3515a6385dcee16 (patch)
tree663ba934a3a55514c73ef0e397c994ac3e4a3358 /drivers/md/dm-core.h
parent0bb80ecc33a8fb5a682236443c1e740d5c917d1d (diff)
dm: fix a race condition in retrieve_deps
There's a race condition in the multipath target when retrieve_deps races with multipath_message calling dm_get_device and dm_put_device. retrieve_deps walks the list of open devices without holding any lock but multipath may add or remove devices to the list while it is running. The end result may be memory corruption or use-after-free memory access. See this description of a UAF with multipath_message(): https://listman.redhat.com/archives/dm-devel/2022-October/052373.html Fix this bug by introducing a new rw semaphore "devices_lock". We grab devices_lock for read in retrieve_deps and we grab it for write in dm_get_device and dm_put_device. Reported-by: Luo Meng <luomeng12@huawei.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Cc: stable@vger.kernel.org Tested-by: Li Lingfeng <lilingfeng3@huawei.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers/md/dm-core.h')
-rw-r--r--drivers/md/dm-core.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index 0d93661f88d3..095b9b49aa82 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -214,6 +214,7 @@ struct dm_table {
/* a list of devices used by this table */
struct list_head devices;
+ struct rw_semaphore devices_lock;
/* events get handed up using this callback */
void (*event_fn)(void *data);