Skip to content

Commit

Permalink
PCI: tegra194: Fix possible array out of bounds access
Browse files Browse the repository at this point in the history
[ Upstream commit 205b3d0 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Sumit Gupta authored and gregkh committed Aug 23, 2023
1 parent 5c23d9b commit ea88c6c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/pci/controller/dwc/pcie-tegra194.c
Expand Up @@ -224,6 +224,7 @@
#define EP_STATE_ENABLED 1

static const unsigned int pcie_gen_freq[] = {
GEN1_CORE_CLK_FREQ, /* PCI_EXP_LNKSTA_CLS == 0; undefined */
GEN1_CORE_CLK_FREQ,
GEN2_CORE_CLK_FREQ,
GEN3_CORE_CLK_FREQ,
Expand Down Expand Up @@ -455,7 +456,11 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)

speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
PCI_EXP_LNKSTA_CLS;
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);

if (speed >= ARRAY_SIZE(pcie_gen_freq))
speed = 0;

clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);

if (pcie->of_data->has_ltr_req_fix)
return IRQ_HANDLED;
Expand Down Expand Up @@ -1016,7 +1021,11 @@ static int tegra_pcie_dw_start_link(struct dw_pcie *pci)

speed = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA) &
PCI_EXP_LNKSTA_CLS;
clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);

if (speed >= ARRAY_SIZE(pcie_gen_freq))
speed = 0;

clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);

tegra_pcie_enable_interrupts(pp);

Expand Down

0 comments on commit ea88c6c

Please sign in to comment.