[PATCH v2025.09.y 24/58] bootm: fix bootm override saving/restoring
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Mar 13 06:25:08 PDT 2026
As bootm_set_overrides() only sets non-NULL members, it's not suitable
to restore old settings as once a member is non-NULL, it can't change
it.
This may lead to use-after-frees, as the original strings are free'd,
but the override keeps pointing at it.
Fix this by merging overrides only before the boot and resetting all
members after.
Fixes: d2dae53f0dc5 ("bootm: fix boot override inheritance")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Link: https://lore.barebox.org/20260126104656.832582-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
common/boot.c | 4 ++--
common/bootm.c | 6 +++++-
include/bootm-overrides.h | 6 ++++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/common/boot.c b/common/boot.c
index 07bd288df29d..f54c812991ad 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -171,13 +171,13 @@ int boot_entry(struct bootentry *be, int verbose, int dryrun)
}
}
- old = bootm_set_overrides(be->overrides);
+ old = bootm_save_overrides(be->overrides);
ret = be->boot(be, verbose, dryrun);
if (ret && ret != -ENOMEDIUM)
pr_err("Booting entry '%s' failed: %pe\n", be->title, ERR_PTR(ret));
- bootm_set_overrides(old);
+ bootm_restore_overrides(old);
globalvar_set_match("linux.bootargs.dyn.", "");
diff --git a/common/bootm.c b/common/bootm.c
index 34c72282d6ba..0cdaf30613fc 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -976,13 +976,17 @@ int bootm_boot(struct bootm_data *bootm_data)
}
#ifdef CONFIG_BOOT_OVERRIDE
-struct bootm_overrides bootm_set_overrides(const struct bootm_overrides overrides)
+struct bootm_overrides bootm_save_overrides(const struct bootm_overrides overrides)
{
struct bootm_overrides old = bootm_overrides;
/* bootm_merge_overrides copies only actual (non-NULL) overrides */
bootm_merge_overrides(&bootm_overrides, &overrides);
return old;
}
+void bootm_restore_overrides(const struct bootm_overrides overrides)
+{
+ bootm_overrides = overrides;
+}
#endif
static int do_bootm_compressed(struct image_data *img_data)
diff --git a/include/bootm-overrides.h b/include/bootm-overrides.h
index 4a270b95afcc..b807e5be310a 100644
--- a/include/bootm-overrides.h
+++ b/include/bootm-overrides.h
@@ -8,12 +8,14 @@ struct bootm_overrides {
};
#ifdef CONFIG_BOOT_OVERRIDE
-struct bootm_overrides bootm_set_overrides(const struct bootm_overrides overrides_new);
+struct bootm_overrides bootm_save_overrides(const struct bootm_overrides overrides);
+void bootm_restore_overrides(const struct bootm_overrides overrides);
#else
-static inline struct bootm_overrides bootm_set_overrides(const struct bootm_overrides overrides)
+static inline struct bootm_overrides bootm_save_overrides(const struct bootm_overrides overrides)
{
return (struct bootm_overrides) {};
}
+static inline void bootm_restore_overrides(const struct bootm_overrides overrides) {}
#endif
static inline void bootm_merge_overrides(struct bootm_overrides *dst,
--
2.47.3
More information about the barebox
mailing list