Skip to content

Commit a7a1598

Browse files
error27axboe
authored andcommitted
drbd: use after free in drbd_create_device()
The drbd_destroy_connection() frees the "connection" so use the _safe() iterator to prevent a use after free. Fixes: b6f85ef ("drbd: Iterate over all connections") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Christoph Böhmwalder <[email protected]> Link: https://lore.kernel.org/r/Y3Jd5iZRbNQ9w6gm@kili Signed-off-by: Jens Axboe <[email protected]>
1 parent d7dbd43 commit a7a1598

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/block/drbd/drbd_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ static int init_submitter(struct drbd_device *device)
26722672
enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigned int minor)
26732673
{
26742674
struct drbd_resource *resource = adm_ctx->resource;
2675-
struct drbd_connection *connection;
2675+
struct drbd_connection *connection, *n;
26762676
struct drbd_device *device;
26772677
struct drbd_peer_device *peer_device, *tmp_peer_device;
26782678
struct gendisk *disk;
@@ -2789,7 +2789,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
27892789
return NO_ERROR;
27902790

27912791
out_idr_remove_from_resource:
2792-
for_each_connection(connection, resource) {
2792+
for_each_connection_safe(connection, n, resource) {
27932793
peer_device = idr_remove(&connection->peer_devices, vnr);
27942794
if (peer_device)
27952795
kref_put(&connection->kref, drbd_destroy_connection);

0 commit comments

Comments
 (0)