From: Fabian Pflug <f.pflug@pengutronix.de>
To: oss-tools@pengutronix.de
Cc: Fabian Pflug <f.pflug@pengutronix.de>
Subject: [OSS-Tools] [PATCH] barebox-state: check in the efivars for dtb
Date: Wed, 2 Sep 2026 12:27:03 +0200 [thread overview]
Message-ID: <20260902102703.1533492-1-f.pflug@pengutronix.de> (raw)
If barebox was bootet via EFI, it will write the current DTB into the
efivars. This also happens if there is only a compiled in devicetree and
is better protected against attackers compared to the state.dtb in the
rootfs, which never gets checked. Therefor check the efivars first.
The efivars begin with a 4 byte identifier, which is not part of the
devicetree and needs to be skipped.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
src/barebox-state.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/barebox-state.c b/src/barebox-state.c
index e74ba19..c88a02b 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -347,12 +347,19 @@ struct state *state_get(const char *name, const char *filename, bool readonly, b
/* No device-tree in procfs / sysfs, try dtb file in the ESP */
if (-PTR_ERR(root) == ENOENT) {
const char *paths[] = {
+ "/sys/firmware/efi/efivars/barebox-dtb-5b91f69c-8b88-4a2b-9269-5f1d802b5175",
/* default mount paths used by systemd */
"/boot/EFI/BAREBOX/state.dtb",
"/boot/efi/EFI/BAREBOX/state.dtb",
"/efi/EFI/BAREBOX/state.dtb",
NULL
};
+ const int offsets[] = {
+ 4, /* the efivars devicetree has additional bytes in front. */
+ 0,
+ 0,
+ 0,
+ };
void *fdt;
int i;
@@ -362,7 +369,7 @@ struct state *state_get(const char *name, const char *filename, bool readonly, b
break;
}
if (fdt) {
- root = of_unflatten_dtb(fdt);
+ root = of_unflatten_dtb(fdt + offsets[i]);
free(fdt);
}
else
--
2.47.3
reply other threads:[~2026-09-02 10:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260902102703.1533492-1-f.pflug@pengutronix.de \
--to=f.pflug@pengutronix.de \
--cc=oss-tools@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