linux-phy.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read
@ 2024-03-21 16:47 Mikhail Kobuk
  2024-03-21 16:47 ` [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Mikhail Kobuk
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mikhail Kobuk @ 2024-03-21 16:47 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Mikhail Kobuk, Vinod Koul, Kishon Vijay Abraham I,
	Marek Behún, Pali Rohár, linux-phy, linux-kernel,
	lvc-project, Alexey Khoroshilov

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: 934337080c6c ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation")
Signed-off-by: Mikhail Kobuk <m.kobuk@ispras.ru>
---
 drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
index 15bf10710de0..1d1db1737422 100644
--- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
+++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
@@ -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];
 		}
-- 
2.44.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size
  2024-03-21 16:47 [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Mikhail Kobuk
@ 2024-03-21 16:47 ` Mikhail Kobuk
  2024-03-22  7:26   ` Miquel Raynal
  2024-03-22  7:25 ` [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Miquel Raynal
  2024-04-05 17:08 ` Vinod Koul
  2 siblings, 1 reply; 5+ messages in thread
From: Mikhail Kobuk @ 2024-03-21 16:47 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Mikhail Kobuk, Vinod Koul, Kishon Vijay Abraham I,
	Marek Behún, Pali Rohár, linux-phy, linux-kernel,
	lvc-project, Alexey Khoroshilov

Replace hardcoded 'gbe_phy_init' array size by explicit one.

Fixes: 934337080c6c ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation")
Signed-off-by: Mikhail Kobuk <m.kobuk@ispras.ru>
---
 drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
index 41162d7228c9..15bf10710de0 100644
--- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
+++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
@@ -603,7 +603,7 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane,
 	u16 val;
 
 	fix_idx = 0;
-	for (addr = 0; addr < 512; addr++) {
+	for (addr = 0; addr < ARRAY_SIZE(gbe_phy_init); addr++) {
 		/*
 		 * All PHY register values are defined in full for 3.125Gbps
 		 * SERDES speed. The values required for 1.25 Gbps are almost
-- 
2.44.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read
  2024-03-21 16:47 [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Mikhail Kobuk
  2024-03-21 16:47 ` [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Mikhail Kobuk
@ 2024-03-22  7:25 ` Miquel Raynal
  2024-04-05 17:08 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2024-03-22  7:25 UTC (permalink / raw)
  To: Mikhail Kobuk
  Cc: Vinod Koul, Kishon Vijay Abraham I, Marek Behún,
	Pali Rohár, linux-phy, linux-kernel, lvc-project,
	Alexey Khoroshilov

Hi Mikhail,

m.kobuk@ispras.ru wrote on Thu, 21 Mar 2024 19:47:30 +0300:

> 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: 934337080c6c ("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>

Thanks,
Miquèl

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size
  2024-03-21 16:47 ` [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Mikhail Kobuk
@ 2024-03-22  7:26   ` Miquel Raynal
  0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2024-03-22  7:26 UTC (permalink / raw)
  To: Mikhail Kobuk
  Cc: Vinod Koul, Kishon Vijay Abraham I, Marek Behún,
	Pali Rohár, linux-phy, linux-kernel, lvc-project,
	Alexey Khoroshilov

Hi Mikhail,

m.kobuk@ispras.ru wrote on Thu, 21 Mar 2024 19:47:31 +0300:

> Replace hardcoded 'gbe_phy_init' array size by explicit one.
> 
> Fixes: 934337080c6c ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation")
> Signed-off-by: Mikhail Kobuk <m.kobuk@ispras.ru>
> ---
>  drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
> index 41162d7228c9..15bf10710de0 100644
> --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
> +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
> @@ -603,7 +603,7 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane,
>  	u16 val;
>  
>  	fix_idx = 0;
> -	for (addr = 0; addr < 512; addr++) {
> +	for (addr = 0; addr < ARRAY_SIZE(gbe_phy_init); addr++) {
>  		/*
>  		 * All PHY register values are defined in full for 3.125Gbps
>  		 * SERDES speed. The values required for 1.25 Gbps are almost

512 is also used where gbe_phy_init is defined, so maybe it would be
worthe defining this size once and then use the definition in both
places.

Thanks, Miquèl

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read
  2024-03-21 16:47 [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Mikhail Kobuk
  2024-03-21 16:47 ` [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Mikhail Kobuk
  2024-03-22  7:25 ` [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Miquel Raynal
@ 2024-04-05 17:08 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2024-04-05 17:08 UTC (permalink / raw)
  To: Miquel Raynal, Mikhail Kobuk
  Cc: Kishon Vijay Abraham I, Marek Behún, Pali Rohár,
	linux-phy, linux-kernel, lvc-project, Alexey Khoroshilov


On Thu, 21 Mar 2024 19:47:30 +0300, Mikhail Kobuk wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/2] phy: marvell: a3700-comphy: Fix out of bounds read
      commit: e4308bc22b9d46cf33165c9dfaeebcf29cd56f04
[2/2] phy: marvell: a3700-comphy: Fix hardcoded array size
      commit: 627207703b73615653eea5ab7a841d5b478d961e

Best regards,
-- 
~Vinod



-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-05 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-21 16:47 [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Mikhail Kobuk
2024-03-21 16:47 ` [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Mikhail Kobuk
2024-03-22  7:26   ` Miquel Raynal
2024-03-22  7:25 ` [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Miquel Raynal
2024-04-05 17:08 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).