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: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] fs: efivarfs: skip variables whose name does not fit struct dirent
Date: Thu, 15 Oct 2026 16:08:01 +0200	[thread overview]
Message-ID: <20261015140802.1227004-1-a.fatoum@pengutronix.de> (raw)

From: Ahmad Fatoum <a.fatoum@barebox.org>

efivarfs fills struct dirent in its own readdir, so it doesn't benefit
from the length check in fillonedir() and strcpy()s the variable name
and GUID suffix into the 256 byte d_name unchecked.

The names come from the firmware, which allows up to 1023 characters
here, and efivars_create() takes them from the path, so creating a
variable with a 300 character name and listing /efivars overruns the
directory allocation.

Let's skip such variables with a warning like fillonedir() does.

Fixes: ef4f9d77b72c ("fs: implement EFI variable filesystem driver")
Assisted-by: Claude:opus-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 fs/efivarfs.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index b9f514c51cd9..da826234b959 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -261,16 +261,22 @@ static struct dirent *efivarfs_readdir(struct device *dev, DIR *dir)
 	struct efivarfs_dir *edir = container_of(dir, struct efivarfs_dir, dir);
 	struct efivarfs_inode *inode;
 
-	if (edir->current == &priv->inodes)
-		return NULL;
+	while (edir->current != &priv->inodes) {
+		inode = list_entry(edir->current, struct efivarfs_inode, node);
+		edir->current = edir->current->next;
 
-	inode = list_entry(edir->current, struct efivarfs_inode, node);
+		if (strlen(inode->full_name) >= sizeof(dir->d.d_name)) {
+			pr_warn("skipping variable %.32s...: name too long\n",
+				inode->full_name);
+			continue;
+		}
 
-	strcpy(dir->d.d_name, inode->full_name);
+		strcpy(dir->d.d_name, inode->full_name);
 
-	edir->current = edir->current->next;
+		return &dir->d;
+	}
 
-	return &dir->d;
+	return NULL;
 }
 
 static int efivarfs_closedir(struct device *dev, DIR *dir)
-- 
2.47.3




                 reply	other threads:[~2026-10-15 14:08 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=20261015140802.1227004-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --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