Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Nicolas Waisman <nico@semmle.com>
Signed-off-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20191004095132.15777-2-will@kernel.org
[adjust commit log a bit]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Will Deacon and committed by
Johannes Berg
4ac2813c 4152561f

+6 -2
+6 -2
net/wireless/wext-sme.c
··· 202 202 struct iw_point *data, char *ssid) 203 203 { 204 204 struct wireless_dev *wdev = dev->ieee80211_ptr; 205 + int ret = 0; 205 206 206 207 /* call only for station! */ 207 208 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION)) ··· 220 219 if (ie) { 221 220 data->flags = 1; 222 221 data->length = ie[1]; 223 - memcpy(ssid, ie + 2, data->length); 222 + if (data->length > IW_ESSID_MAX_SIZE) 223 + ret = -EINVAL; 224 + else 225 + memcpy(ssid, ie + 2, data->length); 224 226 } 225 227 rcu_read_unlock(); 226 228 } else if (wdev->wext.connect.ssid && wdev->wext.connect.ssid_len) { ··· 233 229 } 234 230 wdev_unlock(wdev); 235 231 236 - return 0; 232 + return ret; 237 233 } 238 234 239 235 int cfg80211_mgd_wext_siwap(struct net_device *dev,