Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH] cfg80211: annotate cfg80211_inform_bss
@ 2011-10-27 12:45 Johannes Berg
  2011-10-27 19:40 ` Bing Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Johannes Berg @ 2011-10-27 12:45 UTC (permalink / raw)
  To: John Linville
  Cc: linux-wireless, Samuel Ortiz, Bing Zhao, Jussi Kivilinna,
	Dan Williams, Arend Van Spriel

From: Johannes Berg <johannes.berg@intel.com>

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.

Reported-by: Adam Mikuta <Adam.Mikuta@tieto.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
CC lots of driver maintainers who need to fix this bug.

 include/net/cfg80211.h |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/include/net/cfg80211.h	2011-10-27 14:05:17.000000000 +0200
+++ b/include/net/cfg80211.h	2011-10-27 14:42:51.000000000 +0200
@@ -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,



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

* RE: [PATCH] cfg80211: annotate cfg80211_inform_bss
  2011-10-27 12:45 [PATCH] cfg80211: annotate cfg80211_inform_bss Johannes Berg
@ 2011-10-27 19:40 ` Bing Zhao
  2011-10-28  5:05 ` [PATCH] rndis_wlan: release BSS structures returned by cfg80211_inform_bss() Jussi Kivilinna
  2011-10-28 10:00 ` [PATCH] orinoco: " David Kilroy
  2 siblings, 0 replies; 6+ messages in thread
From: Bing Zhao @ 2011-10-27 19:40 UTC (permalink / raw)
  To: Johannes Berg, John Linville
  Cc: linux-wireless, Samuel Ortiz, Jussi Kivilinna, Dan Williams,
	Arend Van Spriel

SGkgSm9oYW5uZXMsDQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogbGlu
dXgtd2lyZWxlc3Mtb3duZXJAdmdlci5rZXJuZWwub3JnIFttYWlsdG86bGludXgtd2lyZWxlc3Mt
b3duZXJAdmdlci5rZXJuZWwub3JnXSBPbiBCZWhhbGYgT2YNCj4gSm9oYW5uZXMgQmVyZw0KPiBT
ZW50OiBUaHVyc2RheSwgT2N0b2JlciAyNywgMjAxMSA1OjQ1IEFNDQo+IFRvOiBKb2huIExpbnZp
bGxlDQo+IENjOiBsaW51eC13aXJlbGVzczsgU2FtdWVsIE9ydGl6OyBCaW5nIFpoYW87IEp1c3Np
IEtpdmlsaW5uYTsgRGFuIFdpbGxpYW1zOyBBcmVuZCBWYW4gU3ByaWVsDQo+IFN1YmplY3Q6IFtQ
QVRDSF0gY2ZnODAyMTE6IGFubm90YXRlIGNmZzgwMjExX2luZm9ybV9ic3MNCj4gDQo+IEZyb206
IEpvaGFubmVzIEJlcmcgPGpvaGFubmVzLmJlcmdAaW50ZWwuY29tPg0KPiANCj4gVGhpcyBmdW5j
dGlvbiByZXR1cm5zIGEgcmVmZXJlbmNlZCBCU1Mgc3RydWN0DQo+IChvciBOVUxMKSwgYW5ub3Rh
dGUgd2l0aCBfX211c3RfY2hlY2suIEl0IHNlZW1zDQo+IHRoYXQgYSBsb3Qgb2YgZHJpdmVycyBn
ZXQgd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1YnNjcmliZSBsaW51eC13aXJlbGVzcyIgaW4NCj4gdGhlIGJvZHkg
b2YgYSBtZXNzYWdlIHRvIG1ham9yZG9tb0B2Z2VyLmtlcm5lbC5vcmcNCj4gTW9yZSBtYWpvcmRv
bW8gaW5mbyBhdCAgaHR0cDovL3ZnZXIua2VybmVsLm9yZy9tYWpvcmRvbW8taW5mby5odG1sDQo=

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

* [PATCH] rndis_wlan: release BSS structures returned by cfg80211_inform_bss()
  2011-10-27 12:45 [PATCH] cfg80211: annotate cfg80211_inform_bss Johannes Berg
  2011-10-27 19:40 ` Bing Zhao
@ 2011-10-28  5:05 ` Jussi Kivilinna
  2011-10-28 10:00 ` [PATCH] orinoco: " David Kilroy
  2 siblings, 0 replies; 6+ messages in thread
From: Jussi Kivilinna @ 2011-10-28  5:05 UTC (permalink / raw)
  To: linux-wireless; +Cc: Johannes Berg, John W. Linville

Patch fixes rndis_wlan to release referenced BSS structure returned by
cfg80211_inform_bss().

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
---
 drivers/net/wireless/rndis_wlan.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 15464d5..9cc4b8c 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -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);
 }
 
 /*


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

* [PATCH] orinoco: release BSS structures returned by cfg80211_inform_bss()
  2011-10-27 12:45 [PATCH] cfg80211: annotate cfg80211_inform_bss Johannes Berg
  2011-10-27 19:40 ` Bing Zhao
  2011-10-28  5:05 ` [PATCH] rndis_wlan: release BSS structures returned by cfg80211_inform_bss() Jussi Kivilinna
@ 2011-10-28 10:00 ` David Kilroy
  2011-10-28 10:09   ` Johannes Berg
  2 siblings, 1 reply; 6+ messages in thread
From: David Kilroy @ 2011-10-28 10:00 UTC (permalink / raw)
  To: linux-wireless, linville, johannes; +Cc: David Kilroy

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.

Signed-off-by: David Kilroy <kilroyd@googlemail.com>
---
 drivers/net/wireless/orinoco/scan.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/orinoco/scan.c b/drivers/net/wireless/orinoco/scan.c
index e99ca1c..93674d9 100644
--- a/drivers/net/wireless/orinoco/scan.c
+++ b/drivers/net/wireless/orinoco/scan.c
@@ -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,
-- 
1.7.4.1


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

* Re: [PATCH] orinoco: release BSS structures returned by cfg80211_inform_bss()
  2011-10-28 10:00 ` [PATCH] orinoco: " David Kilroy
@ 2011-10-28 10:09   ` Johannes Berg
  2011-10-28 11:47     ` [PATCH v2] " David Kilroy
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2011-10-28 10:09 UTC (permalink / raw)
  To: David Kilroy; +Cc: linux-wireless, linville

On Fri, 2011-10-28 at 11:00 +0100, David Kilroy wrote:
> 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.

Thanks!


> +	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


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

* [PATCH v2] orinoco: release BSS structures returned by cfg80211_inform_bss()
  2011-10-28 10:09   ` Johannes Berg
@ 2011-10-28 11:47     ` David Kilroy
  0 siblings, 0 replies; 6+ messages in thread
From: David Kilroy @ 2011-10-28 11:47 UTC (permalink / raw)
  To: linux-wireless, linville, johannes; +Cc: David Kilroy

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.

Signed-off-by: David Kilroy <kilroyd@googlemail.com>
---
v2: Avoid unnecessary NULL checks
---
 drivers/net/wireless/orinoco/scan.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/orinoco/scan.c b/drivers/net/wireless/orinoco/scan.c
index e99ca1c..96e39ed 100644
--- a/drivers/net/wireless/orinoco/scan.c
+++ b/drivers/net/wireless/orinoco/scan.c
@@ -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,
-- 
1.7.4.1


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

end of thread, other threads:[~2011-10-28 11:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-27 12:45 [PATCH] cfg80211: annotate cfg80211_inform_bss Johannes Berg
2011-10-27 19:40 ` Bing Zhao
2011-10-28  5:05 ` [PATCH] rndis_wlan: release BSS structures returned by cfg80211_inform_bss() Jussi Kivilinna
2011-10-28 10:00 ` [PATCH] orinoco: " David Kilroy
2011-10-28 10:09   ` Johannes Berg
2011-10-28 11:47     ` [PATCH v2] " David Kilroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox