cfg80211: annotate cfg80211_inform_bss
Johannes Berg
maintainerPATCH 1/1 cfg80211: annotate cfg80211_inform_bss
From: Johannes Berg <[email protected]>
This function returns a referenced BSS struct (or NULL), annotate with __must_check. It seems that a lot of drivers get this completely wrong and leak all BSS structs as a result.
---
CC lots of driver maintainers who need to fix this bug.
include/net/cfg80211.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
include/net/cfg80211.h +6 -2
@@ -2651,8 +2651,10 @@ void cfg80211_sched_scan_stopped(struct* * This informs cfg80211 that BSS information was found and * the BSS should be updated/added. +* +* NOTE: Returns a referenced struct, must be released with cfg80211_put_bss()! */ -struct cfg80211_bss * +struct cfg80211_bss *__must_check cfg80211_inform_bss_frame(struct wiphy *wiphy, struct ieee80211_channel *channel, struct ieee80211_mgmt *mgmt, size_t len,
@@ -2674,8 +2676,10 @@ cfg80211_inform_bss_frame(struct wiphy ** * This informs cfg80211 that BSS information was found and * the BSS should be updated/added. +* +* NOTE: Returns a referenced struct, must be released with cfg80211_put_bss()! */ -struct cfg80211_bss * +struct cfg80211_bss *__must_check cfg80211_inform_bss(struct wiphy *wiphy, struct ieee80211_channel *channel, const u8 *bssid,
SGkgSm9oYW5uZXMsDQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogbGlu dXgtd2lyZWxlc3Mtb3duZXJAdmdlci5rZXJuZWwub3JnIFttYWlsdG86bGludXgtd2lyZWxlc3Mt b3duZXJAdmdlci5rZXJuZWwub3JnXSBPbiBCZWhhbGYgT2YNCj4gSm9oYW5uZXMgQmVyZw0KPiBT ZW50OiBUaHVyc2RheSwgT2N0b2JlciAyNywgMjAxMSA1OjQ1IEFNDQo+IFRvOiBKb2huIExpbnZp bGxlDQo+IENjOiBsaW51eC13aXJlbGVzczsgU2FtdWVsIE9ydGl6OyBCaW5nIFpoYW87IEp1c3Np IEtpdmlsaW5uYTsgRGFuIFdpbGxpYW1zOyBBcmVuZCBWYW4gU3Bya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TFfYnNzKg0KPiArc3RydWN0IGNmZzgwMjExX2JzcyAqIF9fbXVzdF9j aGVjaw0KPiAgY2ZnODAyMTFfaW5mb3JtX2JzcyhzdHJ1Y3Qgd2lwaHkgKndpcGh5LA0KPiAgCQkg ICAgc3RydWN0IGllZWU4MDIxMV9jaGFubmVsICpjaGFubmVsLA0KPiAgCQkgICAgY29uc3QgdTgg KmJzc2lkLA0KPiANCj4gDQo+IC0tDQo+IFRvIHVuc3Vic2NyaWJlIGZyb20gdGhpcyBsaXN0OiBz ZW5kIHRoZSBsaW5lICJ1bnN1YnNjcmliZSBsaW51eC13aXJlbGVzcyIgaW4NCj4gdGhlIGJvZHkg b2YgYSBtZXNzYWdlIHRvIG1ham9yZG9tb0B2Z2VyLmtlcm5lbC5vcmcNCj4gTW9yZSBtYWpvcmRv bW8gaW5mbyBhdCAgaHR0cDovL3ZnZXIua2VybmVsLm9yZy9tYWpvcmRvbW8taW5mby5odG1sDQo=
PATCH 1/1 rndis_wlan: release BSS structures returned by cfg80211_inform_bss()
In reply to Johannes BergPatch fixes rndis_wlan to release referenced BSS structure returned by cfg80211_inform_bss().
--- drivers/net/wireless/rndis_wlan.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/net/wireless/rndis_wlan.c +10 -4
@@ -1972,11 +1972,12 @@ static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,return ret; } -static struct cfg80211_bss *rndis_bss_info_update (struct usbnet *usbdev, -struct ndis_80211_bssid_ex *bssid) +static bool rndis_bss_info_update (struct usbnet *usbdev, +struct ndis_80211_bssid_ex *bssid) {struct rndis_wlan_private *priv =get_rndis_wlan_priv (usbdev);struct ieee80211_channel *channel; +struct cfg80211_bss *bss;s32 signal;u64 timestamp;u16 capability;
@@ -2015,9 +2016,12 @@ static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev, capability =le16_to_cpu (fixed->capabilities); beacon_interval =le16_to_cpu (fixed->beacon_interval); -return cfg80211_inform_bss (priv->wdev.wiphy, channel, bssid->mac, + bss =cfg80211_inform_bss (priv->wdev.wiphy, channel, bssid->mac, timestamp, capability, beacon_interval, ie, ie_len, signal,GFP_KERNEL ); +cfg80211_put_bss (bss); + +return (bss !=NULL ); } static struct ndis_80211_bssid_ex *next_bssid_list_item(
@@ -2641,6 +2645,7 @@ static void rndis_wlan_craft_connected_bss(struct usbnet *usbdev, u8 *bssid,struct ieee80211_channel *channel;struct ndis_80211_conf config;struct ndis_80211_ssid ssid; +struct cfg80211_bss *bss;s32 signal;u64 timestamp;u16 capability;
@@ -2714,9 +2719,10 @@ static void rndis_wlan_craft_connected_bss(struct usbnet *usbdev, u8 *bssid, bssid, (u32 )timestamp, capability, beacon_interval, ie_len, ssid.essid, signal); -cfg80211_inform_bss (priv->wdev.wiphy, channel, bssid, + bss =cfg80211_inform_bss (priv->wdev.wiphy, channel, bssid, timestamp, capability, beacon_interval, ie_buf, ie_len, signal,GFP_KERNEL ); +cfg80211_put_bss (bss); }/*
PATCH 1/1 orinoco: release BSS structures returned by cfg80211_inform_bss()
In reply to Johannes BergThe pointer returned by cfg80211_inform_bss is a referenced struct. The orinoco driver does not need to keep the struct, so we just release it.
--- drivers/net/wireless/orinoco/scan.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
drivers/net/wireless/orinoco/scan.c +12 -6
@@ -76,6 +76,7 @@ static void orinoco_add_hostscan_result(struct orinoco_private *priv, {struct wiphy *wiphy =priv_to_wiphy (priv);struct ieee80211_channel *channel; +struct cfg80211_bss *cbss;u8 *ie;u8 ie_buf[46 ];u64 timestamp;
@@ -121,9 +122,11 @@ static void orinoco_add_hostscan_result(struct orinoco_private *priv, beacon_interval =le16_to_cpu (bss->a.beacon_interv); signal =SIGNAL_TO_MBM (le16_to_cpu (bss->a.level)); -cfg80211_inform_bss (wiphy, channel, bss->a.bssid, timestamp, - capability, beacon_interval, ie_buf, ie_len, - signal,GFP_KERNEL ); + cbss =cfg80211_inform_bss (wiphy, channel, bss->a.bssid, timestamp, + capability, beacon_interval, ie_buf, ie_len, + signal,GFP_KERNEL ); +if (cbss) +cfg80211_put_bss (cbss); } void orinoco_add_extscan_result(struct orinoco_private *priv,
@@ -132,6 +135,7 @@ void orinoco_add_extscan_result(struct orinoco_private *priv, {struct wiphy *wiphy =priv_to_wiphy (priv);struct ieee80211_channel *channel; +struct cfg80211_bss *cbss;const u8 *ie;u64 timestamp;s32 signal;
@@ -152,9 +156,11 @@ void orinoco_add_extscan_result(struct orinoco_private *priv, ie = bss->data; signal =SIGNAL_TO_MBM (bss->level); -cfg80211_inform_bss (wiphy, channel, bss->bssid, timestamp, - capability, beacon_interval, ie, ie_len, - signal,GFP_KERNEL ); + cbss =cfg80211_inform_bss (wiphy, channel, bss->bssid, timestamp, + capability, beacon_interval, ie, ie_len, + signal,GFP_KERNEL ); +if (cbss) +cfg80211_put_bss (cbss); } void orinoco_add_hostscan_results(struct orinoco_private *priv,
Signature · 1 line
1.7.4.1
Johannes Berg
maintainerRe: [PATCH] orinoco: release BSS structures returned by cfg80211_inform_bss()
Quoted 3 lines · David Kilroy
The pointer returned by
cfg80211_inform_bssis a referenced struct. The orinoco driver does not need to keep the struct, so we just release it.
Thanks!
drivers/net/wireless/orinoco/scan.c static void orinoco_add_hostscan_result(struct orinoco_private *priv, · line 129
Quoted 5 lines
drivers/net/wireless/orinoco/scan.c +5
-0+ cbss =cfg80211_inform_bss (wiphy, channel, bss->a.bssid, timestamp, + capability, beacon_interval, ie_buf, ie_len, + signal,GFP_KERNEL ); +if (cbss) +cfg80211_put_bss (cbss);
Obviously doesn't hurt, but cfg80211_put_bss(NULL) is acceptable, if you'd prefer the code that way.
johannes
PATCH v2 1/1 orinoco: release BSS structures returned by cfg80211_inform_bss()
The pointer returned by cfg80211_inform_bss is a referenced struct. The orinoco driver does not need to keep the struct, so we just release it.
---
v2: Avoid unnecessary NULL checks
--- drivers/net/wireless/orinoco/scan.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/net/wireless/orinoco/scan.c +10 -6
@@ -76,6 +76,7 @@ static void orinoco_add_hostscan_result(struct orinoco_private *priv, {struct wiphy *wiphy =priv_to_wiphy (priv);struct ieee80211_channel *channel; +struct cfg80211_bss *cbss;u8 *ie;u8 ie_buf[46 ];u64 timestamp;
@@ -121,9 +122,10 @@ static void orinoco_add_hostscan_result(struct orinoco_private *priv, beacon_interval =le16_to_cpu (bss->a.beacon_interv); signal =SIGNAL_TO_MBM (le16_to_cpu (bss->a.level)); -cfg80211_inform_bss (wiphy, channel, bss->a.bssid, timestamp, - capability, beacon_interval, ie_buf, ie_len, - signal,GFP_KERNEL ); + cbss =cfg80211_inform_bss (wiphy, channel, bss->a.bssid, timestamp, + capability, beacon_interval, ie_buf, ie_len, + signal,GFP_KERNEL ); +cfg80211_put_bss (cbss); } void orinoco_add_extscan_result(struct orinoco_private *priv,
@@ -132,6 +134,7 @@ void orinoco_add_extscan_result(struct orinoco_private *priv, {struct wiphy *wiphy =priv_to_wiphy (priv);struct ieee80211_channel *channel; +struct cfg80211_bss *cbss;const u8 *ie;u64 timestamp;s32 signal;
@@ -152,9 +155,10 @@ void orinoco_add_extscan_result(struct orinoco_private *priv, ie = bss->data; signal =SIGNAL_TO_MBM (bss->level); -cfg80211_inform_bss (wiphy, channel, bss->bssid, timestamp, - capability, beacon_interval, ie, ie_len, - signal,GFP_KERNEL ); + cbss =cfg80211_inform_bss (wiphy, channel, bss->bssid, timestamp, + capability, beacon_interval, ie, ie_len, + signal,GFP_KERNEL ); +cfg80211_put_bss (cbss); } void orinoco_add_hostscan_results(struct orinoco_private *priv,
Signature · 1 line
1.7.4.1