Skip to content

Commit eb8df9a

Browse files
Wissam Shoukairmcb30
Wissam Shoukair
authored andcommittedAug 17, 2015
[ipoib] Fix a race when chain-loading undionly.kpxe in IPoIB
The Infiniband link status change callback ipoib_link_state_changed() may be called while the IPoIB device is closed, in which case there will not be an IPoIB queue pair to be joined to the IPv4 broadcast group. This leads to NULL pointer dereferences in ib_mcast_attach() and ib_mcast_detach(). Fix by not attempting to join (or leave) the broadcast group unless we actually have an IPoIB queue pair. Signed-off-by: Wissam Shoukair <wissams@mellanox.com> Modified-by: Michael Brown <mcb30@ipxe.org> Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent fd18417 commit eb8df9a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
 

‎src/drivers/net/ipoib.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ static void ipoib_link_state_changed ( struct ib_device *ibdev ) {
791791
int rc;
792792

793793
/* Leave existing broadcast group */
794-
ipoib_leave_broadcast_group ( ipoib );
794+
if ( ipoib->qp )
795+
ipoib_leave_broadcast_group ( ipoib );
795796

796797
/* Update MAC address based on potentially-new GID prefix */
797798
memcpy ( &ipoib->mac.gid.s.prefix, &ibdev->gid.s.prefix,
@@ -806,7 +807,7 @@ static void ipoib_link_state_changed ( struct ib_device *ibdev ) {
806807
netdev_link_err ( netdev, ( rc ? rc : -EINPROGRESS_JOINING ) );
807808

808809
/* Join new broadcast group */
809-
if ( ib_is_open ( ibdev ) && ib_link_ok ( ibdev ) &&
810+
if ( ib_is_open ( ibdev ) && ib_link_ok ( ibdev ) && ipoib->qp &&
810811
( ( rc = ipoib_join_broadcast_group ( ipoib ) ) != 0 ) ) {
811812
DBGC ( ipoib, "IPoIB %p could not rejoin broadcast group: "
812813
"%s\n", ipoib, strerror ( rc ) );
@@ -894,7 +895,9 @@ static void ipoib_close ( struct net_device *netdev ) {
894895

895896
/* Tear down the queues */
896897
ib_destroy_qp ( ibdev, ipoib->qp );
898+
ipoib->qp = NULL;
897899
ib_destroy_cq ( ibdev, ipoib->cq );
900+
ipoib->cq = NULL;
898901

899902
/* Close IB device */
900903
ib_close ( ibdev );

‎src/net/infiniband.c

+6
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@ int ib_mcast_attach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
718718
struct ib_multicast_gid *mgid;
719719
int rc;
720720

721+
/* Sanity check */
722+
assert ( qp != NULL );
723+
721724
/* Add to software multicast GID list */
722725
mgid = zalloc ( sizeof ( *mgid ) );
723726
if ( ! mgid ) {
@@ -751,6 +754,9 @@ void ib_mcast_detach ( struct ib_device *ibdev, struct ib_queue_pair *qp,
751754
union ib_gid *gid ) {
752755
struct ib_multicast_gid *mgid;
753756

757+
/* Sanity check */
758+
assert ( qp != NULL );
759+
754760
/* Remove from hardware multicast GID list */
755761
ibdev->op->mcast_detach ( ibdev, qp, gid );
756762

‎src/net/infiniband/ib_mcast.c

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ int ib_mcast_join ( struct ib_device *ibdev, struct ib_queue_pair *qp,
150150
DBGC ( ibdev, "IBDEV %p QPN %lx joining " IB_GID_FMT "\n",
151151
ibdev, qp->qpn, IB_GID_ARGS ( gid ) );
152152

153+
/* Sanity check */
154+
assert ( qp != NULL );
155+
153156
/* Initialise structure */
154157
membership->qp = qp;
155158
memcpy ( &membership->gid, gid, sizeof ( membership->gid ) );
@@ -199,6 +202,9 @@ void ib_mcast_leave ( struct ib_device *ibdev, struct ib_queue_pair *qp,
199202
DBGC ( ibdev, "IBDEV %p QPN %lx leaving " IB_GID_FMT "\n",
200203
ibdev, qp->qpn, IB_GID_ARGS ( gid ) );
201204

205+
/* Sanity check */
206+
assert ( qp != NULL );
207+
202208
/* Detach from multicast GID */
203209
ib_mcast_detach ( ibdev, qp, &membership->gid );
204210

0 commit comments

Comments
 (0)
Please sign in to comment.