Skip to content

Commit 153a2e4

Browse files
committed
RDMA/cm: Read id.state under lock when doing pr_debug()
The lock should not be dropped before doing the pr_debug() print as it is accessing data protected by the lock, such as id.state. Fixes: 119bf81 ("IB/cm: Add debug prints to ib_cm") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 98f6715 commit 153a2e4

File tree

1 file changed

+4
-4
lines changed
  • drivers/infiniband/core

1 file changed

+4
-4
lines changed

drivers/infiniband/core/cm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,13 +2394,13 @@ static int cm_rep_handler(struct cm_work *work)
23942394
case IB_CM_MRA_REQ_RCVD:
23952395
break;
23962396
default:
2397-
spin_unlock_irq(&cm_id_priv->lock);
23982397
ret = -EINVAL;
23992398
pr_debug(
24002399
"%s: cm_id_priv->id.state: %d, local_comm_id %d, remote_comm_id %d\n",
24012400
__func__, cm_id_priv->id.state,
24022401
IBA_GET(CM_REP_LOCAL_COMM_ID, rep_msg),
24032402
IBA_GET(CM_REP_REMOTE_COMM_ID, rep_msg));
2403+
spin_unlock_irq(&cm_id_priv->lock);
24042404
goto error;
24052405
}
24062406

@@ -2666,10 +2666,10 @@ int ib_send_cm_drep(struct ib_cm_id *cm_id,
26662666
cm_id_priv = container_of(cm_id, struct cm_id_private, id);
26672667
spin_lock_irqsave(&cm_id_priv->lock, flags);
26682668
if (cm_id->state != IB_CM_DREQ_RCVD) {
2669-
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2670-
kfree(data);
26712669
pr_debug("%s: local_id %d, cm_idcm_id->state(%d) != IB_CM_DREQ_RCVD\n",
26722670
__func__, be32_to_cpu(cm_id->local_id), cm_id->state);
2671+
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2672+
kfree(data);
26732673
return -EINVAL;
26742674
}
26752675

@@ -3005,10 +3005,10 @@ static int cm_rej_handler(struct cm_work *work)
30053005
}
30063006
/* fall through */
30073007
default:
3008-
spin_unlock_irq(&cm_id_priv->lock);
30093008
pr_debug("%s: local_id %d, cm_id_priv->id.state: %d\n",
30103009
__func__, be32_to_cpu(cm_id_priv->id.local_id),
30113010
cm_id_priv->id.state);
3011+
spin_unlock_irq(&cm_id_priv->lock);
30123012
ret = -EINVAL;
30133013
goto out;
30143014
}

0 commit comments

Comments
 (0)