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@pengutronix.de>
Subject: [PATCH] fs: efi: don't leak the file info buffer in efifs_truncate()
Date: Fri,  4 Sep 2026 09:16:21 +0200	[thread overview]
Message-ID: <20260904071621.53334-1-a.fatoum@pengutronix.de> (raw)

The 1 KiB EFI_FILE_INFO buffer is never freed on any of the three
exits, and this runs on every truncating open.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/efi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/efi.c b/fs/efi.c
index 76eb86a85eea..74dad235b19d 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -250,9 +250,9 @@ static int efifs_truncate(struct file *f, loff_t size)
 	efi_status_t efiret;
 	struct efi_file_info *info;
 	size_t bufsize = 1024;
-	int ret;
+	int ret = 0;
 
-	info = xzalloc(1024);
+	info = xzalloc(bufsize);
 
 	efiret = ufile->entry->get_info(ufile->entry, &efi_file_info_id, &bufsize, info);
 	if (EFI_ERROR(efiret)) {
@@ -262,7 +262,7 @@ static int efifs_truncate(struct file *f, loff_t size)
 	}
 
 	if (size > info->FileSize)
-		return 0;
+		goto out;
 
 	info->FileSize = size;
 
@@ -270,11 +270,11 @@ static int efifs_truncate(struct file *f, loff_t size)
 	if (EFI_ERROR(efiret)) {
 		pr_err("%s: unable to SetInfo: %s\n", __func__, efi_strerror(efiret));
 		ret = -efi_errno(efiret);
-		goto out;
 	}
 
-	return 0;
 out:
+	free(info);
+
 	return ret;
 }
 
-- 
2.47.3




             reply	other threads:[~2026-09-04  7:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  7:16 Ahmad Fatoum [this message]
2026-09-04  9:39 ` 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=20260904071621.53334-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