Skip to contentSkip to conversation

infiniband: cxgb4: fix a potential NULL pointer dereference

PATCH In review Kangjie Lu 5 participants 9 messages Mar 9, 2019 – Mar 28, 2019

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 infiniband: cxgb4: fix a potential NULL pointer dereference

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

---
 drivers/infiniband/hw/cxgb4/cm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +3 -0
index 8221813219e5..502a54d57e2c 100644
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
 	req = __skb_put_zero(skb, sizeof(*req));
 	req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
 	req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 17 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

---
drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +0 -0
index 8221813219e5..502a54d57e2c 100644

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 6 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Quoted 6 lines
drivers/infiniband/hw/cxgb4/cm.c +0 -0
 	req = __skb_put_zero(skb, sizeof(*req));
 	req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
 	req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Signature · 1 line
2.17.1
#2 lore raw
Quoted 16 lines · Kangjie Lu
Quoted 16 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

---
drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +0 -0
index 8221813219e5..502a54d57e2c 100644
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
Quoted 6 lines

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 4 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Hi Kangjie,

Please change the patch description to the imperative mood (see also https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/SubmittingPatches). A good way to invite feedback is to add a relevant Cc-list to a patch. The output of scripts/get_maintainer.pl can be a good start.

Bart.

#3 lore raw
In reply to Kangjie Lu
Quoted 19 lines · Kangjie Lu
Quoted 19 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

---
drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +0 -0
index 8221813219e5..502a54d57e2c 100644
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
Quoted 6 lines

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 4 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Sorry for the late response.
I recommend an error print before the return.
---

if (!skb) {
	pr_err("%s - failed to alloc skb\n", __func__);
	return -ENOMEM;
}

---
Thanks for the patch!
- Bharat.

Quoted 8 lines
Quoted 7 lines
drivers/infiniband/hw/cxgb4/cm.c +0 -0
 	req = __skb_put_zero(skb, sizeof(*req));
 	req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
 	req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Signature · 1 line
2.17.1
#4 lore raw
Quoted 25 lines · Potnuri Bharat Teja
Quoted 17 lines · Kangjie Lu
Quoted 17 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +1 -0
index 8221813219e5..502a54d57e2c 100644
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
Quoted 6 lines

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 4 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Quoted 6 lines

Sorry for the late response.
I recommend an error print before the return.

if (!skb) {
	pr_err("%s - failed to alloc skb\n", __func__);
	return -ENOMEM;
}

no error prints on memory allocation failure, the kernel already prints enough on this

Jason

maintainer Acked-by
#5 lore raw
Quoted 33 lines · Jason Gunthorpe
Quoted 25 lines · Potnuri Bharat Teja
Quoted 17 lines · Kangjie Lu
Quoted 17 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +1 -0
index 8221813219e5..502a54d57e2c 100644
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
Quoted 6 lines

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 4 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Quoted 6 lines

Sorry for the late response.
I recommend an error print before the return.

if (!skb) {
	pr_err("%s - failed to alloc skb\n", __func__);
	return -ENOMEM;
}
Quoted 2 lines

no error prints on memory allocation failure, the kernel already prints enough on this

Ok.

#6 lore raw
Quoted 34 lines · Potnuri Bharat Teja
Quoted 33 lines · Jason Gunthorpe
Quoted 31 lines · Potnuri Bharat Teja
Quoted 17 lines · Kangjie Lu
Quoted 17 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

drivers/infiniband/hw/cxgb4/cm.c | 3 +++

1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +1 -0
index 8221813219e5..502a54d57e2c 100644
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
 	int win;
 
Quoted 6 lines

drivers/infiniband/hw/cxgb4/cm.c static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid) · line 1924

Quoted 4 lines
drivers/infiniband/hw/cxgb4/cm.c +3 -0
 	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+

Can someone review this patch? Thanks.

Sorry for the late response.
I recommend an error print before the return.

if (!skb) {
	pr_err("%s - failed to alloc skb\n", __func__);
	return -ENOMEM;
}
Quoted 5 lines
Quoted 2 lines

no error prints on memory allocation failure, the kernel already prints enough on this

Ok.

It needs to be resent with Bart's comment addressed, and all the tags collected.

Jason

Reviewed-by on v1 1/1
#7 lore raw
In reply to Kangjie Lu
Quoted 4 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

Quoted 18 lines
---
  drivers/infiniband/hw/cxgb4/cm.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +3 -0
index 8221813219e5..502a54d57e2c 100644
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
  	int win;
 
  	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
  	req = __skb_put_zero(skb, sizeof(*req));
  	req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
  	req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Reviewed-by on v1 1/1
#8 lore raw
In reply to Kangjie Lu
Quoted 4 lines · Kangjie Lu

get_skb may fail and return NULL. The fix returns "ENOMEM" when it fails to avoid NULL dereference.

Quoted 18 lines
---
  drivers/infiniband/hw/cxgb4/cm.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/infiniband/hw/cxgb4/cm.c +3 -0
index 8221813219e5..502a54d57e2c 100644
@@ -1919,6 +1919,9 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
  	int win;
 
  	skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+	if (!skb)
+		return -ENOMEM;
+
  	req = __skb_put_zero(skb, sizeof(*req));
  	req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
  	req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));