Skip to content

Commit 3473187

Browse files
committed
mac80211: remove wep dependency
The current mac80211 code assumes that WEP is always available. If WEP fails to initialize, ieee80211_register_hw will always fail. In some cases (e.g. FIPS certification), the cryptography used by WEP is unavailable. However, in such cases there is no good reason why CCMP encryption (or even no link level encryption) cannot be used. So, this patch removes mac80211's assumption that WEP (and TKIP) will always be available for use. Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 73e1946 commit 3473187

7 files changed

Lines changed: 30 additions & 21 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
143143
return -EINVAL;
144144
}
145145

146+
/* reject WEP and TKIP keys if WEP failed to initialize */
147+
if ((alg == ALG_WEP || alg == ALG_TKIP) &&
148+
IS_ERR(sdata->local->wep_tx_tfm))
149+
return -EINVAL;
150+
146151
key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
147152
params->seq_len, params->seq);
148153
if (!key)

‎net/mac80211/main.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
637637
goto fail_sta_info;
638638

639639
result = ieee80211_wep_init(local);
640-
if (result < 0) {
640+
if (result < 0)
641641
printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
642642
wiphy_name(local->hw.wiphy), result);
643-
goto fail_wep;
644-
}
645643

646644
rtnl_lock();
647645

@@ -694,7 +692,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
694692
fail_rate:
695693
rtnl_unlock();
696694
ieee80211_wep_free(local);
697-
fail_wep:
698695
sta_info_stop(local);
699696
fail_sta_info:
700697
destroy_workqueue(local->workqueue);

‎net/mac80211/tkip.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ EXPORT_SYMBOL(ieee80211_get_tkip_key);
202202
* @payload_len is the length of payload (_not_ including IV/ICV length).
203203
* @ta is the transmitter addresses.
204204
*/
205-
void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
206-
struct ieee80211_key *key,
207-
u8 *pos, size_t payload_len, u8 *ta)
205+
int ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
206+
struct ieee80211_key *key,
207+
u8 *pos, size_t payload_len, u8 *ta)
208208
{
209209
u8 rc4key[16];
210210
struct tkip_ctx *ctx = &key->u.tkip.tx;
@@ -216,7 +216,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
216216

217217
tkip_mixing_phase2(tk, ctx, ctx->iv16, rc4key);
218218

219-
ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
219+
return ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
220220
}
221221

222222
/* Decrypt packet payload with TKIP using @key. @pos is a pointer to the

‎net/mac80211/tkip.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
u8 *ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key, u16 iv16);
1717

18-
void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
18+
int ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
1919
struct ieee80211_key *key,
2020
u8 *pos, size_t payload_len, u8 *ta);
2121
enum {

‎net/mac80211/wep.c‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ int ieee80211_wep_init(struct ieee80211_local *local)
4747

4848
void ieee80211_wep_free(struct ieee80211_local *local)
4949
{
50-
crypto_free_blkcipher(local->wep_tx_tfm);
51-
crypto_free_blkcipher(local->wep_rx_tfm);
50+
if (!IS_ERR(local->wep_tx_tfm))
51+
crypto_free_blkcipher(local->wep_tx_tfm);
52+
if (!IS_ERR(local->wep_rx_tfm))
53+
crypto_free_blkcipher(local->wep_rx_tfm);
5254
}
5355

5456
static inline bool ieee80211_wep_weak_iv(u32 iv, int keylen)
@@ -122,19 +124,24 @@ static void ieee80211_wep_remove_iv(struct ieee80211_local *local,
122124
/* Perform WEP encryption using given key. data buffer must have tailroom
123125
* for 4-byte ICV. data_len must not include this ICV. Note: this function
124126
* does _not_ add IV. data = RC4(data | CRC32(data)) */
125-
void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
126-
size_t klen, u8 *data, size_t data_len)
127+
int ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
128+
size_t klen, u8 *data, size_t data_len)
127129
{
128130
struct blkcipher_desc desc = { .tfm = tfm };
129131
struct scatterlist sg;
130132
__le32 icv;
131133

134+
if (IS_ERR(tfm))
135+
return -1;
136+
132137
icv = cpu_to_le32(~crc32_le(~0, data, data_len));
133138
put_unaligned(icv, (__le32 *)(data + data_len));
134139

135140
crypto_blkcipher_setkey(tfm, rc4key, klen);
136141
sg_init_one(&sg, data, data_len + WEP_ICV_LEN);
137142
crypto_blkcipher_encrypt(&desc, &sg, &sg, sg.length);
143+
144+
return 0;
138145
}
139146

140147

@@ -168,10 +175,8 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local,
168175
/* Add room for ICV */
169176
skb_put(skb, WEP_ICV_LEN);
170177

171-
ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, keylen + 3,
172-
iv + WEP_IV_LEN, len);
173-
174-
return 0;
178+
return ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, keylen + 3,
179+
iv + WEP_IV_LEN, len);
175180
}
176181

177182

@@ -185,6 +190,9 @@ int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
185190
struct scatterlist sg;
186191
__le32 crc;
187192

193+
if (IS_ERR(tfm))
194+
return -1;
195+
188196
crypto_blkcipher_setkey(tfm, rc4key, klen);
189197
sg_init_one(&sg, data, data_len + WEP_ICV_LEN);
190198
crypto_blkcipher_decrypt(&desc, &sg, &sg, sg.length);

‎net/mac80211/wep.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
int ieee80211_wep_init(struct ieee80211_local *local);
2020
void ieee80211_wep_free(struct ieee80211_local *local);
21-
void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
21+
int ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
2222
size_t klen, u8 *data, size_t data_len);
2323
int ieee80211_wep_encrypt(struct ieee80211_local *local,
2424
struct sk_buff *skb,

‎net/mac80211/wpa.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ static int tkip_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
183183
skb_put(skb, TKIP_ICV_LEN);
184184

185185
hdr = (struct ieee80211_hdr *) skb->data;
186-
ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm,
187-
key, pos, len, hdr->addr2);
188-
return 0;
186+
return ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm,
187+
key, pos, len, hdr->addr2);
189188
}
190189

191190

0 commit comments

Comments
 (0)