Skip to content

Commit

Permalink
scsi: bnx2fc: Fix skb double free in bnx2fc_rcv()
Browse files Browse the repository at this point in the history
skb_share_check() already drops the reference to the skb when returning
NULL. Using kfree_skb() in the error handling path leads to an skb double
free.

Fix this by removing the variable tmp_skb, and return directly when
skb_share_check() returns NULL.

Fixes: 01a4cc4 ("bnx2fc: do not add shared skbs to the fcoe_rx_list")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Link: https://lore.kernel.org/r/20221114110626.526643-1-weiyongjun@huaweicloud.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
  • Loading branch information
Wei Yongjun authored and Martin K. Petersen committed Dec 19, 2023
1 parent 77a6725 commit 08c94d8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions drivers/scsi/bnx2fc/bnx2fc_fcoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
struct fcoe_ctlr *ctlr;
struct fcoe_rcv_info *fr;
struct fcoe_percpu_s *bg;
struct sk_buff *tmp_skb;

interface = container_of(ptype, struct bnx2fc_interface,
fcoe_packet_type);
Expand All @@ -441,11 +440,9 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
goto err;
}

tmp_skb = skb_share_check(skb, GFP_ATOMIC);
if (!tmp_skb)
goto err;

skb = tmp_skb;
skb = skb_share_check(skb, GFP_ATOMIC);
if (!skb)
return -1;

if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Expand Down

0 comments on commit 08c94d8

Please sign in to comment.