Skip to content

Commit

Permalink
phy: marvell: a3700-comphy: Fix out of bounds read
Browse files Browse the repository at this point in the history
[ Upstream commit e4308bc ]

There is an out of bounds read access of 'gbe_phy_init_fix[fix_idx].addr'
every iteration after 'fix_idx' reaches 'ARRAY_SIZE(gbe_phy_init_fix)'.

Make sure 'gbe_phy_init[addr]' is used when all elements of
'gbe_phy_init_fix' array are handled.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 9343370 ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation")
Signed-off-by: Mikhail Kobuk <m.kobuk@ispras.ru>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20240321164734.49273-1-m.kobuk@ispras.ru
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Mikhail Kobuk authored and gregkh committed May 2, 2024
1 parent 935d4c7 commit 610f175
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/phy/marvell/phy-mvebu-a3700-comphy.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,12 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane,
* comparison to 3.125 Gbps values. These register values are
* stored in "gbe_phy_init_fix" array.
*/
if (!is_1gbps && gbe_phy_init_fix[fix_idx].addr == addr) {
if (!is_1gbps &&
fix_idx < ARRAY_SIZE(gbe_phy_init_fix) &&
gbe_phy_init_fix[fix_idx].addr == addr) {
/* Use new value */
val = gbe_phy_init_fix[fix_idx].value;
if (fix_idx < ARRAY_SIZE(gbe_phy_init_fix))
fix_idx++;
fix_idx++;
} else {
val = gbe_phy_init[addr];
}
Expand Down

0 comments on commit 610f175

Please sign in to comment.