Linux-Wireless Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] mac80211: Reject malformed SSID elements
@ 2019-10-04  9:51 Will Deacon
  2019-10-04  9:51 ` [PATCH 2/2] cfg80211: wext: " Will Deacon
  2019-10-04 15:55 ` [PATCH 1/2] mac80211: " Kees Cook
  0 siblings, 2 replies; 4+ messages in thread
From: Will Deacon @ 2019-10-04  9:51 UTC (permalink / raw)
  To: linux-wireless; +Cc: nico, Will Deacon, stable, Johannes Berg, Kees Cook

Although this shouldn't occur in practice, it's a good idea to bounds
check the length field of the SSID element prior to using it for things
like allocations or memcpy operations.

Cc: <stable@vger.kernel.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Kees Cook <keescook@chromium.org>
Reported-by: Nicolas Waisman <nico@semmle.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 net/mac80211/mlme.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 26a2f49208b6..54dd8849d1cc 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -2633,7 +2633,8 @@ struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
 
 	rcu_read_lock();
 	ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
-	if (WARN_ON_ONCE(ssid == NULL))
+	if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
+		      "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
 		ssid_len = 0;
 	else
 		ssid_len = ssid[1];
@@ -5233,7 +5234,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
 
 	rcu_read_lock();
 	ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
-	if (!ssidie) {
+	if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
 		rcu_read_unlock();
 		kfree(assoc_data);
 		return -EINVAL;
-- 
2.23.0.581.g78d2f28ef7-goog


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

* [PATCH 2/2] cfg80211: wext: Reject malformed SSID elements
  2019-10-04  9:51 [PATCH 1/2] mac80211: Reject malformed SSID elements Will Deacon
@ 2019-10-04  9:51 ` " Will Deacon
  2019-10-04 15:56   ` Kees Cook
  2019-10-04 15:55 ` [PATCH 1/2] mac80211: " Kees Cook
  1 sibling, 1 reply; 4+ messages in thread
From: Will Deacon @ 2019-10-04  9:51 UTC (permalink / raw)
  To: linux-wireless; +Cc: nico, Will Deacon, stable, Johannes Berg, Kees Cook

Ensure the SSID element is bounds-checked prior to invoking memcpy()
with its length field.

Cc: <stable@vger.kernel.org>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Kees Cook <keescook@chromium.org>
Reported-by: Nicolas Waisman <nico@semmle.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 net/wireless/wext-sme.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index c67d7a82ab13..3fd2cc7fc36a 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -201,6 +201,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
 			       struct iw_request_info *info,
 			       struct iw_point *data, char *ssid)
 {
+	int ret = 0;
 	struct wireless_dev *wdev = dev->ieee80211_ptr;
 
 	/* call only for station! */
@@ -219,7 +220,10 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
 		if (ie) {
 			data->flags = 1;
 			data->length = ie[1];
-			memcpy(ssid, ie + 2, data->length);
+			if (data->length > IW_ESSID_MAX_SIZE)
+				ret = -EINVAL;
+			else
+				memcpy(ssid, ie + 2, data->length);
 		}
 		rcu_read_unlock();
 	} else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
@@ -229,7 +233,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
 	}
 	wdev_unlock(wdev);
 
-	return 0;
+	return ret;
 }
 
 int cfg80211_mgd_wext_siwap(struct net_device *dev,
-- 
2.23.0.581.g78d2f28ef7-goog


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

* Re: [PATCH 1/2] mac80211: Reject malformed SSID elements
  2019-10-04  9:51 [PATCH 1/2] mac80211: Reject malformed SSID elements Will Deacon
  2019-10-04  9:51 ` [PATCH 2/2] cfg80211: wext: " Will Deacon
@ 2019-10-04 15:55 ` " Kees Cook
  1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2019-10-04 15:55 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-wireless, nico, stable, Johannes Berg

On Fri, Oct 04, 2019 at 10:51:31AM +0100, Will Deacon wrote:
> Although this shouldn't occur in practice, it's a good idea to bounds
> check the length field of the SSID element prior to using it for things
> like allocations or memcpy operations.
> 
> Cc: <stable@vger.kernel.org>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: Kees Cook <keescook@chromium.org>
> Reported-by: Nicolas Waisman <nico@semmle.com>
> Signed-off-by: Will Deacon <will@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  net/mac80211/mlme.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
> index 26a2f49208b6..54dd8849d1cc 100644
> --- a/net/mac80211/mlme.c
> +++ b/net/mac80211/mlme.c
> @@ -2633,7 +2633,8 @@ struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
>  
>  	rcu_read_lock();
>  	ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
> -	if (WARN_ON_ONCE(ssid == NULL))
> +	if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
> +		      "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
>  		ssid_len = 0;
>  	else
>  		ssid_len = ssid[1];
> @@ -5233,7 +5234,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
>  
>  	rcu_read_lock();
>  	ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
> -	if (!ssidie) {
> +	if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
>  		rcu_read_unlock();
>  		kfree(assoc_data);
>  		return -EINVAL;
> -- 
> 2.23.0.581.g78d2f28ef7-goog
> 

-- 
Kees Cook

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

* Re: [PATCH 2/2] cfg80211: wext: Reject malformed SSID elements
  2019-10-04  9:51 ` [PATCH 2/2] cfg80211: wext: " Will Deacon
@ 2019-10-04 15:56   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2019-10-04 15:56 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-wireless, nico, stable, Johannes Berg

On Fri, Oct 04, 2019 at 10:51:32AM +0100, Will Deacon wrote:
> Ensure the SSID element is bounds-checked prior to invoking memcpy()
> with its length field.
> 
> Cc: <stable@vger.kernel.org>
> Cc: Johannes Berg <johannes@sipsolutions.net>
> Cc: Kees Cook <keescook@chromium.org>
> Reported-by: Nicolas Waisman <nico@semmle.com>
> Signed-off-by: Will Deacon <will@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>  net/wireless/wext-sme.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
> index c67d7a82ab13..3fd2cc7fc36a 100644
> --- a/net/wireless/wext-sme.c
> +++ b/net/wireless/wext-sme.c
> @@ -201,6 +201,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
>  			       struct iw_request_info *info,
>  			       struct iw_point *data, char *ssid)
>  {
> +	int ret = 0;
>  	struct wireless_dev *wdev = dev->ieee80211_ptr;
>  
>  	/* call only for station! */
> @@ -219,7 +220,10 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
>  		if (ie) {
>  			data->flags = 1;
>  			data->length = ie[1];
> -			memcpy(ssid, ie + 2, data->length);
> +			if (data->length > IW_ESSID_MAX_SIZE)
> +				ret = -EINVAL;
> +			else
> +				memcpy(ssid, ie + 2, data->length);
>  		}
>  		rcu_read_unlock();
>  	} else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) {
> @@ -229,7 +233,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
>  	}
>  	wdev_unlock(wdev);
>  
> -	return 0;
> +	return ret;
>  }
>  
>  int cfg80211_mgd_wext_siwap(struct net_device *dev,
> -- 
> 2.23.0.581.g78d2f28ef7-goog
> 

-- 
Kees Cook

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04  9:51 [PATCH 1/2] mac80211: Reject malformed SSID elements Will Deacon
2019-10-04  9:51 ` [PATCH 2/2] cfg80211: wext: " Will Deacon
2019-10-04 15:56   ` Kees Cook
2019-10-04 15:55 ` [PATCH 1/2] mac80211: " Kees Cook

Linux-Wireless Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-wireless/0 linux-wireless/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-wireless linux-wireless/ https://lore.kernel.org/linux-wireless \
		linux-wireless@vger.kernel.org linux-wireless@archiver.kernel.org
	public-inbox-index linux-wireless

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-wireless


AGPL code for this site: git clone https://public-inbox.org/ public-inbox