From: Aristo Chen <aristo.chen@canonical.com>
To: u-boot@lists.denx.de
Cc: Aristo Chen <aristo.chen@canonical.com>,
Tom Rini <trini@konsulko.com>,
Adriana Nicolae <adriana@arista.com>,
Richard Weinberger <richard@nod.at>,
Sam Protsenko <semen.protsenko@linaro.org>
Subject: [PATCH v1 1/3] fdt_support: bound serialN alias length before copying to stack
Date: Mon, 25 May 2026 13:26:23 +0000 [thread overview]
Message-ID: <20260525132628.755148-2-aristo.chen@canonical.com> (raw)
In-Reply-To: <20260525132628.755148-1-aristo.chen@canonical.com>
fdt_fixup_stdout() reads the path stored in /aliases/serialN with
fdt_getprop() and then memcpys it into a fixed 256-byte stack buffer.
The length returned by libfdt is the raw on-disk property size and is
not bounded by any console-path convention, so an oversized property
in a malformed or untrusted devicetree overflows the buffer with
attacker-controlled length and contents. The "/* long enough */"
comment next to tmp[] codifies an unchecked assumption.
Reject lengths that exceed sizeof(tmp) with a warning and return
-FDT_ERR_NOSPACE. The fixup runs during fdt_chosen() on every booted
kernel when CONFIG_OF_STDOUT_VIA_ALIAS is enabled, and when the OS
devicetree is not signature-verified the property is reachable from an
attacker-influenced blob.
Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
---
boot/fdt_support.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 1c215e548db..3e9445603ff 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -160,6 +160,12 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
goto noalias;
}
+ if (len > (int)sizeof(tmp)) {
+ printf("WARNING: %s: %s alias path too long (%d bytes)\n",
+ __func__, sername, len);
+ return -FDT_ERR_NOSPACE;
+ }
+
/* fdt_setprop may break "path" so we copy it to tmp buffer */
memcpy(tmp, path, len);
--
2.43.0
next prev parent reply other threads:[~2026-05-25 14:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 13:26 [PATCH v1 0/3] fdt_support: validate property lengths in chosen and dma-range fixups Aristo Chen
2026-05-25 13:26 ` Aristo Chen [this message]
2026-05-25 13:26 ` [PATCH v1 2/3] fdt_support: validate dma-ranges length in fdt_get_dma_range Aristo Chen
2026-05-25 13:26 ` [PATCH v1 3/3] fdt_support: prefer __func__ over __FUNCTION__ Aristo Chen
2026-05-25 14:43 ` Tom Rini
2026-05-25 14:48 ` [PATCH v1 0/3] fdt_support: validate property lengths in chosen and dma-range fixups 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=20260525132628.755148-2-aristo.chen@canonical.com \
--to=aristo.chen@canonical.com \
--cc=adriana@arista.com \
--cc=richard@nod.at \
--cc=semen.protsenko@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox