ath11k: fix a double free and a memory leak
Subsystems (3)
PATCH 1/1 ath11k: fix a double free and a memory leak
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
mac.c:6204:2: warning: Attempt to free released memory
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The channels pointer is allocated in ath11k_mac_setup_channels_rates() When it fails midway, it cleans up the memory it has already allocated. So the error handling needs to skip freeing the memory.
There is a second problem. ath11k_mac_setup_channels_rates(), allocates 3 channels. err_free misses releasing ar->mac.sbands[NL80211_BAND_6GHZ].channels
--- drivers/net/wireless/ath/ath11k/mac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +3 -2
@@ -6089,7 +6089,7 @@ static int __ath11k_mac_register(struct ath11k *ar) ret =ath11k_mac_setup_channels_rates (ar, cap->supported_bands);if (ret) - goto err_free; + goto err;ath11k_mac_setup_ht_vht_cap (ar, cap, &ht_cap);ath11k_mac_setup_he_cap (ar, cap);
@@ -6203,7 +6203,8 @@ static int __ath11k_mac_register(struct ath11k *ar) err_free:kfree (ar->mac.sbands[NL80211_BAND_2GHZ ].channels);kfree (ar->mac.sbands[NL80211_BAND_5GHZ ].channels); - +kfree (ar->mac.sbands[NL80211_BAND_6GHZ ].channels); +err:SET_IEEE80211_DEV (ar->hw,NULL );return ret; }
Signature · 7 lines
2.18.1 -- ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Quoted 12 lines · On Sun, Sep 06, 2020 at 02:26:25PM -0700, [email protected] wrote:
From: Tom Rix <[email protected]>
clang static analyzer reports this problem
mac.c:6204:2: warning: Attempt to free released memory
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The channels pointer is allocated in
ath11k_mac_setup_channels_rates()When it fails midway, it cleans up the memory it has already allocated. So the error handling needs to skip freeing the memory.
Quoted 6 lines
There is a second problem.
ath11k_mac_setup_channels_rates(), allocates 3 channels.err_freemisses releasing ar->mac.sbands[NL80211_BAND_6GHZ].channelsFixes d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")Signed-off-by Tom Rix <[email protected]>
Quoted 30 lines
--- drivers/net/wireless/ath/ath11k/mac.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/net/wireless/ath/ath11k/mac.c +3
-2@@ -6089,7 +6089,7 @@ static int __ath11k_mac_register(struct ath11k *ar) ret =ath11k_mac_setup_channels_rates (ar, cap->supported_bands);if (ret) - goto err_free; + goto err;ath11k_mac_setup_ht_vht_cap (ar, cap, &ht_cap);ath11k_mac_setup_he_cap (ar, cap);@@ -6203,7 +6203,8 @@ static int __ath11k_mac_register(struct ath11k *ar) err_free:kfree (ar->mac.sbands[NL80211_BAND_2GHZ ].channels);kfree (ar->mac.sbands[NL80211_BAND_5GHZ ].channels); - +kfree (ar->mac.sbands[NL80211_BAND_6GHZ ].channels); +err:SET_IEEE80211_DEV (ar->hw,NULL );return ret; }Signature · 1 line
2.18.1
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Quoted 10 lines · [email protected] wrote:
clang static analyzer reports this problem
mac.c:6204:2: warning: Attempt to free released memory
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The channels pointer is allocated in
ath11k_mac_setup_channels_rates()When it fails midway, it cleans up the memory it has already allocated. So the error handling needs to skip freeing the memory.
Quoted 7 lines
There is a second problem.
ath11k_mac_setup_channels_rates(), allocates 3 channels.err_freemisses releasing ar->mac.sbands[NL80211_BAND_6GHZ].channelsFixes d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")Signed-off-by Tom Rix <[email protected]>Signed-off-by Kalle Valo <[email protected]>
Patch applied to ath-next branch of ath.git, thanks.
7e8453e35e40 ath11k: fix a double free and a memory leak
Signature · 9 lines
https://patchwork.kernel.org/patch/11759745/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches -- ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Quoted 10 lines · [email protected] wrote:
clang static analyzer reports this problem
mac.c:6204:2: warning: Attempt to free released memory
kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The channels pointer is allocated in
ath11k_mac_setup_channels_rates()When it fails midway, it cleans up the memory it has already allocated. So the error handling needs to skip freeing the memory.
Quoted 7 lines
There is a second problem.
ath11k_mac_setup_channels_rates(), allocates 3 channels.err_freemisses releasing ar->mac.sbands[NL80211_BAND_6GHZ].channelsFixes d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")Signed-off-by Tom Rix <[email protected]>Signed-off-by Kalle Valo <[email protected]>
Patch applied to ath-next branch of ath.git, thanks.
7e8453e35e40 ath11k: fix a double free and a memory leak
Signature · 3 lines
https://patchwork.kernel.org/patch/11759745/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches