From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] param: make setting a parameter to the same string value a no-op
Date: Thu, 11 Dec 2025 18:17:05 +0100 [thread overview]
Message-ID: <20251211171706.2369329-1-a.fatoum@pengutronix.de> (raw)
setenv("global.bootm.root_param", getenv("global.bootm.root_param"))
triggers a use-after-free, because the value is free'd before being
duplicated and allocated again.
Let's just early exit in this case as there's nothing further to do.
This was noticed by KASAN when bootm_data_restore_defaults restored
global.bootm.root_param.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
lib/parameter.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/parameter.c b/lib/parameter.c
index b9a449c32657..bf5dbbb05e6b 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -131,6 +131,8 @@ int bobject_set_param(bobject_t _bobj, const char *name, const char *val)
int bobject_param_set_generic(bobject_t _bobj, struct param_d *p,
const char *val)
{
+ if (val == p->value)
+ return 0;
free(p->value);
if (!val) {
p->value = NULL;
--
2.47.3
next reply other threads:[~2025-12-11 17:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 17:17 Ahmad Fatoum [this message]
2025-12-15 7:23 ` Sascha Hauer
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=20251211171706.2369329-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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