🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #1311

Re: [PATCH net-next v3 2/2] net: pcs: rzn1-miic: Validate dtb configuration values

#1311
From: Simon Horman
Date: Fri, 09 Oct 2026 14:26
60 lines
7821 bytes
On Tue, Oct 06, 2026 at 09:48:12AM -0700, Kyle Hendry via B4 Relay 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.
> 
> Signed-off-by: Kyle Hendry <khendry@reliablecontrols.com>
> ---
>  drivers/net/pcs/pcs-rzn1-miic.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
> index 31716241b58f..10622eb654d2 100644
> --- a/drivers/net/pcs/pcs-rzn1-miic.c
> +++ b/drivers/net/pcs/pcs-rzn1-miic.c
> @@ -693,16 +693,40 @@ 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)
> -		dt_val[0] = conf;
> +	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;
> +		} else {
> +			dt_val[0] = conf;
> +		}
> +	}

Hi Kyle,

Please drop the else arm here, it is unnecessary.

Doing so will move the code into the preferred style
of handling errors conditionally while keeping
the main thread of execution outside (extra) conditions.

(Completely untested, but I mean like this.)

	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;
	}

With that change, feel free to add:

Reviewed-by: Simon Horman <horms@kernel.org>

-- 
pw-bot: changes-requested
Technical Details
Message-ID: <20261009142626.GE83879@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-343743-linux-kernel-netdev=dewy.ru
References: <20261006-miic-validate-dtb-v3-v3-0-68617b3dca5c@reliablecontrols.com> <20261006-miic-validate-dtb-v3-v3-2-68617b3dca5c@reliablecontrols.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-343743-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 2/2] net: pcs: rzn1-miic: Validate dtb
 configuration values
Date: Fri, 9 Oct 2026 15:26:26 +0100
Organization: Usenet Network
Message-ID: <20261009142626.GE83879@horms.kernel.org>
References: <20261006-miic-validate-dtb-v3-v3-0-68617b3dca5c@reliablecontrols.com>
 <20261006-miic-validate-dtb-v3-v3-2-68617b3dca5c@reliablecontrols.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="1123789"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pYHPkUBVeQyvSchiuF/yPE6s0YY= sha256:p8U0fUj4tX6eIg5qr4kL8JEB10xMKt36NTX8myRVNQM=
	sha1:dnEN99SfFOJeEevyvEdWgunRxA4= sha256:yZfXiAKYWiM2nswSVrYHaJJpO4HruRoaKZJFUk12WTU=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id CBEC910F6F4; Fri,  9 Oct 2026 17:26:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.341
X-Spam-Status: No, score=-1.341 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jMzXzVPgRMUR;
	Fri,  9 Oct 2026 17:26:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-343743-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id A5E2B10F6EC; Fri,  9 Oct 2026 17:26:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id 8C4D7301E9; Fri,  9 Oct 2026 14:26:34 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 865373C109F;
	Fri,  9 Oct 2026 14:26:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D+rQK5js"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33C573431F8;
	Fri,  9 Oct 2026 14:26:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791555992; cv=none; b=GI5zDOGh26gBStgxRpmyl44fWK0bjIHuupmKZbagDnD5URQS1UWoNHVq+E+aQPU45aU59ONz9kQdWDuzSSMavvtvvmLtg7oYZLQ1948veVaw+rtFWOp5ZfU831DhYDyp4CBqGRLrfNaw+n05o3/Z3ttN+enNzS3hq9ILGBnFZRo=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791555992; c=relaxed/simple;
	bh=jsgXyspX+A1abRVIuSI4vKkw0YZqKn+DWQ6nHxC+fjg=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=ND5QIjtmEsO5HuNO+xEXJ6kGjGFyFdg6lBrNMsx6FCfVU0PLWU8T/I2e5jaWvQiyBUheOPARdx0y8bg40Y8mn148m+XcCC0BDS6+HGl+ZowIKlFWaaqGzlpQlvTq92WompEbidhfE45YyFLxrjsetxhjtcFnPEzNDMUNwS9GPbY=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D+rQK5js; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7410E1F00893;
	Fri,  9 Oct 2026 14:26:28 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1791555991;
	bh=pM5q2YWqVU6exVxt+Fkb1ukGHEwP5IPEUe1WbHW/XFA=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=D+rQK5jsExPJqhyjzg0n2LyXmgwKcz7HRkEYRChcdrjzmD/z19VcVaCfbu7I1am3F
	 4KtOPuUvOO8JXz1hRWnCSEQo6QLt4nhMDl234gkNGzFR2K6flUXfKU2ymU4KF353Lt
	 j3AU4T3twEKAva07aZONUU/L48rU1viaD633VuZSwdazl8OU9hI8tX3PwBKnUoi1kY
	 oM+anowbAvGvPEiBS2mmZLoKDi1XIZVmkzgHXXeQYDBfQwytQ19eVC9GXLVHi0HckT
	 ROz7J5iegBtpbtq4gip5kKNRkQGGqZdIEYUzg4100j+skmPB/WCwZvhbIYYURBqjHk
	 kTtm9FWrF3BMw==
X-Cc: Clément Léger <clement.leger@bootlin.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Magnus Damm <magnus.damm@gmail.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
	linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <20261006-miic-validate-dtb-v3-v3-2-68617b3dca5c@reliablecontrols.com>