]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drbd: use after free in drbd_create_device()
authorDan Carpenter <error27@gmail.com>
Tue, 15 Nov 2022 13:16:43 +0000 (16:16 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 16:42:16 +0000 (17:42 +0100)
[ Upstream commit f459c52f2e4c3903d5c5d05145f33cffe001c986 ]

The drbd_destroy_connection() frees the "connection" so use the _safe()
iterator to prevent a use after free.

Fixes: f6838346e19b ("drbd: Iterate over all connections")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Link: https://lore.kernel.org/r/Y3Jd5iZRbNQ9w6gm@kili
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/drbd/drbd_main.c

index 5ece2fd70d9cfe9b2c6f2afeea02115de18f1f9c..f3a96c76f5a482fff40fc65530050478789e86eb 100644 (file)
@@ -2778,7 +2778,7 @@ static int init_submitter(struct drbd_device *device)
 enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigned int minor)
 {
        struct drbd_resource *resource = adm_ctx->resource;
-       struct drbd_connection *connection;
+       struct drbd_connection *connection, *n;
        struct drbd_device *device;
        struct drbd_peer_device *peer_device, *tmp_peer_device;
        struct gendisk *disk;
@@ -2906,7 +2906,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
 out_idr_remove_vol:
        idr_remove(&connection->peer_devices, vnr);
 out_idr_remove_from_resource:
-       for_each_connection(connection, resource) {
+       for_each_connection_safe(connection, n, resource) {
                peer_device = idr_remove(&connection->peer_devices, vnr);
                if (peer_device)
                        kref_put(&connection->kref, drbd_destroy_connection);