linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi/bnx2fc/bnx2fx_fcore: Fix a double free in bnx2fc_rcv
@ 2021-03-28  8:16 Lv Yunlong
  0 siblings, 0 replies; 2+ messages in thread
From: Lv Yunlong @ 2021-03-28  8:16 UTC (permalink / raw)
  To: skashyap, jhasan, GR-QLogic-Storage-Upstream, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, Lv Yunlong

In bnx2fc_rcv, it calls skb_share_check(skb,GFP_ATOMIC) to clone
the skb. But if skb_clone() failed, skb_share_check() will free
the skb in the first time and return NULL. Then skb_share_check()
returns NULL and goto err.

Unfortunately, the same skb is freed in the second time in err.

I think moving skb = tmp_skb in front of if(!tmp_err) goto err
is a good solution, because freeing a NULL skb is safe.

Fixes: 01a4cc4d0cd6a ("bnx2fc: do not add shared skbs to the fcoe_rx_list")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 16bb6d2f98de..2e213d336ebe 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -445,11 +445,11 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
 	}
 
 	tmp_skb = skb_share_check(skb, GFP_ATOMIC);
+	skb = tmp_skb;
+
 	if (!tmp_skb)
 		goto err;
 
-	skb = tmp_skb;
-
 	if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
 		printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
 		goto err;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] scsi/bnx2fc/bnx2fx_fcore: Fix a double free in bnx2fc_rcv
@ 2021-05-24 10:23 Lv Yunlong
  0 siblings, 0 replies; 2+ messages in thread
From: Lv Yunlong @ 2021-05-24 10:23 UTC (permalink / raw)
  To: skashyap, jhasan, GR-QLogic-Storage-Upstream, jejb,
	martin.petersen, mlombard
  Cc: linux-scsi, linux-kernel, Lv Yunlong

In bnx2fc_rcv, it calls skb_share_check(skb,GFP_ATOMIC) to clone
the skb. But if skb_clone() failed, skb_share_check() will free
the skb in the first time and return NULL. Then skb_share_check()
returns NULL and goto err.

Unfortunately, the same skb is freed in the second time in the err.

As kfree_skb() free a null pointer is a safe operation, my patch
put "skb = tmp_skb;" ahead of the "if(!tmp_skb) goto err;". So that
if skb_share_check() failed, skb will be a null pointer.

Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 8863a74e6c57..89c277cb93b2 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -445,11 +445,10 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
 	}
 
 	tmp_skb = skb_share_check(skb, GFP_ATOMIC);
+	skb = tmp_skb;
 	if (!tmp_skb)
 		goto err;
 
-	skb = tmp_skb;
-
 	if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
 		printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
 		goto err;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-24 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28  8:16 [PATCH] scsi/bnx2fc/bnx2fx_fcore: Fix a double free in bnx2fc_rcv Lv Yunlong
2021-05-24 10:23 Lv Yunlong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).