From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 02 Sep 2026 12:27:10 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x1iBR-009yRj-2d for lore@lore.pengutronix.de; Wed, 02 Sep 2026 12:27:10 +0200 Received: from [127.0.0.1] (helo=metis.whiteo.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1x1iBQ-00042v-7j; Wed, 02 Sep 2026 12:27:08 +0200 Received: from dude06.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::5c]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1x1iBN-00042f-Rj; Wed, 02 Sep 2026 12:27:05 +0200 From: Fabian Pflug To: oss-tools@pengutronix.de Date: Wed, 2 Sep 2026 12:27:03 +0200 Message-ID: <20260902102703.1533492-1-f.pflug@pengutronix.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH] barebox-state: check in the efivars for dtb X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fabian Pflug Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false 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 --- 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