Skip to contentSkip to conversation

IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

PATCH Superseded Ralph Campbell 1 participant 1 message May 5, 2010 InfiniBand

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 IB/ipoib: fix dangling pointer references to ipoib_neigh and ipoib_path

Basically, a struct sk_buff has a pointer to a struct dst_entry which has a pointer to a struct neighbour. IPoIB uses
struct neighbour.ha to store the IB "hardware address" and a pointer to a struct ipoib_neigh. When using connected mode, struct ipoib_neigh has a pointer to struct ipoib_cm_tx which contains pointers back to struct ipoib_neigh and ipoib_path. The core network code will call ipoib_neigh_cleanup() when it is destroying struct neighbour and IPoIB should guarantee that the struct ipoib_neigh and all the memory it points to are destroyed. Also, the connected mode RC QP contains a pointer back to the struct ipoib_cm_tx which can be dereferenced in the CQ completion handler. The problem is that there are several places where the struct ipoib_cm_tx can be used after it has been freed. The easiest way to reproduce this bug is to run a UDP bandwidth test while loading/unloading the IPoIB module or ifup/ifdown the interface.
The fix is rather complex since the RC QP connection setup, tear down, and CQ completion draining are asynchronous processes. The struct ipoib_cm_tx goes through four "states":
1) created, flags==0, and linked on the priv->cm.start_list.
2) not on the start_list, flags==0, and in the process of creating the RC QP.
3) not on the start_list, flags & IPOIB_FLAG_INITIALIZED, and RC QP created.
4) on the priv->cm.reap_task list or being destroyed by ipoib_cm_tx_reap().

---

I updated the description to be more detailed.
I stripped out as much non-functional code changes as I could.

 drivers/infiniband/ulp/ipoib/ipoib.h           |   14 +
 drivers/infiniband/ulp/ipoib/ipoib_cm.c        |  108 +++++-----
 drivers/infiniband/ulp/ipoib/ipoib_main.c      |  259 +++++++++++-------------
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c |   76 ++-----
 4 files changed, 215 insertions(+), 242 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib.h +10 -4
index 753a983..5a842d7 100644
@@ -415,9 +415,7 @@ static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
 				     INFINIBAND_ALEN, sizeof(void *));
 }
 
-struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh,
-				      struct net_device *dev);
-void ipoib_neigh_free(struct net_device *dev, struct ipoib_neigh *neigh);
+void ipoib_neigh_flush(struct ipoib_neigh *neigh);
 
 extern struct workqueue_struct *ipoib_workqueue;
 
@@ -464,7 +462,8 @@ void ipoib_dev_cleanup(struct net_device *dev);
 
 void ipoib_mcast_join_task(struct work_struct *work);
 void ipoib_mcast_carrier_on_task(struct work_struct *work);
-void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb);
+void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb,
+		      struct ipoib_neigh *neigh);
 
 void ipoib_mcast_restart_task(struct work_struct *work);
 int ipoib_mcast_start_thread(struct net_device *dev);
@@ -570,6 +569,7 @@ void ipoib_cm_dev_cleanup(struct net_device *dev);
 struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
 				    struct ipoib_neigh *neigh);
 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
+void ipoib_cm_flush_path(struct net_device *dev, struct ipoib_path *path);
 void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
 			   unsigned int mtu);
 void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc);
@@ -659,6 +659,12 @@ void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
 }
 
 static inline
+void ipoib_cm_flush_path(struct net_device *dev, struct ipoib_path *path)
+{
+	return;
+}
+
+static inline
 int ipoib_cm_add_mode_attr(struct net_device *dev)
 {
 	return 0;
drivers/infiniband/ulp/ipoib/ipoib_cm.c +59 -49

163 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_main.c +124 -135

433 lines not on this page · raw message

drivers/infiniband/ulp/ipoib/ipoib_multicast.c +22 -54

124 lines not on this page · raw message

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html