devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Beisswenger <johannes.beisswenger-QHh2hmjso9JBDgjK7y7TUQ@public.gmane.org>
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Johannes Beisswenger
	<johannes.beisswenger-QHh2hmjso9JBDgjK7y7TUQ@public.gmane.org>
Subject: [PATCH 1/3] checks: Fix segmentation fault in check_graph_node
Date: Fri, 28 Apr 2023 15:38:32 +0200	[thread overview]
Message-ID: <20230428133834.78178-1-johannes.beisswenger@cetitec.com> (raw)

Dts files which contain an 'endpoint' node as a direct child of the
root node cause a segmentation fault inside check_graph_node(). This
type of error can easily happen when a 'remote-endpoint' property is
accidentally placed outside the corresponding endpoint and port nodes.

Example with 'endpoint' node:
/dts-v1/;
/ {	endpoint {};  };

Example with remote-endpoint property:
/dts-v1/;
/ {
	foo {
                remote-endpoint = <0xdeadbeef>;
	};
};

Signed-off-by: Johannes Beisswenger <johannes.beisswenger-QHh2hmjso9JBDgjK7y7TUQ@public.gmane.org>
---

Hello,

this patch series is equivalent to the following GitHub pull request https://github.com/dgibson/dtc/pull/92
which also contains a short summary of the issue.
In short: the segmentation fault happens because check_graph_node() dereferences
node->parent without checking whether it is NULL.

The actual code changes are quite small, nevertheless please let me know if there are any issues.

Best regards
Johannes Beisswenger

CETITEC GmbH
Mannheimer Str. 17
D-75179 Pforzheim, Germany 


 checks.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/checks.c b/checks.c
index 16bc7f6..8ed7a60 100644
--- a/checks.c
+++ b/checks.c
@@ -1767,6 +1767,11 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti,
 		      get_property(child, "remote-endpoint")))
 			continue;
 
+                /* The root node cannot be a port */
+		if (!node->parent) {
+			FAIL(c, dti, node, "root node contains endpoint node '%s', potentially misplaced remote-endpoint property", child->name);
+			continue;
+		}
 		node->bus = &graph_port_bus;
 
 		/* The parent of 'port' nodes can be either 'ports' or a device */
-- 
2.40.0


             reply	other threads:[~2023-04-28 13:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 13:38 Johannes Beisswenger [this message]
     [not found] ` <20230428133834.78178-1-johannes.beisswenger-QHh2hmjso9JBDgjK7y7TUQ@public.gmane.org>
2023-04-28 13:38   ` [PATCH 2/3] tests: Add test cases for bad endpoint node and remote-endpoint prop checks Johannes Beisswenger
2023-04-28 13:38   ` [PATCH 3/3] checks: Fix crash in graph_child_address if 'reg' cell size > 1 Johannes Beisswenger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230428133834.78178-1-johannes.beisswenger@cetitec.com \
    --to=johannes.beisswenger-qhh2hmjso9jbdgjk7y7tuq@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).