lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aWg3vOBK4uKwyRp4@zatzit>
Date: Thu, 15 Jan 2026 11:41:32 +1100
From: David Gibson <david@...son.dropbear.id.au>
To: Herve Codina <herve.codina@...tlin.com>
Cc: Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk@...nel.org>,
	Conor Dooley <conor+dt@...nel.org>,
	Ayush Singh <ayush@...gleboard.org>,
	Geert Uytterhoeven <geert@...ux-m68k.org>,
	devicetree-compiler@...r.kernel.org, devicetree@...r.kernel.org,
	linux-kernel@...r.kernel.org, devicetree-spec@...r.kernel.org,
	Hui Pu <hui.pu@...ealthcare.com>,
	Ian Ray <ian.ray@...ealthcare.com>,
	Luca Ceresoli <luca.ceresoli@...tlin.com>,
	Thomas Petazzoni <thomas.petazzoni@...tlin.com>
Subject: Re: [RFC PATCH 07/77] livetree: Improve get_node_by_phandle()

On Mon, Jan 12, 2026 at 03:18:57PM +0100, Herve Codina wrote:
> get_node_by_phandle() allows to get a node based on its phandle value.
> It checks the phandle value against value available in internal node
> structure.
> 
> This internal phandle value is updated during process_check() and so,
> get_node_by_phandle() cannot give correct results before the
> process_check() call.
> 
> Improve get_node_by_phandle() to look at node phandle properties when
> the internal phandle value is not valid.
> 
> This allows to return a correct matching node even if process_check()
> was not called yet.
> 
> With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed
> to update internal phandle references before the call to process_check().
> Indeed, this tag allows to identify phandles and internal references
> need to be updated based on the phandle value before the
> process_check() call.

Having two entirely different paths for get_node_by_phandle() is
really ugly.

I suspect a better approach would be to special case updates to the
internal phandle field as we parse the phandle properties, rather than
doing it as a batch during the checks.

> Signed-off-by: Herve Codina <herve.codina@...tlin.com>
> ---
>  livetree.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/livetree.c b/livetree.c
> index f328824..9b67934 100644
> --- a/livetree.c
> +++ b/livetree.c
> @@ -609,16 +609,35 @@ struct node *get_node_by_label(struct node *tree, const char *label)
>  	return NULL;
>  }
>  
> +static cell_t get_node_phandle_existing(struct node *node)
> +{
> +	struct property *prop;
> +
> +	if (phandle_is_valid(node->phandle))
g> +		return node->phandle;
> +
> +	prop = get_property(node, "phandle");
> +	if (!prop) {
> +		prop = get_property(node, "linux,phandle");
> +		if (!prop)
> +			return 0;
> +	}
> +
> +	return propval_cell(prop);
> +}
> +
>  struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
>  {
>  	struct node *child, *node;
> +	cell_t tree_phandle;
>  
>  	if (!phandle_is_valid(phandle)) {
>  		assert(generate_fixups);
>  		return NULL;
>  	}
>  
> -	if (tree->phandle == phandle) {
> +	tree_phandle = get_node_phandle_existing(tree);

It's especially nasty that we call the expensive version first, then
fall back to the cheap version...

> +	if (phandle_is_valid(tree_phandle) && tree_phandle == phandle) {
>  		if (tree->deleted)
>  			return NULL;
>  		return tree;
> -- 
> 2.52.0
> 
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ