All of lore.kernel.org
 help / color / mirror / Atom feed
From: Elijah Conners <business@elijahpepe.com>
To: "u-boot" <u-boot@lists.denx.de>
Cc: "sjg" <sjg@chromium.org>, "trini" <trini@konsulko.com>
Subject: [PATCH] fdt: change splicing offset detection
Date: Sun, 25 Sep 2022 21:30:02 -0700	[thread overview]
Message-ID: <183780f2842.101060331203165.2781699063163773236@elijahpepe.com> (raw)
In-Reply-To: 

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

             reply	other threads:[~2022-09-26 11:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26  4:30 Elijah Conners [this message]
2022-10-22  1:06 ` [PATCH] fdt: change splicing offset detection 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=183780f2842.101060331203165.2781699063163773236@elijahpepe.com \
    --to=business@elijahpepe.com \
    --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.