Skip to content

Fix crash caused by spurious aliases phandles. #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

uiopaubo
Copy link

If a device tree has specified a phandle for an aliases node, perhaps appearing as "aliases: aliases" in the device tree source, the phandle property will occur in the device tree data for the node.

If this property value is not decoded appropriately by prop_value, fdt_scan_node will raise a TypeError trying to use the inappropriately decoded value as a dictionary key when recording a phandle-to-node association. This effectively crashes the tool.

This modification lets prop_value decode property values normally instead of treating aliases nodes as a special case. Any phandle associated with such a node will then be reported by the validator in a message of the following form:

aliases: phandle: 26 is not of type 'array'

This is somewhat opaque and could arguably be reported in a more helpful way, but it indicates the presence of the spurious phandle instead of terminating abruptly.

If a device tree has specified a phandle for an aliases node,
perhaps appearing as "aliases: aliases" in the device tree source,
the phandle property will occur in the device tree data for the
node.

If this property value is not decoded appropriately by prop_value,
fdt_scan_node will raise a TypeError trying to use the
inappropriately decoded value as a dictionary key when recording
a phandle-to-node association. This effectively crashes the tool.

This modification lets prop_value decode property values normally
instead of treating aliases nodes as a special case. Any phandle
associated with such a node will then be reported by the validator
in a message of the following form:

aliases: phandle: 26 is not of type 'array'

This is somewhat opaque and could arguably be reported in a more
helpful way, but it indicates the presence of the spurious phandle
instead of terminating abruptly.

Signed-off-by: Paul Boddie <paul@boddie.org.uk>
@@ -82,7 +82,7 @@ def prop_value(validator, nodename, p):
data = bytes(p)
fmt = None

if nodename in {'__fixups__', 'aliases'}:
if nodename in {'__fixups__'}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to result in aliases property names possibly matching on some actual property name and getting the type wrong. You need to add an exclusion for 'phandle' (and perhaps 'linux,phandle' for completeness).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that it might then be easier to preserve the special case for 'aliases' and to test p.name for 'phandle', decoding the numeric data obtained for that property. This would cover the case of a phandle having been introduced without risking other breakage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants