linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
       [not found]   ` <20180108100403.GA4715@light.dominikbrodowski.net>
@ 2018-01-14 18:03     ` Dominik Brodowski
  2018-01-14 21:58       ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Brodowski @ 2018-01-14 18:03 UTC (permalink / raw)
  To: johannes.berg; +Cc: regressions, netdev, linux-wireless, linux-kernel

As ieee80211_bss_get_ie() derefences an RCU, it needs to be called with
rcu_read_lock held.

Fixes: 44905265bc15 ("nl80211: don't expose wdev->ssid for most interfaces")
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
---

This patch fixes the regression I reported in the last couple of weeks for
various v4.15-rcX revisions to netdev, where a "suspicious RCU usage"
showed up in net/wireless/util.c:778.

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2b3dbcd40e46..1eecc249fb5e 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2618,8 +2618,10 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
 		const u8 *ssid_ie;
 		if (!wdev->current_bss)
 			break;
+		rcu_read_lock();
 		ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
 					       WLAN_EID_SSID);
+		rcu_read_unlock();
 		if (!ssid_ie)
 			break;
 		if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))

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

* Re: [PATCH] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
  2018-01-14 18:03     ` [PATCH] nl80211: take RCU read lock when calling ieee80211_bss_get_ie() Dominik Brodowski
@ 2018-01-14 21:58       ` Johannes Berg
  2018-01-14 22:22         ` [PATCH v2] " Dominik Brodowski
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2018-01-14 21:58 UTC (permalink / raw)
  To: Dominik Brodowski; +Cc: regressions, netdev, linux-wireless, linux-kernel

Hi,

> Fixes: 44905265bc15 ("nl80211: don't expose wdev->ssid for most interfaces")
> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
> ---
> 
> This patch fixes the regression I reported in the last couple of weeks for
> various v4.15-rcX revisions to netdev, where a "suspicious RCU usage"
> showed up in net/wireless/util.c:778.

Huh. You should added linux-wireless to those reports, I simply didn't
see them!

> diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
> index 2b3dbcd40e46..1eecc249fb5e 100644
> --- a/net/wireless/nl80211.c
> +++ b/net/wireless/nl80211.c
> @@ -2618,8 +2618,10 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
>  		const u8 *ssid_ie;
>  		if (!wdev->current_bss)
>  			break;
> +		rcu_read_lock();
>  		ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
>  					       WLAN_EID_SSID);
> +		rcu_read_unlock();
>  		if (!ssid_ie)
>  			break;
>  		if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))

This uses the ssid_ie, so that doesn't really seem right? The
protection should extend beyond the usage.

johannes

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

* [PATCH v2] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
  2018-01-14 21:58       ` Johannes Berg
@ 2018-01-14 22:22         ` Dominik Brodowski
  2018-01-14 22:40           ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Brodowski @ 2018-01-14 22:22 UTC (permalink / raw)
  To: Johannes Berg; +Cc: regressions, netdev, linux-wireless, linux-kernel

As ieee80211_bss_get_ie() derefences an RCU, it needs to be called with
rcu_read_lock held.

Fixes: 44905265bc15 ("nl80211: don't expose wdev->ssid for most interfaces")
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
---

> This uses the ssid_ie, so that doesn't really seem right? The
> protection should extend beyond the usage.

Indeed -- I had misread the code and hadn't thought of ssid_ie also needing
the protection during its lifetime. So here's a new version 2 -- which I
will only be able to test tomorrow, though...

Thanks,
	Dominik

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2b3dbcd40e46..b53bd8db7974 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2618,12 +2618,15 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
 		const u8 *ssid_ie;
 		if (!wdev->current_bss)
 			break;
+		rcu_read_lock();
 		ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
 					       WLAN_EID_SSID);
 		if (!ssid_ie)
-			break;
+			goto nla_rcu_unlock;
 		if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
-			goto nla_put_failure_locked;
+			goto nla_put_failure_rcu_locked;
+ nla_rcu_unlock:
+		rcu_read_unlock();
 		break;
 		}
 	default:
@@ -2635,6 +2638,8 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
 	genlmsg_end(msg, hdr);
 	return 0;
 
+ nla_put_failure_rcu_locked:
+	rcu_read_unlock();
  nla_put_failure_locked:
 	wdev_unlock(wdev);
  nla_put_failure:

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

* Re: [PATCH v2] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
  2018-01-14 22:22         ` [PATCH v2] " Dominik Brodowski
@ 2018-01-14 22:40           ` Johannes Berg
  2018-01-15  7:12             ` [PATCH v3] " Dominik Brodowski
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2018-01-14 22:40 UTC (permalink / raw)
  To: Dominik Brodowski; +Cc: regressions, netdev, linux-wireless, linux-kernel

On Sun, 2018-01-14 at 23:22 +0100, Dominik Brodowski wrote:
> 
> +		rcu_read_lock();
>  		ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
>  					       WLAN_EID_SSID);
>  		if (!ssid_ie)
> -			break;

nit-picking now: that "break" here may have been easier before these
changes

> +			goto nla_rcu_unlock;
>  		if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
> -			goto nla_put_failure_locked;
> +			goto nla_put_failure_rcu_locked;
> + nla_rcu_unlock:
> +		rcu_read_unlock();
>  		break;

but after, perhaps it's easier to just do

		if (ssid_ie &&
		    nla_put(...)
			goto nla_put_failure_rcu_locked;

and avoid the extra label (but yeah, it's getting late)

johannes

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

* [PATCH v3] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
  2018-01-14 22:40           ` Johannes Berg
@ 2018-01-15  7:12             ` Dominik Brodowski
  2018-01-15  8:15               ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Brodowski @ 2018-01-15  7:12 UTC (permalink / raw)
  To: Johannes Berg; +Cc: regressions, netdev, linux-wireless, linux-kernel

As ieee80211_bss_get_ie() derefences an RCU to return ssid_ie, both
the call to this function and any operation on this variable need
protection by the RCU read lock.

Fixes: 44905265bc15 ("nl80211: don't expose wdev->ssid for most interfaces")
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
---

> but after, perhaps it's easier to just do
> 
> 		if (ssid_ie &&
> 		    nla_put(...)
> 			goto nla_put_failure_rcu_locked;
> 
> and avoid the extra label (but yeah, it's getting late)

OK, done that (and updated the commit message), and testet it.

Thanks,
	Dominik

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2b3dbcd40e46..ed87a97fcb0b 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2618,12 +2618,13 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
 		const u8 *ssid_ie;
 		if (!wdev->current_bss)
 			break;
+		rcu_read_lock();
 		ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
 					       WLAN_EID_SSID);
-		if (!ssid_ie)
-			break;
-		if (nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
-			goto nla_put_failure_locked;
+		if (ssid_ie &&
+		    nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
+			goto nla_put_failure_rcu_locked;
+		rcu_read_unlock();
 		break;
 		}
 	default:
@@ -2635,6 +2636,8 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
 	genlmsg_end(msg, hdr);
 	return 0;
 
+ nla_put_failure_rcu_locked:
+	rcu_read_unlock();
  nla_put_failure_locked:
 	wdev_unlock(wdev);
  nla_put_failure:

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

* Re: [PATCH v3] nl80211: take RCU read lock when calling ieee80211_bss_get_ie()
  2018-01-15  7:12             ` [PATCH v3] " Dominik Brodowski
@ 2018-01-15  8:15               ` Johannes Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2018-01-15  8:15 UTC (permalink / raw)
  To: Dominik Brodowski; +Cc: regressions, netdev, linux-wireless, linux-kernel

On Mon, 2018-01-15 at 08:12 +0100, Dominik Brodowski wrote:
> As ieee80211_bss_get_ie() derefences an RCU to return ssid_ie, both
> the call to this function and any operation on this variable need
> protection by the RCU read lock.
> 
> Fixes: 44905265bc15 ("nl80211: don't expose wdev->ssid for most interfaces")
> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
> ---
> 
> > but after, perhaps it's easier to just do
> > 
> > 		if (ssid_ie &&
> > 		    nla_put(...)
> > 			goto nla_put_failure_rcu_locked;
> > 
> > and avoid the extra label (but yeah, it's getting late)
> 
> OK, done that (and updated the commit message), and testet it.
> 

Applied, thanks!

johannes

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

end of thread, other threads:[~2018-01-15  8:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20171222072012.GA3110@light.dominikbrodowski.net>
     [not found] ` <20171230131132.GA2624@light.dominikbrodowski.net>
     [not found]   ` <20180108100403.GA4715@light.dominikbrodowski.net>
2018-01-14 18:03     ` [PATCH] nl80211: take RCU read lock when calling ieee80211_bss_get_ie() Dominik Brodowski
2018-01-14 21:58       ` Johannes Berg
2018-01-14 22:22         ` [PATCH v2] " Dominik Brodowski
2018-01-14 22:40           ` Johannes Berg
2018-01-15  7:12             ` [PATCH v3] " Dominik Brodowski
2018-01-15  8:15               ` Johannes Berg

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).