Skip to content

Commit 66bc695

Browse files
Jianmin ZhuPixelBoot
authored andcommitted
qcacld-3.0: Avoid possible array OOB
Add bound check before access array to avoid out of bound issue. Separate array bound and duplicate check of 11a and 11b since they have different length and type. Change-Id: Icb9382cd42385339532518759de0f6137c5203bd CRs-Fixed: 3051517
1 parent a7e2058 commit 66bc695

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

drivers/staging/qcacld-3.0/core/mac/src/pe/lim/lim_assoc_utils.c

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2011-2021 The Linux Foundation. All rights reserved.
3+
* Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
34
*
45
* Previously licensed under the ISC license by Qualcomm Atheros, Inc.
56
*
@@ -1643,7 +1644,7 @@ lim_populate_peer_rate_set(tpAniSirGlobal pMac,
16431644
{
16441645
tSirMacRateSet tempRateSet;
16451646
tSirMacRateSet tempRateSet2;
1646-
uint32_t i, j, val, min, isArate = 0;
1647+
uint32_t i, j, val, min;
16471648
uint8_t aRateIndex = 0;
16481649
uint8_t bRateIndex = 0;
16491650

@@ -1703,39 +1704,40 @@ lim_populate_peer_rate_set(tpAniSirGlobal pMac,
17031704
min = j;
17041705
}
17051706
}
1706-
if (sirIsArate(tempRateSet.rate[min] & 0x7f)) {
1707-
isArate = 1;
1707+
/*
1708+
* HAL needs to know whether the rate is basic rate or not, as it needs to
1709+
* update the response rate table accordingly. e.g. if one of the 11a rates is
1710+
* basic rate, then that rate can be used for sending control frames.
1711+
* HAL updates the response rate table whenever basic rate set is changed.
1712+
*/
1713+
if (basicOnly && !(tempRateSet.rate[min] & 0x80)) {
1714+
pe_debug("Invalid basic rate");
1715+
} else if (sirIsArate(tempRateSet.rate[min] & 0x7f)) {
1716+
if (aRateIndex >= SIR_NUM_11A_RATES) {
1717+
pe_debug("OOB, aRateIndex: %d", aRateIndex);
1718+
} else if (aRateIndex >= 1 && (tempRateSet.rate[min] ==
1719+
pRates->llaRates[aRateIndex - 1])) {
1720+
pe_debug("Duplicate 11a rate: %d",
1721+
tempRateSet.rate[min]);
1722+
} else {
1723+
pRates->llaRates[aRateIndex++] =
1724+
tempRateSet.rate[min];
1725+
}
17081726
} else if (sirIsBrate(tempRateSet.rate[min] & 0x7f)) {
1709-
isArate = 0;
1727+
if (bRateIndex >= SIR_NUM_11B_RATES) {
1728+
pe_debug("OOB, bRateIndex: %d", bRateIndex);
1729+
} else if (bRateIndex >= 1 && (tempRateSet.rate[min] ==
1730+
pRates->llbRates[bRateIndex - 1])) {
1731+
pe_debug("Duplicate 11b rate: %d",
1732+
tempRateSet.rate[min]);
1733+
} else {
1734+
pRates->llbRates[bRateIndex++] =
1735+
tempRateSet.rate[min];
1736+
}
17101737
} else {
17111738
pe_debug("%d is neither 11a nor 11b rate",
17121739
tempRateSet.rate[min]);
1713-
tempRateSet.rate[min] = 0xff;
1714-
continue;
1715-
}
1716-
if (tempRateSet.rate[min] == pRates->llaRates[aRateIndex] ||
1717-
tempRateSet.rate[min] == pRates->llbRates[bRateIndex]) {
1718-
pe_debug("Duplicate rate: %d", tempRateSet.rate[min]);
1719-
tempRateSet.rate[min] = 0xff;
1720-
continue;
1721-
}
1722-
/*
1723-
* HAL needs to know whether the rate is basic rate or not,
1724-
* as it needs to update the response rate table accordingly.
1725-
* e.g. if one of the 11a rates is basic rate, then that rate
1726-
* can be used for sending control frames. HAL updates the
1727-
* response rate table whenever basic rate set is changed.
1728-
*/
1729-
if (basicOnly && !(tempRateSet.rate[min] & 0x80)) {
1730-
tempRateSet.rate[min] = 0xff;
1731-
continue;
17321740
}
1733-
if (isArate && aRateIndex < SIR_NUM_11A_RATES)
1734-
pRates->llaRates[aRateIndex++] =
1735-
tempRateSet.rate[min];
1736-
else if (bRateIndex < SIR_NUM_11B_RATES)
1737-
pRates->llbRates[bRateIndex++] =
1738-
tempRateSet.rate[min];
17391741
tempRateSet.rate[min] = 0xff;
17401742
}
17411743

0 commit comments

Comments
 (0)