cfg80211: wext: really don't store non-WEP keys
[cascardo/linux.git] / net / wireless / wext-compat.c
index 7b97d43..2b096c0 100644 (file)
@@ -406,6 +406,10 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
        if (pairwise && !addr)
                return -EINVAL;
 
+       /*
+        * In many cases we won't actually need this, but it's better
+        * to do it first in case the allocation fails. Don't use wext.
+        */
        if (!wdev->wext.keys) {
                wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
                                          GFP_KERNEL);
@@ -493,7 +497,13 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
        if (err)
                return err;
 
-       if (!addr) {
+       /*
+        * We only need to store WEP keys, since they're the only keys that
+        * can be be set before a connection is established and persist after
+        * disconnecting.
+        */
+       if (!addr && (params->cipher == WLAN_CIPHER_SUITE_WEP40 ||
+                     params->cipher == WLAN_CIPHER_SUITE_WEP104)) {
                wdev->wext.keys->params[idx] = *params;
                memcpy(wdev->wext.keys->data[idx],
                        params->key, params->key_len);