From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
To: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Cc: Simon Glass <sjg@chromium.org>, Sam Edwards <cfsworks@gmail.com>,
Anshul Dalal <anshuld@ti.com>,
u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 2/2] common/spl: guard against buffer overflow in spl_fit_get_image_name()
Date: Wed, 25 Jun 2025 01:05:59 +0200 [thread overview]
Message-ID: <3637667b-d7af-4e2c-b79d-fa20fda232ba@canonical.com> (raw)
In-Reply-To: <62500d98-9489-49e0-9c34-b8033c708687@iopsys.eu>
On 24.06.25 23:05, Mikhail Kshevetskiy wrote:
>
> On 24.06.2025 18:34, Heinrich Schuchardt wrote:
>> [You don't often get email from heinrich.schuchardt@canonical.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>>
>> A malformed FIT image could have an image name property that is not NUL
>> terminated. Reject such images.
>>
>> Reported-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
>> ---
>> common/spl/spl_fit.c | 10 ++++++++--
>> 1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
>> index e250c11ebbd..25f3c822a49 100644
>> --- a/common/spl/spl_fit.c
>> +++ b/common/spl/spl_fit.c
>> @@ -73,7 +73,7 @@ static int spl_fit_get_image_name(const struct spl_fit_info *ctx,
>> const char **outname)
>> {
>> struct udevice *sysinfo;
>> - const char *name, *str;
>> + const char *name, *str, *end;
>> __maybe_unused int node;
>> int len, i;
>> bool found = true;
>> @@ -83,11 +83,17 @@ static int spl_fit_get_image_name(const struct spl_fit_info *ctx,
>> debug("cannot find property '%s': %d\n", type, len);
>> return -EINVAL;
>> }
>> + /* A string property should be NUL terminated */
>> + end = name + len - 1;
>> + if (!len || *end) {
>> + debug("malformed property '%s'\n", type);
>> + return -EINVAL;
>> + }
>>
>> str = name;
>> for (i = 0; i < index; i++) {
>> str = strchr(str, '\0') + 1;
>> - if (!str || (str - name >= len)) {
>> + if (str > end) {
>
> and if strchr() will return NULL, then str will be equal to 1. In this
> case str will be less then end, so the loop will not terminate.
strchr() searching for NUL will never return NULL but search until it
hits NUL.
And as the patch adds checks that the buffer pointed to by str is NUL
terminated we will not read outside of the buffer.
Best regards
Heinrich
>
>
>> found = false;
>> break;
>> }
>> --
>> 2.48.1
>>
next prev parent reply other threads:[~2025-06-24 23:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 15:34 [PATCH 0/2] spl: fix error handling in spl_fit_get_image_name() Heinrich Schuchardt
2025-06-24 15:34 ` [PATCH 1/2] common/spl: Revert fix potential out of buffer access in spl_fit_get_image_name function Heinrich Schuchardt
2025-06-25 2:18 ` E Shattow
2025-06-24 15:34 ` [PATCH 2/2] common/spl: guard against buffer overflow in spl_fit_get_image_name() Heinrich Schuchardt
2025-06-24 21:02 ` Mikhail Kshevetskiy
2025-06-24 23:05 ` Heinrich Schuchardt
2025-06-24 21:05 ` Mikhail Kshevetskiy
2025-06-24 23:05 ` Heinrich Schuchardt [this message]
2025-06-24 23:07 ` Mikhail Kshevetskiy
2025-06-25 2:18 ` E Shattow
2025-06-25 2:00 ` [PATCH 0/2] spl: fix error handling " E Shattow
2025-06-26 19:32 ` Tom Rini
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=3637667b-d7af-4e2c-b79d-fa20fda232ba@canonical.com \
--to=heinrich.schuchardt@canonical.com \
--cc=anshuld@ti.com \
--cc=cfsworks@gmail.com \
--cc=mikhail.kshevetskiy@iopsys.eu \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.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 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.