netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 076/106] rtlwifi: Fix a double free in _rtl_usb_tx_urb_setup()
Date: Mon,  8 Jun 2020 19:22:08 -0400	[thread overview]
Message-ID: <20200608232238.3368589-76-sashal@kernel.org> (raw)
In-Reply-To: <20200608232238.3368589-1-sashal@kernel.org>

From: Dan Carpenter <dan.carpenter@oracle.com>

[ Upstream commit beb12813bc75d4a23de43b85ad1c7cb28d27631e ]

Seven years ago we tried to fix a leak but actually introduced a double
free instead.  It was an understandable mistake because the code was a
bit confusing and the free was done in the wrong place.  The "skb"
pointer is freed in both _rtl_usb_tx_urb_setup() and _rtl_usb_transmit().
The free belongs _rtl_usb_transmit() instead of _rtl_usb_tx_urb_setup()
and I've cleaned the code up a bit to hopefully make it more clear.

Fixes: 36ef0b473fbf ("rtlwifi: usb: add missing freeing of skbuff")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200513093951.GD347693@mwanda
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/usb.c b/drivers/net/wireless/realtek/rtlwifi/usb.c
index 1181b725f503..1893640555c1 100644
--- a/drivers/net/wireless/realtek/rtlwifi/usb.c
+++ b/drivers/net/wireless/realtek/rtlwifi/usb.c
@@ -910,10 +910,8 @@ static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw,
 
 	WARN_ON(NULL == skb);
 	_urb = usb_alloc_urb(0, GFP_ATOMIC);
-	if (!_urb) {
-		kfree_skb(skb);
+	if (!_urb)
 		return NULL;
-	}
 	_rtl_install_trx_info(rtlusb, skb, ep_num);
 	usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev,
 			  ep_num), skb->data, skb->len, _rtl_tx_complete, skb);
@@ -927,7 +925,6 @@ static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
 	u32 ep_num;
 	struct urb *_urb = NULL;
-	struct sk_buff *_skb = NULL;
 
 	WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl);
 	if (unlikely(IS_USB_STOP(rtlusb))) {
@@ -936,8 +933,7 @@ static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
 		return;
 	}
 	ep_num = rtlusb->ep_map.ep_mapping[qnum];
-	_skb = skb;
-	_urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num);
+	_urb = _rtl_usb_tx_urb_setup(hw, skb, ep_num);
 	if (unlikely(!_urb)) {
 		pr_err("Can't allocate urb. Drop skb!\n");
 		kfree_skb(skb);
-- 
2.25.1


  parent reply	other threads:[~2020-06-08 23:53 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08 23:20 [PATCH AUTOSEL 4.19 001/106] ath9x: Fix stack-out-of-bounds Write in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:20 ` [PATCH AUTOSEL 4.19 002/106] ath9k: Fix use-after-free Write in ath9k_htc_rx_msg Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 008/106] net: atlantic: make hw_get_regs optional Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 009/106] net: ena: fix error returning in ena_com_get_hash_function() Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 015/106] ixgbe: Fix XDP redirect on archs with PAGE_SIZE above 4K Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 017/106] Bluetooth: Add SCO fallback for invalid LMP parameters error Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 025/106] batman-adv: Revert "disable ethtool link speed detection when auto negotiation off" Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 029/106] net: vmxnet3: fix possible buffer overflow caused by bad DMA value in vmxnet3_get_rss() Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 031/106] ath9k: Fix use-after-free Read in ath9k_wmi_ctrl_rx Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 032/106] ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 033/106] brcmfmac: fix wrong location to get firmware feature Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 035/106] e1000: Distribute switch variables for initialization Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 043/106] netfilter: nft_nat: return EOPNOTSUPP if type or flags are not supported Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 044/106] selftests/bpf: Fix memory leak in extract_build_id() Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 045/106] net: bcmgenet: set Rx mode before starting netif Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 051/106] net: lpc-enet: fix error return code in lpc_mii_init() Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 053/106] net: allwinner: Fix use correct return type for ndo_start_xmit() Sasha Levin
2020-06-08 23:21 ` [PATCH AUTOSEL 4.19 055/106] ath9k_htc: Silence undersized packet warnings Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 068/106] ath10k: Remove msdu from idr when management pkt send fails Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 069/106] wcn36xx: Fix error handling path in 'wcn36xx_probe()' Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 070/106] net: qed*: Reduce RX and TX default ring count when running inside kdump kernel Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 071/106] mt76: avoid rx reorder buffer overflow Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 073/106] net: dsa: mt7530: set CPU port to fallback mode Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 074/106] veth: Adjust hard_start offset on redirect XDP frames Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 075/106] net/mlx5e: IPoIB, Drop multicast packets that this interface sent Sasha Levin
2020-06-08 23:22 ` Sasha Levin [this message]
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 077/106] mwifiex: Fix memory corruption in dump_station Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 087/106] net: ethernet: fec: move GPR register offset and bit into DT Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 088/106] macvlan: Skip loopback packets in RX handler Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 097/106] ixgbe: fix signed-integer-overflow warning Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 104/106] vxlan: Avoid infinite loop when suppressing NS messages with invalid options Sasha Levin
2020-06-08 23:22 ` [PATCH AUTOSEL 4.19 105/106] net_failover: fixed rollback in net_failover_open() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200608232238.3368589-76-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dan.carpenter@oracle.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).