mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: "Jan Lübbe" <j.luebbe@pengutronix.de>,
	"Ahmad Fatoum" <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] defaultenv: skip non-existent dirs in defaultenv_append_runtime_directory
Date: Mon, 24 Nov 2025 18:59:40 +0100	[thread overview]
Message-ID: <20251124175947.1725563-1-a.fatoum@pengutronix.de> (raw)

QEMU fw_cfg file system driver is the sole user of
defaultenv_append_runtime_directory() and it passes a path that's not
necessarily available.

When that happens, this is not noticed until the loop in defaultenv_load()
aborts early with an -ENOENT preventing load of an external environment.

Fix this as well as further issues of this sort by not adding directories
that don't exist at the time defaultenv_append_runtime_directory() is
called.

Fixes: 31dfb561d1a4 ("fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg")
Reported-by: Jan Lübbe <j.luebbe@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 defaultenv/defaultenv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index d6cca466a683..652fda05027a 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -20,6 +20,7 @@
 #include <init.h>
 #include <libfile.h>
 #include <asm/unaligned.h>
+#include <fs.h>
 #include "barebox_default_env.h"
 
 static LIST_HEAD(defaultenv_list);
@@ -100,6 +101,10 @@ void defaultenv_append(void *buf, unsigned int size, const char *name)
 void defaultenv_append_runtime_directory(const char *srcdir)
 {
 	struct defaultenv *df;
+	struct stat s;
+
+	if (stat(srcdir, &s) || !S_ISDIR(s.st_mode))
+		return;
 
 	defaultenv_add_base();
 
-- 
2.47.3




             reply	other threads:[~2025-11-24 18:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 17:59 Ahmad Fatoum [this message]
2025-11-24 17:59 ` [PATCH 2/3] defaultenv: don't abort defaultenv_load silently on error Ahmad Fatoum
2025-11-24 17:59 ` [PATCH 3/3] defaultenv: add base and external defaultenv in pure_initcall Ahmad Fatoum

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=20251124175947.1725563-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=j.luebbe@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