Skip to contentSkip to conversation

net: pse-pd: Fix out of bound for loop

PATCH Applied Kory Maincent 4 participants 4 messages Oct 15, 2024 – Oct 20, 2024

Subsystems (3)
lore
Share & tools
lore

Kory Maincent

author maintainer
#0 lore raw

PATCH 1/1 net: pse-pd: Fix out of bound for loop

Adjust the loop limit to prevent out-of-bounds access when iterating over PI structures. The loop should not reach the index pcdev->nr_lines since we allocate exactly pcdev->nr_lines number of PI structures. This fix ensures proper bounds are maintained during iterations.

Fixes 9be9567a7c59 ("net: pse-pd: Add support for PSE PIs")
---
 drivers/net/pse-pd/pse_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/pse-pd/pse_core.c +2 -2
index f8e6854781e6..2906ce173f66 100644
@@ -113,7 +113,7 @@ static void pse_release_pis(struct pse_controller_dev *pcdev)
 {
 	int i;
 
-	for (i = 0; i <= pcdev->nr_lines; i++) {
+	for (i = 0; i < pcdev->nr_lines; i++) {
 		of_node_put(pcdev->pi[i].pairset[0].np);
 		of_node_put(pcdev->pi[i].pairset[1].np);
 		of_node_put(pcdev->pi[i].np);
@@ -647,7 +647,7 @@ static int of_pse_match_pi(struct pse_controller_dev *pcdev,
 {
 	int i;
 
-	for (i = 0; i <= pcdev->nr_lines; i++) {
+	for (i = 0; i < pcdev->nr_lines; i++) {
 		if (pcdev->pi[i].np == np)
 			return i;
 	}
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kory Maincent

Adjust the loop limit to prevent out-of-bounds access when iterating over PI structures. The loop should not reach the index pcdev->nr_lines since we allocate exactly pcdev->nr_lines number of PI structures. This fix ensures proper bounds are maintained during iterations.

Fixes 9be9567a7c59 ("net: pse-pd: Add support for PSE PIs")
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Kory Maincent
Quoted 7 lines · Kory Maincent

Adjust the loop limit to prevent out-of-bounds access when iterating over PI structures. The loop should not reach the index pcdev->nr_lines since we allocate exactly pcdev->nr_lines number of PI structures. This fix ensures proper bounds are maintained during iterations.

Fixes 9be9567a7c59 ("net: pse-pd: Add support for PSE PIs")

Thank you!

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#3 lore raw
In reply to Kory Maincent
This patch was applied to netdev/net.git (main) by Andrew Lunn <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Andrew Lunn <[email protected]>:

Quoted 9 lines · On Tue, 15 Oct 2024 15:02:54 +0200 you wrote:

Adjust the loop limit to prevent out-of-bounds access when iterating over PI structures. The loop should not reach the index pcdev->nr_lines since we allocate exactly pcdev->nr_lines number of PI structures. This fix ensures proper bounds are maintained during iterations.

Fixes 9be9567a7c59 ("net: pse-pd: Add support for PSE PIs")

[...]

Here is the summary with links:
- [net] net: pse-pd: Fix out of bound for loop

    https://git.kernel.org/netdev/net/c/f2767a41959e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html