Skip to content

Commit f48b726

Browse files
matanb10dledford
authored andcommitted
IB/core: Add lock to multicast handlers
When two handlers used the same object in the old schema, we blocked the process in the kernel. The new schema just returns -EBUSY. This could lead to different behaviour in applications between the old schema and the new schema. In most cases, using such handlers concurrently could lead to crashing the process. For example, if thread A destroys a QP and thread B modifies it, we could have the destruction happens before the modification. In this case, we are accessing freed memory which could lead to crashing the process. This is true for most cases. However, attaching and detaching a multicast address from QP concurrently is safe. Therefore, we preserve the original behaviour by adding a lock there. Signed-off-by: Matan Barak <matanb@mellanox.com> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent fd3c790 commit f48b726

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎drivers/infiniband/core/uverbs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ struct ib_usrq_object {
163163

164164
struct ib_uqp_object {
165165
struct ib_uevent_object uevent;
166+
/* lock for mcast list */
167+
struct mutex mcast_lock;
166168
struct list_head mcast_list;
167169
struct ib_uxrcd_object *uxrcd;
168170
};

‎drivers/infiniband/core/uverbs_cmd.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ static int create_qp(struct ib_uverbs_file *file,
13521352
return PTR_ERR(obj);
13531353
obj->uxrcd = NULL;
13541354
obj->uevent.uobject.user_handle = cmd->user_handle;
1355+
mutex_init(&obj->mcast_lock);
13551356

13561357
if (cmd_sz >= offsetof(typeof(*cmd), rwq_ind_tbl_handle) +
13571358
sizeof(cmd->rwq_ind_tbl_handle) &&
@@ -2589,6 +2590,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
25892590

25902591
obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
25912592

2593+
mutex_lock(&obj->mcast_lock);
25922594
list_for_each_entry(mcast, &obj->mcast_list, list)
25932595
if (cmd.mlid == mcast->lid &&
25942596
!memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
@@ -2612,6 +2614,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
26122614
kfree(mcast);
26132615

26142616
out_put:
2617+
mutex_unlock(&obj->mcast_lock);
26152618
uobj_put_obj_read(qp);
26162619

26172620
return ret ? ret : in_len;
@@ -2636,6 +2639,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
26362639
return -EINVAL;
26372640

26382641
obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2642+
mutex_lock(&obj->mcast_lock);
26392643

26402644
ret = ib_detach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
26412645
if (ret)
@@ -2650,6 +2654,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
26502654
}
26512655

26522656
out_put:
2657+
mutex_unlock(&obj->mcast_lock);
26532658
uobj_put_obj_read(qp);
26542659
return ret ? ret : in_len;
26552660
}

0 commit comments

Comments
 (0)