mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: AbdelRahman Yossef <abdelrahmanyossef12@gmail.com>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] of: fdt: fix possible overflow during parsing of fdt
Date: Wed, 13 Nov 2024 03:13:59 +0200	[thread overview]
Message-ID: <CABwgSGYBOuXY9onePu9tcp5ToDjYDJc9A2X-UVuVZJATra3yeA@mail.gmail.com> (raw)
In-Reply-To: <383d6b94-1152-4257-b18c-9f31857944ca@pengutronix.de>

Hi,

> Changelog would've been nice. This also should have been v3 not v2


So should I write a new patch (v4) and add Changelog?

> Hmm is this + 1 correct? I am wondering if we should be dropping
> the + 1 here and make it maxlen <= 0 above.
>
> What do you think?


Well, I think the + 1 is unnecessary here. But it's been there for
over 11 years, So maybe someone
has another opinion on the matter.

Cheers,
Abdelrahman


On Tue, Nov 12, 2024 at 9:56 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Hello Abdelrahman,
>
> Thanks for your patch.
>
> On 12.11.24 20:10, Abdelrahman Youssef wrote:
> > While fuzzing, the name marked by FDT_BEGIN_NODE sometimes extends beyond
> > the struct block area, Causing a heap-overflow.
> >
> > Since `maxlen` is an unsigned integer representing the length of name,
> > It can be negative, So it overflows to large numbers, Causing strnlen()
> > to overflow.
> >
> > So we can just change the type of maxlen to signed and check if it's negative.
> >
> > Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
> > ---
>
> Changelog would've been nice. This also should have been v3 not v2.
>
> >  drivers/of/fdt.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 2c3ea31394..d8d8a4922c 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -176,7 +176,7 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
> >       void *dt_strings;
> >       struct fdt_header f;
> >       int ret;
> > -     unsigned int maxlen;
> > +     int maxlen;
> >       const struct fdt_header *fdt = infdt;
> >
> >       ret = fdt_parse_header(infdt, size, &f);
> > @@ -210,6 +210,11 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, int size,
> >                       maxlen = (unsigned long)fdt + f.off_dt_struct +
> >                               f.size_dt_struct - (unsigned long)name;
> >
> > +                     if (maxlen < 0) {
> > +                             ret = -ESPIPE;
> > +                             goto err;
> > +                     }
> > +
> >                       len = strnlen(name, maxlen + 1);
>
> Hmm is this + 1 correct? I am wondering if we should be dropping
> the + 1 here and make it maxlen <= 0 above.
>
> What do you think?
>
> Cheers,
> Ahmad
>
> >                       if (len > maxlen) {>                            ret = -ESPIPE;
>
>
> --
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2024-11-13  1:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-12 19:10 Abdelrahman Youssef
2024-11-12 19:56 ` Ahmad Fatoum
2024-11-13  1:13   ` AbdelRahman Yossef [this message]
2024-11-13 12:17   ` Sascha Hauer
2024-11-13 12:37     ` AbdelRahman Yossef
2024-11-13 17:46       ` Ahmad Fatoum

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=CABwgSGYBOuXY9onePu9tcp5ToDjYDJc9A2X-UVuVZJATra3yeA@mail.gmail.com \
    --to=abdelrahmanyossef12@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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