Skip to content

Commit 20c7840

Browse files
mjruhldledford
authored andcommitted
IB/core: If the MGID/MLID pair is not on the list return an error
A list of MGID/MLID pairs is built when doing a multicast attach. When the multicast detach is called, the list is searched, and regardless of the search outcome, the driver detach is called. If an MGID/MLID pair is not on the list, driver detach should not be called, and an error should be returned. Calling the driver without removing an MGID/MLID pair from the list can leave the core and driver out of sync. Fixes: f4e4015 ("IB/uverbs: track multicast group membership for userspace QPs") Cc: [email protected] Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Michael J. Ruhl <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 2443c6c commit 20c7840

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,6 +2658,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
26582658
struct ib_qp *qp;
26592659
struct ib_uverbs_mcast_entry *mcast;
26602660
int ret = -EINVAL;
2661+
bool found = false;
26612662

26622663
if (copy_from_user(&cmd, buf, sizeof cmd))
26632664
return -EFAULT;
@@ -2669,18 +2670,22 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
26692670
obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
26702671
mutex_lock(&obj->mcast_lock);
26712672

2672-
ret = ib_detach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
2673-
if (ret)
2674-
goto out_put;
2675-
26762673
list_for_each_entry(mcast, &obj->mcast_list, list)
26772674
if (cmd.mlid == mcast->lid &&
26782675
!memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
26792676
list_del(&mcast->list);
26802677
kfree(mcast);
2678+
found = true;
26812679
break;
26822680
}
26832681

2682+
if (!found) {
2683+
ret = -EINVAL;
2684+
goto out_put;
2685+
}
2686+
2687+
ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2688+
26842689
out_put:
26852690
mutex_unlock(&obj->mcast_lock);
26862691
uobj_put_obj_read(qp);

0 commit comments

Comments
 (0)