Skip to contentSkip to conversation

infiniband: hw: qedr: add null check before pointer dereference

PATCH Applied Gustavo A. R. Silva 4 participants 5 messages May 22, 2017 – Jun 1, 2017

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

PATCH 1/1 infiniband: hw: qedr: add null check before pointer dereference

Add null check before dereferencing pointer sgid_attr.ndev inside function rdma_vlan_dev_vlan_id().

Addresses-Coverity-ID: 1373979

---
 drivers/infiniband/hw/qedr/qedr_cm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/infiniband/hw/qedr/qedr_cm.c +6 -4
index 3d7705c..d86dbe8 100644
@@ -270,11 +270,13 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
 		return rc;
 	}
 
-	vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
-	if (vlan_id < VLAN_CFI_MASK)
-		has_vlan = true;
-	if (sgid_attr.ndev)
+	if (sgid_attr.ndev) {
+		vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
+		if (vlan_id < VLAN_CFI_MASK)
+			has_vlan = true;
+
 		dev_put(sgid_attr.ndev);
+	}
 
 	if (!memcmp(&sgid, &zgid, sizeof(sgid))) {
 		DP_ERR(dev, "gsi post send: GID not found GID index %d\n",
Signature · 1 line
2.5.0
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva

Add null check before dereferencing pointer sgid_attr.ndev inside function rdma_vlan_dev_vlan_id().

Addresses-Coverity-ID: 1373979

---
 drivers/infiniband/hw/qedr/qedr_cm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

+ Ram,

Ram, IB part of qedr driver doesn't exist in MAINTAINERS file.

Quoted 10 lines
drivers/infiniband/hw/qedr/qedr_cm.c +0 -1
index 3d7705c..d86dbe8 100644
@@ -270,11 +270,13 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
 		return rc;
 	}
 
-	vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);

drivers/infiniband/hw/qedr/qedr_cm.c static inline int qedr_gsi_build_header(struct qedr_dev *dev, · line 279

Quoted 10 lines
drivers/infiniband/hw/qedr/qedr_cm.c +6 -3
-	if (vlan_id < VLAN_CFI_MASK)
-		has_vlan = true;
-	if (sgid_attr.ndev)
+	if (sgid_attr.ndev) {
+		vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
+		if (vlan_id < VLAN_CFI_MASK)
+			has_vlan = true;
+
 		dev_put(sgid_attr.ndev);
+	}

I do agree that it is better than kernel panic trying to access NULL pointer, but I'm not sure that retaining default vlan_id = 0 is correct solution here.

Quoted 6 lines
drivers/infiniband/hw/qedr/qedr_cm.c +0 -1
 	if (!memcmp(&sgid, &zgid, sizeof(sgid))) {
 		DP_ERR(dev, "gsi post send: GID not found GID index %d\n",
--

2.5.0

Acked-by on v1 1/1
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 34 lines

Add null check before dereferencing pointer sgid_attr.ndev inside function rdma_vlan_dev_vlan_id().

Addresses-Coverity-ID: 1373979

---
 drivers/infiniband/hw/qedr/qedr_cm.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/infiniband/hw/qedr/qedr_cm.c +6 -5
index 3d7705c..d86dbe8 100644
@@ -270,11 +270,13 @@ static inline int qedr_gsi_build_header(struct qedr_dev *dev,
 		return rc;
 	}
 
-	vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
-	if (vlan_id < VLAN_CFI_MASK)
-		has_vlan = true;
-	if (sgid_attr.ndev)
+	if (sgid_attr.ndev) {
+		vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
+		if (vlan_id < VLAN_CFI_MASK)
+			has_vlan = true;
+
 		dev_put(sgid_attr.ndev);
+	}
 
 	if (!memcmp(&sgid, &zgid, sizeof(sgid))) {
 		DP_ERR(dev, "gsi post send: GID not found GID index %d\n",
--

2.5.0

Quoted 4 lines

--
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

Thanks.

Applied
#4 lore raw
In reply to Gustavo A. R. Silva
Quoted 6 lines · Gustavo A. R. Silva

Add null check before dereferencing pointer sgid_attr.ndev inside function rdma_vlan_dev_vlan_id().

Addresses-Coverity-ID: 1373979

---

Thanks, applied.

Signature · 9 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
   
Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

--
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