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-next>] [day] [month] [year] [list]
Message-Id: <20250104210524.2137-1-gordoste@iinet.net.au>
Date: Sun,  5 Jan 2025 08:05:22 +1100
From: Stephen Gordon <gordoste@...et.net.au>
To: robh@...nel.org,
	saravanak@...gle.com
Cc: devicetree@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Stephen Gordon <gordoste@...et.net.au>
Subject: [PATCH 0/2] of_graph: Ensure graph nodes are returned in address order

Hi Rob,

As discussed in [1], the order of nodes returned by
of_graph_get_next_child() can differ depending which code built the
device tree. While the DT spec does not guarantee a specific node order,
some drivers may assume that node order will be the same across platforms.

One example is a driver accessing port@0 using a phandle, and then
iterating through the children using of_get_next_port(). This does not
work as intended when the tree is built using drivers/of/dynamic.c.

To avoid breakage, we create a new function to return children in address
order which can be used when the order is important. We then use this to
guarantee that graph nodes are returned in address order.

Testing was conducted using a custom module loading a graph and running
the following on each ``ports`` node.

	num = 0;
        for_each_child_of_node(ports, child) {
                of_property_read_u32(child, "reg", &id);
                data1[num++] = '0' + id;
        }

        num = 0;
        for_each_child_of_node_by_id(ports, child) {
                of_property_read_u32(child, "reg", &id);
                data2[num++] = '0' + id;
        }

        dev_dbg(dev, "ports%d: %s/%s", ports_id, data1, data2);

Test results:

[   62.074178] testgraph testgraph: ports8: 0/0
[   62.074183] testgraph testgraph: ports7: 9/9
[   62.074186] testgraph testgraph: ports6: /
[   62.074193] testgraph testgraph: ports5: 012/012
[   62.074199] testgraph testgraph: ports4: 102/012
[   62.074205] testgraph testgraph: ports3: 021/012
[   62.074211] testgraph testgraph: ports2: 201/012
[   62.074217] testgraph testgraph: ports1: 120/012
[   62.074223] testgraph testgraph: ports0: 210/012

These are all as expected. I can supply test files on request if you
would like to see the test cases, and perhaps suggest more.

Regards,
Stephen

[1] https://lore.kernel.org/linux-devicetree/CAL_JsqJdMy8h96crA2r66dHgrnQ9Rbm=g9i=hp9tZ5DLnbVpnA@mail.gmail.com/

Stephen Gordon (2):
  of: Add of_get_next_child_by_id()
  of: Convert of_graph_get_next_xx to return nodes in address order

 drivers/of/base.c     | 41 ++++++++++++++++++++++++++++++++++++++++-
 drivers/of/property.c |  4 ++--
 include/linux/of.h    | 12 ++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ