Skip to content

Commit 570b90f

Browse files
amlutoKalle Valo
authored andcommitted
orinoco: Use shash instead of ahash for MIC calculations
Eric Biggers pointed out that the orinoco driver pointed scatterlists at the stack. Fix it by switching from ahash to shash. The result should be simpler, faster, and more correct. kvalo: cherry picked from commit 1fef293 as I accidentally applied this patch to wireless-drivers-next when I was supposed to apply this wireless-drivers Cc: stable@vger.kernel.org # 4.9 only Reported-by: Eric Biggers <ebiggers3@gmail.com> Signed-off-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
1 parent f5a0aab commit 570b90f

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

drivers/net/wireless/intersil/orinoco/mic.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/********************************************************************/
1717
int orinoco_mic_init(struct orinoco_private *priv)
1818
{
19-
priv->tx_tfm_mic = crypto_alloc_ahash("michael_mic", 0,
19+
priv->tx_tfm_mic = crypto_alloc_shash("michael_mic", 0,
2020
CRYPTO_ALG_ASYNC);
2121
if (IS_ERR(priv->tx_tfm_mic)) {
2222
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
@@ -25,7 +25,7 @@ int orinoco_mic_init(struct orinoco_private *priv)
2525
return -ENOMEM;
2626
}
2727

28-
priv->rx_tfm_mic = crypto_alloc_ahash("michael_mic", 0,
28+
priv->rx_tfm_mic = crypto_alloc_shash("michael_mic", 0,
2929
CRYPTO_ALG_ASYNC);
3030
if (IS_ERR(priv->rx_tfm_mic)) {
3131
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
@@ -40,17 +40,16 @@ int orinoco_mic_init(struct orinoco_private *priv)
4040
void orinoco_mic_free(struct orinoco_private *priv)
4141
{
4242
if (priv->tx_tfm_mic)
43-
crypto_free_ahash(priv->tx_tfm_mic);
43+
crypto_free_shash(priv->tx_tfm_mic);
4444
if (priv->rx_tfm_mic)
45-
crypto_free_ahash(priv->rx_tfm_mic);
45+
crypto_free_shash(priv->rx_tfm_mic);
4646
}
4747

48-
int orinoco_mic(struct crypto_ahash *tfm_michael, u8 *key,
48+
int orinoco_mic(struct crypto_shash *tfm_michael, u8 *key,
4949
u8 *da, u8 *sa, u8 priority,
5050
u8 *data, size_t data_len, u8 *mic)
5151
{
52-
AHASH_REQUEST_ON_STACK(req, tfm_michael);
53-
struct scatterlist sg[2];
52+
SHASH_DESC_ON_STACK(desc, tfm_michael);
5453
u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
5554
int err;
5655

@@ -67,18 +66,27 @@ int orinoco_mic(struct crypto_ahash *tfm_michael, u8 *key,
6766
hdr[ETH_ALEN * 2 + 2] = 0;
6867
hdr[ETH_ALEN * 2 + 3] = 0;
6968

70-
/* Use scatter gather to MIC header and data in one go */
71-
sg_init_table(sg, 2);
72-
sg_set_buf(&sg[0], hdr, sizeof(hdr));
73-
sg_set_buf(&sg[1], data, data_len);
69+
desc->tfm = tfm_michael;
70+
desc->flags = 0;
7471

75-
if (crypto_ahash_setkey(tfm_michael, key, MIC_KEYLEN))
76-
return -1;
72+
err = crypto_shash_setkey(tfm_michael, key, MIC_KEYLEN);
73+
if (err)
74+
return err;
75+
76+
err = crypto_shash_init(desc);
77+
if (err)
78+
return err;
79+
80+
err = crypto_shash_update(desc, hdr, sizeof(hdr));
81+
if (err)
82+
return err;
83+
84+
err = crypto_shash_update(desc, data, data_len);
85+
if (err)
86+
return err;
87+
88+
err = crypto_shash_final(desc, mic);
89+
shash_desc_zero(desc);
7790

78-
ahash_request_set_tfm(req, tfm_michael);
79-
ahash_request_set_callback(req, 0, NULL, NULL);
80-
ahash_request_set_crypt(req, sg, mic, data_len + sizeof(hdr));
81-
err = crypto_ahash_digest(req);
82-
ahash_request_zero(req);
8391
return err;
8492
}

drivers/net/wireless/intersil/orinoco/mic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define _ORINOCO_MIC_H_
77

88
#include <linux/types.h>
9+
#include <crypto/hash.h>
910

1011
#define MICHAEL_MIC_LEN 8
1112

@@ -15,7 +16,7 @@ struct crypto_ahash;
1516

1617
int orinoco_mic_init(struct orinoco_private *priv);
1718
void orinoco_mic_free(struct orinoco_private *priv);
18-
int orinoco_mic(struct crypto_ahash *tfm_michael, u8 *key,
19+
int orinoco_mic(struct crypto_shash *tfm_michael, u8 *key,
1920
u8 *da, u8 *sa, u8 priority,
2021
u8 *data, size_t data_len, u8 *mic);
2122

drivers/net/wireless/intersil/orinoco/orinoco.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ struct orinoco_private {
152152
u8 *wpa_ie;
153153
int wpa_ie_len;
154154

155-
struct crypto_ahash *rx_tfm_mic;
156-
struct crypto_ahash *tx_tfm_mic;
155+
struct crypto_shash *rx_tfm_mic;
156+
struct crypto_shash *tx_tfm_mic;
157157

158158
unsigned int wpa_enabled:1;
159159
unsigned int tkip_cm_active:1;

0 commit comments

Comments
 (0)