Skip to content

Commit daa69a2

Browse files
Dan Carpentergregkh
authored andcommitted
mwifiex: Prevent memory corruption handling keys
[ Upstream commit e186967 ] The length of the key comes from the network and it's a 16 bit number. It needs to be capped to prevent a buffer overflow. Fixes: 5e6e3a9 ("wireless: mwifiex: initial commit for Marvell mwifiex driver") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Ganapathi Bhat <ganapathi.bhat@nxp.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20200708115857.GA13729@mwanda Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9686780 commit daa69a2

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ static int mwifiex_ret_802_11_key_material_v1(struct mwifiex_private *priv,
581581
{
582582
struct host_cmd_ds_802_11_key_material *key =
583583
&resp->params.key_material;
584+
int len;
585+
586+
len = le16_to_cpu(key->key_param_set.key_len);
587+
if (len > sizeof(key->key_param_set.key))
588+
return -EINVAL;
584589

585590
if (le16_to_cpu(key->action) == HostCmd_ACT_GEN_SET) {
586591
if ((le16_to_cpu(key->key_param_set.key_info) & KEY_MCAST)) {
@@ -594,9 +599,8 @@ static int mwifiex_ret_802_11_key_material_v1(struct mwifiex_private *priv,
594599

595600
memset(priv->aes_key.key_param_set.key, 0,
596601
sizeof(key->key_param_set.key));
597-
priv->aes_key.key_param_set.key_len = key->key_param_set.key_len;
598-
memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key,
599-
le16_to_cpu(priv->aes_key.key_param_set.key_len));
602+
priv->aes_key.key_param_set.key_len = cpu_to_le16(len);
603+
memcpy(priv->aes_key.key_param_set.key, key->key_param_set.key, len);
600604

601605
return 0;
602606
}
@@ -611,9 +615,14 @@ static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
611615
struct host_cmd_ds_command *resp)
612616
{
613617
struct host_cmd_ds_802_11_key_material_v2 *key_v2;
614-
__le16 len;
618+
int len;
615619

616620
key_v2 = &resp->params.key_material_v2;
621+
622+
len = le16_to_cpu(key_v2->key_param_set.key_params.aes.key_len);
623+
if (len > WLAN_KEY_LEN_CCMP)
624+
return -EINVAL;
625+
617626
if (le16_to_cpu(key_v2->action) == HostCmd_ACT_GEN_SET) {
618627
if ((le16_to_cpu(key_v2->key_param_set.key_info) & KEY_MCAST)) {
619628
mwifiex_dbg(priv->adapter, INFO, "info: key: GTK is set\n");
@@ -629,10 +638,9 @@ static int mwifiex_ret_802_11_key_material_v2(struct mwifiex_private *priv,
629638
memset(priv->aes_key_v2.key_param_set.key_params.aes.key, 0,
630639
WLAN_KEY_LEN_CCMP);
631640
priv->aes_key_v2.key_param_set.key_params.aes.key_len =
632-
key_v2->key_param_set.key_params.aes.key_len;
633-
len = priv->aes_key_v2.key_param_set.key_params.aes.key_len;
641+
cpu_to_le16(len);
634642
memcpy(priv->aes_key_v2.key_param_set.key_params.aes.key,
635-
key_v2->key_param_set.key_params.aes.key, le16_to_cpu(len));
643+
key_v2->key_param_set.key_params.aes.key, len);
636644

637645
return 0;
638646
}

0 commit comments

Comments
 (0)