From: Marek Vasut <marek.vasut@mailbox.org>
To: Simon Glass <sjg@chromium.org>,
Marek Vasut <marek.vasut+renesas@mailbox.org>
Cc: u-boot@lists.denx.de, Adriano Cordova <adrianox@gmail.com>,
Andrew Goodbody <andrew.goodbody@linaro.org>,
Christian Marangi <ansuelsmth@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Sam Edwards <cfsworks@gmail.com>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 3/3] libfdt: Check fdt_offset_ptr() return value unconditionally
Date: Thu, 13 Nov 2025 22:48:36 +0100 [thread overview]
Message-ID: <8a4ba995-840a-41ed-b496-6c32965d4ce5@mailbox.org> (raw)
In-Reply-To: <CAFLszTgRxLTWjCCbxxme9XtG2E80CrYOesry_86YuagL8uPJ-w@mail.gmail.com>
On 11/13/25 8:33 PM, Simon Glass wrote:
Hello Simon,
>> The fdt_offset_ptr() may return NULL pointer, check the return
>> value from fdt_offset_ptr() for NULL unconditionally to prevent
>> sandbox crashes.
>>
>> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
>> ---
>> Cc: Adriano Cordova <adrianox@gmail.com>
>> Cc: Andrew Goodbody <andrew.goodbody@linaro.org>
>> Cc: Christian Marangi <ansuelsmth@gmail.com>
>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>> Cc: Patrice Chotard <patrice.chotard@foss.st.com>
>> Cc: Sam Edwards <cfsworks@gmail.com>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
>> Cc: u-boot@lists.denx.de
>> ---
>> scripts/dtc/libfdt/fdt.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c
>> index 95f644c31f9..d16cc3d4730 100644
>> --- a/scripts/dtc/libfdt/fdt.c
>> +++ b/scripts/dtc/libfdt/fdt.c
>> @@ -168,7 +168,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
>>
>> *nextoffset = -FDT_ERR_TRUNCATED;
>> tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
>> - if (!can_assume(VALID_DTB) && !tagp)
>> + if (!tagp)
>> return FDT_END; /* premature end */
>> tag = fdt32_to_cpu(*tagp);
>> offset += FDT_TAGSIZE;
>> @@ -186,7 +186,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
>>
>> case FDT_PROP:
>> lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
>> - if (!can_assume(VALID_DTB) && !lenp)
>> + if (!lenp)
>> return FDT_END; /* premature end */
>>
>> len = fdt32_to_cpu(*lenp);
>> --
>> 2.51.0
>>
>
> The can_assume() is there to be respected and helps to reduce code
> size. What problem are you actually seeing?
fdt_offset_ptr() can return NULL, and it does in test_spl on sandbox if
I recall it right, because the U-Boot code passes in offsets which can
not be resolved properly and that makes fdt_offset_ptr() return NULL and
trigger SIGSEGV when it is dereferenced here.
next prev parent reply other threads:[~2025-11-13 21:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 12:21 [PATCH 0/3] Synchronize DTC to 1.7.2 Marek Vasut
2025-11-13 12:21 ` [PATCH 1/3] dm: core: Check ofnode_to_offset() return value Marek Vasut
2025-11-13 19:33 ` Simon Glass
2025-11-13 21:51 ` Marek Vasut
2025-11-13 22:46 ` Simon Glass
2025-11-14 5:17 ` Marek Vasut
2025-11-14 14:36 ` Tom Rini
2025-11-16 0:16 ` Marek Vasut
2025-11-16 14:13 ` Tom Rini
2025-11-16 21:28 ` Marek Vasut
2025-11-17 14:14 ` Tom Rini
2025-11-13 12:21 ` [PATCH 2/3] scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c Marek Vasut
2025-11-13 12:21 ` [PATCH 3/3] libfdt: Check fdt_offset_ptr() return value unconditionally Marek Vasut
2025-11-13 19:33 ` Simon Glass
2025-11-13 21:48 ` Marek Vasut [this message]
2025-11-13 23:34 ` Simon Glass
2025-11-20 4:20 ` Marek Vasut
2025-11-13 17:57 ` [PATCH 0/3] Synchronize DTC to 1.7.2 Tom Rini
2025-11-13 18:40 ` Marek Vasut
2025-11-13 18:49 ` Tom Rini
2025-11-13 19:32 ` Simon Glass
2025-11-15 23:23 ` Marek Vasut
2025-11-16 14:11 ` Tom Rini
2025-11-16 21:48 ` Marek Vasut
2025-11-17 18:40 ` Tom Rini
2025-11-19 21:31 ` Marek Vasut
2025-11-20 15:54 ` Tom Rini
2025-11-20 20:14 ` Marek Vasut
2025-11-21 19:55 ` Tom Rini
2025-12-02 17:46 ` Marek Vasut
2025-12-02 18:06 ` Tom Rini
2025-12-02 18:35 ` Marek Vasut
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=8a4ba995-840a-41ed-b496-6c32965d4ce5@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=adrianox@gmail.com \
--cc=andrew.goodbody@linaro.org \
--cc=ansuelsmth@gmail.com \
--cc=cfsworks@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=patrice.chotard@foss.st.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/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