Commit e4308bc2 authored by Mikhail Kobuk's avatar Mikhail Kobuk Committed by Vinod Koul

phy: marvell: a3700-comphy: Fix out of bounds read

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: 93433708 ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation")
Signed-off-by: default avatarMikhail Kobuk <m.kobuk@ispras.ru>
Reviewed-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20240321164734.49273-1-m.kobuk@ispras.ruSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 4cece764
......@@ -611,10 +611,11 @@ 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++;
} else {
val = gbe_phy_init[addr];
......
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