Commit 4ac2813c authored by Will Deacon's avatar Will Deacon Committed by Johannes Berg

cfg80211: wext: avoid copying malformed SSIDs

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

Cc: <stable@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Reported-by: default avatarNicolas Waisman <nico@semmle.com>
Signed-off-by: default avatarWill Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20191004095132.15777-2-will@kernel.org
[adjust commit log a bit]
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 4152561f
...@@ -202,6 +202,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev, ...@@ -202,6 +202,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
struct iw_point *data, char *ssid) struct iw_point *data, char *ssid)
{ {
struct wireless_dev *wdev = dev->ieee80211_ptr; struct wireless_dev *wdev = dev->ieee80211_ptr;
int ret = 0;
/* call only for station! */ /* call only for station! */
if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION))
...@@ -219,6 +220,9 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev, ...@@ -219,6 +220,9 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
if (ie) { if (ie) {
data->flags = 1; data->flags = 1;
data->length = ie[1]; data->length = ie[1];
if (data->length > IW_ESSID_MAX_SIZE)
ret = -EINVAL;
else
memcpy(ssid, ie + 2, data->length); memcpy(ssid, ie + 2, data->length);
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -229,7 +233,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev, ...@@ -229,7 +233,7 @@ int cfg80211_mgd_wext_giwessid(struct net_device *dev,
} }
wdev_unlock(wdev); wdev_unlock(wdev);
return 0; return ret;
} }
int cfg80211_mgd_wext_siwap(struct net_device *dev, int cfg80211_mgd_wext_siwap(struct net_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment