Skip to contentSkip to conversation

infiniband: make sure the src net is infiniband when create new link

PATCH Applied Hangbin Liu 2 participants 2 messages Jan 3, 2014 – Jan 4, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 infiniband: make sure the src net is infiniband when create new link

When we create a new infiniband link with uninfiniband device, e.g. ip link add link em1 type ipoib pkey 0x8001. We will get a NULL pointer dereference cause other dev like Ethernet don't have struct ib_device.

The code path is:
rtnl_newlink
|-- ipoib_new_child_link

        |-- __ipoib_vlan_add
              |-- ipoib_set_dev_features
                    |-- ib_query_device

Fix this bug by make sure the src net is infiniband when create new link.

---
 drivers/infiniband/ulp/ipoib/ipoib_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/ulp/ipoib/ipoib_netlink.c +2 -1
index c29b5c8..cdc7df4 100644
@@ -31,6 +31,7 @@
  */
 
 #include <linux/netdevice.h>
+#include <linux/if_arp.h>      /* For ARPHRD_xxx */
 #include <linux/module.h>
 #include <net/rtnetlink.h>
 #include "ipoib.h"
@@ -103,7 +104,7 @@ static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
 		return -EINVAL;
 
 	pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
-	if (!pdev)
+	if (!pdev || pdev->type != ARPHRD_INFINIBAND)
 		return -ENODEV;
 
 	ppriv = netdev_priv(pdev);
Signature · 1 line
1.8.1.4
maintainer Applied
#1 lore raw

From: Hangbin Liu <[email protected]>
Date: Fri, 3 Jan 2014 11:33:45 +0800

Quoted 7 lines

When we create a new infiniband link with uninfiniband device, e.g. ip link add link em1 type ipoib pkey 0x8001. We will get a NULL pointer dereference cause other dev like Ethernet don't have struct ib_device.

The code path is:
rtnl_newlink
|-- ipoib_new_child_link

Quoted 7 lines
        |-- __ipoib_vlan_add
              |-- ipoib_set_dev_features
                    |-- ib_query_device

Fix this bug by make sure the src net is infiniband when create new link.

Applied, thank you.