From: Herve Codina <herve.codina@bootlin.com>
To: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Cc: <devicetree-compiler@vger.kernel.org>,
David Gibson <david@gibson.dropbear.id.au>,
Rob Herring <robh@kernel.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>,
Michal Orzel <michal.orzel@amd.com>,
Bertrand Marquis <bertrand.marquis@arm.com>
Subject: Re: [PATCH] libfdt: Fix fdt_get_path() reading before the start of the buffer
Date: Thu, 1 Oct 2026 17:10:10 +0200 [thread overview]
Message-ID: <20261001171010.3715b028@bootlin.com> (raw)
In-Reply-To: <20261001121036.2910243-1-ayan.kumar.halder@amd.com>
Hi Ayan,
On Thu, 1 Oct 2026 13:10:36 +0100
Ayan Kumar Halder <ayan.kumar.halder@amd.com> wrote:
> fdt_get_path() walks the tree from the root, appending each node's name
> to the caller's buffer as it goes down and removing the last component
> again as it comes back up. It keeps the number of components currently
> in the buffer in pdepth, and removes components while pdepth is greater
> than the depth reported by fdt_next_node().
>
> fdt_next_node() reports that it has left the tree by taking the depth
> negative, but the offset it returns at that point is the offset of the
> end tag, which is not negative. The loop only tests the offset, so for a
fdt_next_node() returns an error (-FDT_ERR_NOTFOUND) when it reaches the
FDT_END tag [1].
I don't understand your point. Maybe I've missed something.
Can you clarify?
[1] https://github.com/dgibson/dtc/blob/7a1e017926004ecff5fce62d62d42ce9f3e00082/libfdt/fdt.c#L283
> nodeoffset at or past the end tag it runs one more time with a negative
> depth. pdepth still counts the components in the buffer, so the removal
> loop is asked to remove more components than are there: it takes the
> index down to zero and carries on scanning backwards for a '/' that is
> not in the buffer.
>
> Stop the walk when the depth shows it has left the tree. Offsets that
> far along are rejected by the error paths below in any case, so this
> does not change what callers see.
If fdt_next_node() can return an offset (positive value) which is not pointing
to a node without any errors (negative returned value), fdt_next_node() has
to be fixed not callers.
Can you give details leading fdt_next_node() returning a valid offset which
doesn't point to a node?
Best regards,
Hervé
>
> Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
> ---
> libfdt/fdt_ro.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 11f2e2e..32689c7 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -582,7 +582,7 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
> return -FDT_ERR_NOSPACE;
>
> for (offset = 0, depth = 0;
> - (offset >= 0) && (offset <= nodeoffset);
> + (offset >= 0) && (depth >= 0) && (offset <= nodeoffset);
> offset = fdt_next_node(fdt, offset, &depth)) {
> while (pdepth > depth) {
> do {
next prev parent reply other threads:[~2026-10-01 15:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 12:10 [PATCH] libfdt: Fix fdt_get_path() reading before the start of the buffer Ayan Kumar Halder
2026-10-01 15:10 ` Herve Codina [this message]
2026-10-01 17:18 ` Halder, Ayan Kumar
2026-10-02 9:28 ` Herve Codina
2026-10-06 2:59 ` David Gibson
2026-10-08 12:15 ` Simon Glass
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=20261001171010.3715b028@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=bertrand.marquis@arm.com \
--cc=david@gibson.dropbear.id.au \
--cc=devicetree-compiler@vger.kernel.org \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=robh@kernel.org \
--cc=sstabellini@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.