From: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org,
Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
Subject: [PATCH] drivers: of: fix possible overflow
Date: Tue, 12 Nov 2024 14:54:52 +0200 [thread overview]
Message-ID: <20241112125452.333653-1-abdelrahmanyossef12@gmail.com> (raw)
while parsing the fdt header, the name of the begining node marked by
FDT_BEGIN_NODE that is part of the struct block moves out of the block
that results in heap-overflow.
So this patch checks if the length of name (maxlen) + the offset of
the struct block exceeds the size of the whole block.
Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
---
drivers/of/fdt.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 2c3ea31394..7dc8ee2529 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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 + f.off_dt_struct > f.size_dt_struct) {
+ ret = -ESPIPE;
+ goto err;
+ }
+
len = strnlen(name, maxlen + 1);
if (len > maxlen) {
ret = -ESPIPE;
--
2.43.0
next reply other threads:[~2024-11-12 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 12:54 Abdelrahman Youssef [this message]
2024-11-12 14:03 ` 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=20241112125452.333653-1-abdelrahmanyossef12@gmail.com \
--to=abdelrahmanyossef12@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.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