Commit 1e3d31c5 authored by Roel Kluin's avatar Roel Kluin Committed by John W. Linville

libertas: Read buffer overflow

Check whether index is within bounds before testing the element.

(also includes "Libertas: Association request to the driver failed"

The size of the tmp buffer was too small, causing a regression

rates->rates has an arraysize of 1, so a memcpy with
MAX_RATES (14) was already causing reads out of bounds.

In get_common_rates() the memset/memcpy can be moved upwards. -- JWL)
Signed-off-by: default avatarRoel Kluin <roel.kluin@gmail.com>
Tested-by: default avatarDaniel Mack <daniel@caiaq.de>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 1c4e9ab3
...@@ -44,12 +44,11 @@ static int get_common_rates(struct lbs_private *priv, ...@@ -44,12 +44,11 @@ static int get_common_rates(struct lbs_private *priv,
{ {
u8 *card_rates = lbs_bg_rates; u8 *card_rates = lbs_bg_rates;
size_t num_card_rates = sizeof(lbs_bg_rates); size_t num_card_rates = sizeof(lbs_bg_rates);
int ret = 0, i, j; int i, j;
u8 *tmp; u8 *tmp;
size_t tmp_size = 0; size_t tmp_size = 0;
tmp = kzalloc((ARRAY_SIZE(lbs_bg_rates) - 1) * (*rates_size - 1), tmp = kzalloc(MAX_RATES * ARRAY_SIZE(lbs_bg_rates), GFP_KERNEL);
GFP_KERNEL);
if (!tmp) if (!tmp)
return -1; return -1;
...@@ -66,24 +65,24 @@ static int get_common_rates(struct lbs_private *priv, ...@@ -66,24 +65,24 @@ static int get_common_rates(struct lbs_private *priv,
lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size);
lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
memset(rates, 0, *rates_size);
*rates_size = min_t(u16, tmp_size, *rates_size);
memcpy(rates, tmp, *rates_size);
if (!priv->enablehwauto) { if (!priv->enablehwauto) {
for (i = 0; i < tmp_size; i++) { for (i = 0; i < tmp_size; i++) {
if (tmp[i] == priv->cur_rate) if (tmp[i] == priv->cur_rate)
goto done; break;
}
if (i == tmp_size) {
lbs_pr_alert("Previously set fixed data rate %#x isn't "
"compatible with the network.\n",
priv->cur_rate);
return -1;
} }
lbs_pr_alert("Previously set fixed data rate %#x isn't "
"compatible with the network.\n", priv->cur_rate);
ret = -1;
goto done;
} }
ret = 0;
done:
memset(rates, 0, *rates_size);
*rates_size = min_t(int, tmp_size, *rates_size);
memcpy(rates, tmp, *rates_size);
kfree(tmp); kfree(tmp);
return ret; return 0;
} }
...@@ -325,8 +324,8 @@ static int lbs_associate(struct lbs_private *priv, ...@@ -325,8 +324,8 @@ static int lbs_associate(struct lbs_private *priv,
rates = (struct mrvl_ie_rates_param_set *) pos; rates = (struct mrvl_ie_rates_param_set *) pos;
rates->header.type = cpu_to_le16(TLV_TYPE_RATES); rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
memcpy(&rates->rates, &bss->rates, MAX_RATES);
tmplen = MAX_RATES; tmplen = MAX_RATES;
memcpy(&rates->rates, &bss->rates, tmplen);
if (get_common_rates(priv, rates->rates, &tmplen)) { if (get_common_rates(priv, rates->rates, &tmplen)) {
ret = -1; ret = -1;
goto done; goto done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment