[PATCH 13/13] fs: efivarfs: zero-fill variables grown by truncate
Sascha Hauer
s.hauer at pengutronix.de
Wed Nov 18 06:52:03 PST 2026
efivarfs_truncate() grows the buffer of a variable with realloc(), which
leaves the new bytes uninitialized, and stores the variable with them:
write 1000 bytes, ftruncate(300), ftruncate(600)
-> bytes 300..599 hold whatever was in memory
Clear what the variable grows by.
Fixes: 46b5a6d6527f ("fs: efivars: implement write support")
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
fs/efivarfs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index da826234b9..efc6d9a12b 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -232,8 +232,11 @@ static int efivarfs_truncate(struct file *f, loff_t size)
struct efi_runtime_services *rt = efile->priv->rt;
efi_status_t efiret;
+ efile->buf = realloc(efile->buf, size + sizeof(uint32_t));
+ /* what a variable grows by reads back as zeroes */
+ if (size > efile->size)
+ memset(efile->buf + efile->size, 0, size - efile->size);
efile->size = size;
- efile->buf = realloc(efile->buf, efile->size + sizeof(uint32_t));
efiret = rt->set_variable(efile->name, &efile->vendor,
efile->attributes,
--
2.47.3
More information about the barebox
mailing list