]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
drbd: fix an invalid memory access caused by incorrect use of list iterator
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Wed, 6 Apr 2022 19:04:44 +0000 (21:04 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 16 Sep 2022 08:52:11 +0000 (10:52 +0200)
commitb9a291e8258f5d02d9ea0b56b2b8cc9b949a0a1c
treed1f8427e468b552d2ef12fc0874ab4a77bbb7893
parent9371ebeb5a6c899fa53efbc4d791c1840d2c331a
drbd: fix an invalid memory access caused by incorrect use of list iterator

BugLink: https://bugs.launchpad.net/bugs/1987451
[ Upstream commit ae4d37b5df749926891583d42a6801b5da11e3c1 ]

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: c06ece6ba6f1b ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/block/drbd/drbd_main.c