All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Elijah Conners <business@elijahpepe.com>
Cc: u-boot <u-boot@lists.denx.de>, trini <trini@konsulko.com>
Subject: Re: [PATCH] fdt: change splicing offset detection
Date: Fri, 21 Oct 2022 19:06:38 -0600	[thread overview]
Message-ID: <CAPnjgZ1b8CZv9f7=+yUTZN6y4-yc5freOS7TQH7quZ8TTsDSkA@mail.gmail.com> (raw)
In-Reply-To: <183780f2842.101060331203165.2781699063163773236@elijahpepe.com>

Hi Elijah,

On Sun, 25 Sept 2022 at 22:30, Elijah Conners <business@elijahpepe.com> wrote:
>
> In fdt_rw.c, -FDT_ERR_BADOFFSET is returned when either the sum of the
> old
> length and the splice point are less than the splice point, or when the
> sum of the old length and the splice point exceed the end of the
> pointer.
> Adding an int and a pointer may result in a pointer overflow, an
> undefined behavior, which means that the result of this if statement
> can't be recovered from. Checking if the old length exceeds the end of
> the pointer minus the pointer is a much safer check.
>
> Signed-off-by: Elijah Conners <business@elijahpepe.com>
> ---
>  scripts/dtc/libfdt/fdt_rw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c
> index 2eb2b38703..672b74ae7a 100644
> --- a/scripts/dtc/libfdt/fdt_rw.c
> +++ b/scripts/dtc/libfdt/fdt_rw.c
> @@ -58,7 +58,7 @@ static int fdt_splice_(void *fdt, void *splicepoint, int oldlen, int newlen)
>         char *p = splicepoint;
>         char *end = (char *)fdt + fdt_data_size_(fdt);
>
> -       if (((p + oldlen) < p) || ((p + oldlen) > end))
> +       if (oldlen >= (end - p))
>                 return -FDT_ERR_BADOFFSET;
>         if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))
>                 return -FDT_ERR_BADOFFSET;
> --
> 2.29.2.windows.2

Granted this function is not documented but I don't think the new
check is correct. I did not know that pointer overflow was undefined,
but perhaps there is another way to solve this? This breaks CI.

I suggest sending this to the devicetreee-compiler mailing list and
resolving it there first.

Regards,
Simon

      reply	other threads:[~2022-10-22  1:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  4:30 [PATCH] fdt: change splicing offset detection Elijah Conners
2022-10-22  1:06 ` Simon Glass [this message]

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='CAPnjgZ1b8CZv9f7=+yUTZN6y4-yc5freOS7TQH7quZ8TTsDSkA@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=business@elijahpepe.com \
    --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.