@@ -802,6 +802,9 @@ static void ieee80211_key_destroy(struct ieee80211_key *key,
802
802
803
803
void ieee80211_key_free_unused (struct ieee80211_key * key )
804
804
{
805
+ if (!key )
806
+ return ;
807
+
805
808
WARN_ON (key -> sdata || key -> local );
806
809
ieee80211_key_free_common (key );
807
810
}
@@ -854,7 +857,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
854
857
* can cause warnings to appear.
855
858
*/
856
859
bool delay_tailroom = sdata -> vif .type == NL80211_IFTYPE_STATION ;
857
- int ret = - EOPNOTSUPP ;
860
+ int ret ;
858
861
859
862
mutex_lock (& sdata -> local -> key_mtx );
860
863
@@ -868,8 +871,10 @@ int ieee80211_key_link(struct ieee80211_key *key,
868
871
* the same cipher. Enforce the assumption for pairwise keys.
869
872
*/
870
873
if ((alt_key && alt_key -> conf .cipher != key -> conf .cipher ) ||
871
- (old_key && old_key -> conf .cipher != key -> conf .cipher ))
874
+ (old_key && old_key -> conf .cipher != key -> conf .cipher )) {
875
+ ret = - EOPNOTSUPP ;
872
876
goto out ;
877
+ }
873
878
} else if (sta ) {
874
879
struct link_sta_info * link_sta = & sta -> deflink ;
875
880
int link_id = key -> conf .link_id ;
@@ -895,18 +900,19 @@ int ieee80211_key_link(struct ieee80211_key *key,
895
900
896
901
/* Non-pairwise keys must also not switch the cipher on rekey */
897
902
if (!pairwise ) {
898
- if (old_key && old_key -> conf .cipher != key -> conf .cipher )
903
+ if (old_key && old_key -> conf .cipher != key -> conf .cipher ) {
904
+ ret = - EOPNOTSUPP ;
899
905
goto out ;
906
+ }
900
907
}
901
908
902
909
/*
903
910
* Silently accept key re-installation without really installing the
904
911
* new version of the key to avoid nonce reuse or replay issues.
905
912
*/
906
913
if (ieee80211_key_identical (sdata , old_key , key )) {
907
- ieee80211_key_free_unused (key );
908
914
ret = - EALREADY ;
909
- goto out ;
915
+ goto unlock ;
910
916
}
911
917
912
918
key -> local = sdata -> local ;
@@ -930,7 +936,11 @@ int ieee80211_key_link(struct ieee80211_key *key,
930
936
ieee80211_key_free (key , delay_tailroom );
931
937
}
932
938
939
+ key = NULL ;
940
+
933
941
out :
942
+ ieee80211_key_free_unused (key );
943
+ unlock :
934
944
mutex_unlock (& sdata -> local -> key_mtx );
935
945
936
946
return ret ;
0 commit comments