Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values
@ 2026-10-14 15:32 Kyle Hendry via B4 Relay
  2026-10-14 15:32 ` [PATCH net-next v4 1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H Kyle Hendry via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Kyle Hendry via B4 Relay @ 2026-10-14 15:32 UTC (permalink / raw)
  To: Clément Léger, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Geert Uytterhoeven, Magnus Damm, Lad Prabhakar
  Cc: linux-renesas-soc, netdev, linux-kernel, Kyle Hendry,
	Simon Horman

This series addresses issues found when reviewing another fix:
https://lore.kernel.org/netdev/20260915-rzn1-miic-fix-array-v5-1-b7173fd5b97d@reliablecontrols.com/

Invalid values from the dtb could cause out of bounds array access. Checking
the values as they're parsed should prevent this.

Changes in v4:
- Remove unnecessary else
- Link to v3: https://lore.kernel.org/r/20261006-miic-validate-dtb-v3-v3-0-68617b3dca5c@reliablecontrols.com

Changes in v3:
- Squash patches changing miic_port_max
- Change name of miic_port_max to miic_port_last
- Remove fixes tags
- Add another check for configuration value of miic-switch-portin
- Link to v2: https://lore.kernel.org/r/20260928-miic-validate-dtb-v2-0-1ee3d33748e9@reliablecontrols.com/

Changes in v2:
- Simplify fixes by making miic_port_max the last documented port number
- Add fixes tags
- Link to v1: https://lore.kernel.org/r/20260925-miic-validate-dtb-v1-0-3a6db9bb75ec@reliablecontrols.com

Signed-off-by: Kyle Hendry <khendry@reliablecontrols.com>
---
Kyle Hendry (2):
      net: pcs: rzn1-miic: Update port numbering for RZ/T2H
      net: pcs: rzn1-miic: Validate dtb configuration values

 drivers/net/pcs/pcs-rzn1-miic.c | 42 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)
---
base-commit: 05b5019b01fb9443b09ae4ed34af1135a80a84c8
change-id: 20261005-miic-validate-dtb-v3-cf31820cb1e9

Best regards,
-- 
Kyle Hendry <khendry@reliablecontrols.com>



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

* [PATCH net-next v4 1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H
  2026-10-14 15:32 [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
@ 2026-10-14 15:32 ` Kyle Hendry via B4 Relay
  2026-10-14 15:32 ` [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
  2026-10-20 13:40 ` [PATCH net-next v4 0/2] " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Kyle Hendry via B4 Relay @ 2026-10-14 15:32 UTC (permalink / raw)
  To: Clément Léger, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Geert Uytterhoeven, Magnus Damm, Lad Prabhakar
  Cc: linux-renesas-soc, netdev, linux-kernel, Kyle Hendry,
	Simon Horman

From: Kyle Hendry <khendry@reliablecontrols.com>

The port numbers on the RZ/T2H are documented as 0 to 3. Update the info
structure and change the member name to miic_port_last to be more accurate.

This value was being used as the number of miic registers when setting
default values. Add logic to get the total port count and loop over that.

Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Kyle Hendry <khendry@reliablecontrols.com>
---
 drivers/net/pcs/pcs-rzn1-miic.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
index 3aa513467060..31716241b58f 100644
--- a/drivers/net/pcs/pcs-rzn1-miic.c
+++ b/drivers/net/pcs/pcs-rzn1-miic.c
@@ -222,7 +222,7 @@ enum miic_type {
  * @index_to_string: String representations of the index values
  * @index_to_string_count: Number of entries in the index_to_string array
  * @miic_port_start: MIIC port start number
- * @miic_port_max: Maximum MIIC supported
+ * @miic_port_last: MIIC port last number
  * @sw_mode_mask: Switch mode mask
  * @reset_ids: Reset names array
  * @reset_count: Number of entries in the reset_ids array
@@ -240,7 +240,7 @@ struct miic_of_data {
 	const char * const *index_to_string;
 	u8 index_to_string_count;
 	u8 miic_port_start;
-	u8 miic_port_max;
+	u8 miic_port_last;
 	u8 sw_mode_mask;
 	const char * const *reset_ids;
 	u8 reset_count;
@@ -485,7 +485,7 @@ struct phylink_pcs *miic_create(struct device *dev, struct device_node *np)
 
 	miic = platform_get_drvdata(pdev);
 	of_data = miic->of_data;
-	if (port > of_data->miic_port_max || port < of_data->miic_port_start) {
+	if (port > of_data->miic_port_last || port < of_data->miic_port_start) {
 		put_device(&pdev->dev);
 		return ERR_PTR(-EINVAL);
 	}
@@ -523,6 +523,7 @@ EXPORT_SYMBOL(miic_destroy);
 static int miic_init_hw(struct miic *miic, u32 cfg_mode)
 {
 	u8 sw_mode_mask = miic->of_data->sw_mode_mask;
+	int num_ports;
 	int port;
 
 	/* Unlock write access to accessory registers (cf datasheet). If this
@@ -538,7 +539,10 @@ static int miic_init_hw(struct miic *miic, u32 cfg_mode)
 	miic_reg_writel(miic, MIIC_MODCTRL,
 			((cfg_mode << __ffs(sw_mode_mask)) & sw_mode_mask));
 
-	for (port = 0; port < miic->of_data->miic_port_max; port++) {
+	num_ports = miic->of_data->miic_port_last -
+		miic->of_data->miic_port_start + 1;
+
+	for (port = 0; port < num_ports; port++) {
 		miic_converter_enable(miic, port, 0);
 		/* Disable speed/duplex control from these registers, datasheet
 		 * says switch registers should be used to setup switch port
@@ -825,7 +829,7 @@ static struct miic_of_data rzn1_miic_of_data = {
 	.index_to_string = index_to_string,
 	.index_to_string_count = ARRAY_SIZE(index_to_string),
 	.miic_port_start = 1,
-	.miic_port_max = 5,
+	.miic_port_last = 5,
 	.sw_mode_mask = GENMASK(4, 0),
 	.init_unlock_lock_regs = true,
 	.miic_write = miic_reg_writel_unlocked,
@@ -841,7 +845,7 @@ static struct miic_of_data rzt2h_miic_of_data = {
 	.index_to_string = rzt2h_index_to_string,
 	.index_to_string_count = ARRAY_SIZE(rzt2h_index_to_string),
 	.miic_port_start = 0,
-	.miic_port_max = 4,
+	.miic_port_last = 3,
 	.sw_mode_mask = GENMASK(2, 0),
 	.reset_ids = rzt2h_reset_ids,
 	.reset_count = ARRAY_SIZE(rzt2h_reset_ids),

-- 
2.43.0



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

* [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values
  2026-10-14 15:32 [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
  2026-10-14 15:32 ` [PATCH net-next v4 1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H Kyle Hendry via B4 Relay
@ 2026-10-14 15:32 ` Kyle Hendry via B4 Relay
  2026-10-14 16:43   ` Lad, Prabhakar
  2026-10-20 13:40 ` [PATCH net-next v4 0/2] " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Kyle Hendry via B4 Relay @ 2026-10-14 15:32 UTC (permalink / raw)
  To: Clément Léger, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Geert Uytterhoeven, Magnus Damm, Lad Prabhakar
  Cc: linux-renesas-soc, netdev, linux-kernel, Kyle Hendry,
	Simon Horman

From: Kyle Hendry <khendry@reliablecontrols.com>

Bad configuration values from the dtb could result in out of bounds array
access. Verify parsed values are within range for the SoC and fail the
probe if invalid.

Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Kyle Hendry <khendry@reliablecontrols.com>
---
 drivers/net/pcs/pcs-rzn1-miic.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
index 31716241b58f..f8bafce26bf1 100644
--- a/drivers/net/pcs/pcs-rzn1-miic.c
+++ b/drivers/net/pcs/pcs-rzn1-miic.c
@@ -693,16 +693,39 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg)
 	memset(dt_val, MIIC_MODCTRL_CONF_NONE,
 	       sizeof(*dt_val) * miic->of_data->conf_conv_count);
 
-	if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0)
+	if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0) {
+		if (conf >= miic->of_data->conf_to_string_count) {
+			dev_err(miic->dev, "Port input configuration out of range: %d\n",
+				conf);
+			ret = -EINVAL;
+			goto err;
+		}
 		dt_val[0] = conf;
+	}
 
 	for_each_available_child_of_node(np, conv) {
 		if (of_property_read_u32(conv, "reg", &port))
 			continue;
 
+		if (port < miic->of_data->miic_port_start ||
+		    port > miic->of_data->miic_port_last) {
+			dev_err(miic->dev, "Port number out of range: %d\n", port);
+			of_node_put(conv);
+			ret = -EINVAL;
+			goto err;
+		}
+
 		if (of_property_read_u32(conv, "renesas,miic-input", &conf))
 			continue;
 
+		if (conf >= miic->of_data->conf_to_string_count) {
+			dev_err(miic->dev, "Port %d configuration out of range: %d\n",
+				port, conf);
+			of_node_put(conv);
+			ret = -EINVAL;
+			goto err;
+		}
+
 		/* Adjust for 0 based index */
 		dt_val[port + !miic->of_data->miic_port_start] = conf;
 
@@ -712,6 +735,7 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg)
 	}
 
 	ret = miic_match_dt_conf(miic, dt_val, mode_cfg);
+err:
 	kfree(dt_val);
 
 	return ret;

-- 
2.43.0



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

* Re: [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values
  2026-10-14 15:32 ` [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
@ 2026-10-14 16:43   ` Lad, Prabhakar
  0 siblings, 0 replies; 5+ messages in thread
From: Lad, Prabhakar @ 2026-10-14 16:43 UTC (permalink / raw)
  To: khendry
  Cc: Clément Léger, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Geert Uytterhoeven, Magnus Damm, Lad Prabhakar,
	linux-renesas-soc, netdev, linux-kernel, Simon Horman

On Wed, Oct 14, 2026 at 4:37 PM Kyle Hendry via B4 Relay
<devnull+khendry.reliablecontrols.com@kernel.org> wrote:
>
> From: Kyle Hendry <khendry@reliablecontrols.com>
>
> Bad configuration values from the dtb could result in out of bounds array
> access. Verify parsed values are within range for the SoC and fail the
> probe if invalid.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
> Signed-off-by: Kyle Hendry <khendry@reliablecontrols.com>
> ---
>  drivers/net/pcs/pcs-rzn1-miic.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Cheers,
Prabhakar

> diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
> index 31716241b58f..f8bafce26bf1 100644
> --- a/drivers/net/pcs/pcs-rzn1-miic.c
> +++ b/drivers/net/pcs/pcs-rzn1-miic.c
> @@ -693,16 +693,39 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg)
>         memset(dt_val, MIIC_MODCTRL_CONF_NONE,
>                sizeof(*dt_val) * miic->of_data->conf_conv_count);
>
> -       if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0)
> +       if (of_property_read_u32(np, "renesas,miic-switch-portin", &conf) == 0) {
> +               if (conf >= miic->of_data->conf_to_string_count) {
> +                       dev_err(miic->dev, "Port input configuration out of range: %d\n",
> +                               conf);
> +                       ret = -EINVAL;
> +                       goto err;
> +               }
>                 dt_val[0] = conf;
> +       }
>
>         for_each_available_child_of_node(np, conv) {
>                 if (of_property_read_u32(conv, "reg", &port))
>                         continue;
>
> +               if (port < miic->of_data->miic_port_start ||
> +                   port > miic->of_data->miic_port_last) {
> +                       dev_err(miic->dev, "Port number out of range: %d\n", port);
> +                       of_node_put(conv);
> +                       ret = -EINVAL;
> +                       goto err;
> +               }
> +
>                 if (of_property_read_u32(conv, "renesas,miic-input", &conf))
>                         continue;
>
> +               if (conf >= miic->of_data->conf_to_string_count) {
> +                       dev_err(miic->dev, "Port %d configuration out of range: %d\n",
> +                               port, conf);
> +                       of_node_put(conv);
> +                       ret = -EINVAL;
> +                       goto err;
> +               }
> +
>                 /* Adjust for 0 based index */
>                 dt_val[port + !miic->of_data->miic_port_start] = conf;
>
> @@ -712,6 +735,7 @@ static int miic_parse_dt(struct miic *miic, u32 *mode_cfg)
>         }
>
>         ret = miic_match_dt_conf(miic, dt_val, mode_cfg);
> +err:
>         kfree(dt_val);
>
>         return ret;
>
> --
> 2.43.0
>
>
>

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

* Re: [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values
  2026-10-14 15:32 [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
  2026-10-14 15:32 ` [PATCH net-next v4 1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H Kyle Hendry via B4 Relay
  2026-10-14 15:32 ` [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
@ 2026-10-20 13:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-20 13:40 UTC (permalink / raw)
  To: Kyle Hendry
  Cc: clement.leger, andrew, hkallweit1, linux, davem, edumazet, kuba,
	pabeni, geert+renesas, magnus.damm, prabhakar.mahadev-lad.rj,
	linux-renesas-soc, netdev, linux-kernel, horms

Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 14 Oct 2026 08:32:36 -0700 you wrote:
> This series addresses issues found when reviewing another fix:
> https://lore.kernel.org/netdev/20260915-rzn1-miic-fix-array-v5-1-b7173fd5b97d@reliablecontrols.com/
> 
> Invalid values from the dtb could cause out of bounds array access. Checking
> the values as they're parsed should prevent this.
> 
> Changes in v4:
> - Remove unnecessary else
> - Link to v3: https://lore.kernel.org/r/20261006-miic-validate-dtb-v3-v3-0-68617b3dca5c@reliablecontrols.com
> 
> [...]

Here is the summary with links:
  - [net-next,v4,1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H
    https://git.kernel.org/netdev/net-next/c/5af4c3f61791
  - [net-next,v4,2/2] net: pcs: rzn1-miic: Validate dtb configuration values
    https://git.kernel.org/netdev/net-next/c/585df8d1eed9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-10-20 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 15:32 [PATCH net-next v4 0/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
2026-10-14 15:32 ` [PATCH net-next v4 1/2] net: pcs: rzn1-miic: Update port numbering for RZ/T2H Kyle Hendry via B4 Relay
2026-10-14 15:32 ` [PATCH net-next v4 2/2] net: pcs: rzn1-miic: Validate dtb configuration values Kyle Hendry via B4 Relay
2026-10-14 16:43   ` Lad, Prabhakar
2026-10-20 13:40 ` [PATCH net-next v4 0/2] " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox