提交 3699fa57 编写于 作者: D Dan Carpenter 提交者: openeuler-sync-bot

drbd: use after free in drbd_create_device()

stable inclusion
from stable-v5.10.156
commit 9ed51414aef6e59e832e2960f10766dce2d5b1a1
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7MCG1

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9ed51414aef6e59e832e2960f10766dce2d5b1a1

--------------------------------

[ Upstream commit a7a15981 ]

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

Fixes: b6f85ef9 ("drbd: Iterate over all connections")
Signed-off-by: NDan Carpenter <error27@gmail.com>
Reviewed-by: NChristoph Böhmwalder <christoph.boehmwalder@linbit.com>
Link: https://lore.kernel.org/r/Y3Jd5iZRbNQ9w6gm@kiliSigned-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: Nsanglipeng <sanglipeng1@jd.com>
(cherry picked from commit 7233425e)
上级 5767450d
...@@ -2720,7 +2720,7 @@ static int init_submitter(struct drbd_device *device) ...@@ -2720,7 +2720,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) 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_resource *resource = adm_ctx->resource;
struct drbd_connection *connection; struct drbd_connection *connection, *n;
struct drbd_device *device; struct drbd_device *device;
struct drbd_peer_device *peer_device, *tmp_peer_device; struct drbd_peer_device *peer_device, *tmp_peer_device;
struct gendisk *disk; struct gendisk *disk;
...@@ -2839,7 +2839,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig ...@@ -2839,7 +2839,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
out_idr_remove_vol: out_idr_remove_vol:
idr_remove(&connection->peer_devices, vnr); idr_remove(&connection->peer_devices, vnr);
out_idr_remove_from_resource: 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); peer_device = idr_remove(&connection->peer_devices, vnr);
if (peer_device) if (peer_device)
kref_put(&connection->kref, drbd_destroy_connection); kref_put(&connection->kref, drbd_destroy_connection);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册