From: Mike McTernan <mikemcternan-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: "Pierre-Clément Tosi"
<ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Mike McTernan"
<mikemcternan-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH] libfdt: Validate alias property value is a valid string.
Date: Mon, 10 Oct 2022 11:03:28 +0100 [thread overview]
Message-ID: <20221010100328.2207018-1-mikemcternan@google.com> (raw)
Prevent circular alias resolution causing infinite recursion.
Signed-off-by: Mike McTernan <mikemcternan-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
libfdt/fdt_ro.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 9f6c551..870c4a5 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -525,13 +525,27 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
const char *fdt_get_alias_namelen(const void *fdt,
const char *name, int namelen)
{
+ const char *prop;
int aliasoffset;
+ int prop_len;
aliasoffset = fdt_path_offset(fdt, "/aliases");
if (aliasoffset < 0)
return NULL;
- return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
+ prop = fdt_getprop_namelen(fdt, aliasoffset, name, namelen, &prop_len);
+ if (prop && !can_assume(VALID_INPUT)) {
+ /* Validate the alias value. From the devicetree spec v0.3:
+ * "An alias value is a device path and is encoded as a string.
+ * The value representes the full path to a node, ..."
+ * A full path must start at the root to prevent recursion.
+ */
+ if (prop_len < 2 || *prop != '/' || strnlen(prop, prop_len) != prop_len - 1) {
+ prop = NULL;
+ }
+ }
+
+ return prop;
}
const char *fdt_get_alias(const void *fdt, const char *name)
--
2.38.0.rc2.412.g84df46c1b4-goog
next reply other threads:[~2022-10-10 10:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 10:03 Mike McTernan [this message]
[not found] ` <20221010100328.2207018-1-mikemcternan-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2023-05-14 6:50 ` [PATCH] libfdt: Validate alias property value is a valid string David Gibson
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=20221010100328.2207018-1-mikemcternan@google.com \
--to=mikemcternan-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=ptosi-hpIqsD4AKlfQT0dZR+AlfA@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).