Skip to content

Commit 205b3d0

Browse files
Sumit Guptathierryreding
authored andcommitted
PCI: tegra194: Fix possible array out of bounds access
Add check to fix the possible array out of bounds violation by making speed equal to GEN1_CORE_CLK_FREQ when its value is more than the size of "pcie_gen_freq" array. This array has size of four but possible speed (CLS) values are from "0 to 0xF". So, "speed - 1" values are "-1 to 0xE". Suggested-by: Bjorn Helgaas <helgaas@kernel.org> Signed-off-by: Sumit Gupta <sumitg@nvidia.com> Link: https://lore.kernel.org/lkml/72b9168b-d4d6-4312-32ea-69358df2f2d0@nvidia.com/ Acked-by: Lorenzo Pieralisi <lpieralisi@kernel.org> Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent 9422644 commit 205b3d0

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

drivers/pci/controller/dwc/pcie-tegra194.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
#define EP_STATE_ENABLED 1
224224

225225
static const unsigned int pcie_gen_freq[] = {
226+
GEN1_CORE_CLK_FREQ, /* PCI_EXP_LNKSTA_CLS == 0; undefined */
226227
GEN1_CORE_CLK_FREQ,
227228
GEN2_CORE_CLK_FREQ,
228229
GEN3_CORE_CLK_FREQ,
@@ -459,7 +460,11 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
459460

460461
speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
461462
PCI_EXP_LNKSTA_CLS;
462-
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
463+
464+
if (speed >= ARRAY_SIZE(pcie_gen_freq))
465+
speed = 0;
466+
467+
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
463468

464469
if (pcie->of_data->has_ltr_req_fix)
465470
return IRQ_HANDLED;
@@ -1020,7 +1025,11 @@ static int tegra_pcie_dw_start_link(struct dw_pcie *pci)
10201025

10211026
speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
10221027
PCI_EXP_LNKSTA_CLS;
1023-
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
1028+
1029+
if (speed >= ARRAY_SIZE(pcie_gen_freq))
1030+
speed = 0;
1031+
1032+
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
10241033

10251034
tegra_pcie_enable_interrupts(pp);
10261035

0 commit comments

Comments
 (0)