Skip to content

Commit ae4d37b

Browse files
Xiaomeng Tongaxboe
authored andcommitted
drbd: fix an invalid memory access caused by incorrect use of list iterator
The bug is here: idr_remove(&connection->peer_devices, vnr); If the previous for_each_connection() don't exit early (no goto hit inside the loop), the iterator 'connection' after the loop will be a bogus pointer to an invalid structure object containing the HEAD (&resource->connections). As a result, the use of 'connection' above will lead to a invalid memory access (including a possible invalid free as idr_remove could call free_layer). The original intention should have been to remove all peer_devices, but the following lines have already done the work. So just remove this line and the unneeded label, to fix this bug. Cc: stable@vger.kernel.org Fixes: c06ece6 ("drbd: Turn connection->volumes into connection->peer_devices") Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com> Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> Reviewed-by: Lars Ellenberg <lars.ellenberg@linbit.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aadb22b commit ae4d37b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/block/drbd/drbd_main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,12 +2773,12 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
27732773

27742774
if (init_submitter(device)) {
27752775
err = ERR_NOMEM;
2776-
goto out_idr_remove_vol;
2776+
goto out_idr_remove_from_resource;
27772777
}
27782778

27792779
err = add_disk(disk);
27802780
if (err)
2781-
goto out_idr_remove_vol;
2781+
goto out_idr_remove_from_resource;
27822782

27832783
/* inherit the connection state */
27842784
device->state.conn = first_connection(resource)->cstate;
@@ -2792,8 +2792,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
27922792
drbd_debugfs_device_add(device);
27932793
return NO_ERROR;
27942794

2795-
out_idr_remove_vol:
2796-
idr_remove(&connection->peer_devices, vnr);
27972795
out_idr_remove_from_resource:
27982796
for_each_connection(connection, resource) {
27992797
peer_device = idr_remove(&connection->peer_devices, vnr);

0 commit comments

Comments
 (0)