From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: linux-fsdevel@vger.kernel.org, linux-efi@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Jeremy Kerr <jk@ozlabs.org>
Subject: [PATCH 0/6] convert efivarfs to manage object data correctly
Date: Tue, 10 Dec 2024 12:02:18 -0500 [thread overview]
Message-ID: <20241210170224.19159-1-James.Bottomley@HansenPartnership.com> (raw)
I've added fsdevel because I'm hopping some kind vfs person will check
the shift from efivarfs managing its own data to its data being
managed as part of the vfs object lifetimes. The following paragraph
should describe all you need to know about the unusual features of the
filesystem.
efivarfs is a filesystem projecting the current state of the UEFI
variable store and allowing updates via write. Because EFI variables
contain both contents and a set of attributes, which can't be mapped
to filesystem data, the u32 attribute is prepended to the output of
the file and, since UEFI variables can't be empty, this makes every
file at least 5 characters long. EFI variables can be removed either
by doing an unlink (easy) or by doing a conventional write update that
reduces the content to zero size, which means any write update can
potentially remove the file.
Currently efivarfs has two bugs: it leaks memory and if a create is
attempted that results in an error in the write, it creates a zero
length file remnant that doesn't represent an EFI variable (i.e. the
state reflection of the EFI variable store goes out of sync).
The code uses inode->i_private to point to additionaly allocated
information but tries to maintain a global list of the shadowed
varibles for internal tracking. Forgetting to kfree() entries in this
list when they are deleted is the source of the memory leak.
I've tried to make the patches as easily reviewable by non-EFI people
as possible, so some possible cleanups (like consolidating or removing
the efi lock handling and possibly removing the additional entry
allocation entirely in favour of simply converting the dentry name to
the variable name and guid) are left for later.
The first patch removes some unused fields in the entry; patches 2-3
eliminate the list search for duplication (some EFI variable stores
have buggy iterators) and replaces it with a dcache lookup. Patch 4
move responsibility for freeing the entry data to inode eviction which
both fixes the memory leak and also means we no longer need to iterate
over the variable list and free its entries in kill_sb. Since the
variable list is now unused, patch 5 removes it and its helper
functions.
Patch 6 fixes the second bug by introducing a file_operations->release
method that checks to see if the inode size is zero when the file is
closed and removes it if it is. Since all files must be at least 5 in
length we use a zero i_size as an indicator that either the variable
was removed on write or that it wasn't correctly created in the first
place.
James
---
James Bottomley (6):
efivarfs: remove unused efi_varaible.Attributes and .kobj
efivarfs: add helper to convert from UC16 name and GUID to utf8 name
efivarfs: make variable_is_present use dcache lookup
efivarfs: move freeing of variable entry into evict_inode
efivarfs: remove unused efivarfs_list
efivarfs: fix error on write to new variable leaving remnants
fs/efivarfs/file.c | 31 ++++---
fs/efivarfs/inode.c | 5 --
fs/efivarfs/internal.h | 20 ++---
fs/efivarfs/super.c | 59 +++++++-------
fs/efivarfs/vars.c | 179 ++++++++++-------------------------------
5 files changed, 99 insertions(+), 195 deletions(-)
--
2.35.3
next reply other threads:[~2024-12-10 17:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 17:02 James Bottomley [this message]
2024-12-10 17:02 ` [PATCH 1/6] efivarfs: remove unused efi_varaible.Attributes and .kobj James Bottomley
2024-12-10 17:02 ` [PATCH 2/6] efivarfs: add helper to convert from UC16 name and GUID to utf8 name James Bottomley
2024-12-10 17:02 ` [PATCH 3/6] efivarfs: make variable_is_present use dcache lookup James Bottomley
2024-12-10 17:14 ` Dionna Amalie Glaze
2024-12-10 17:27 ` James Bottomley
2024-12-23 20:20 ` Al Viro
2024-12-23 21:44 ` James Bottomley
2024-12-10 17:02 ` [PATCH 4/6] efivarfs: move freeing of variable entry into evict_inode James Bottomley
2024-12-11 11:19 ` Christian Brauner
2024-12-10 17:02 ` [PATCH 5/6] efivarfs: remove unused efivarfs_list James Bottomley
2024-12-10 17:02 ` [PATCH 6/6] efivarfs: fix error on write to new variable leaving remnants James Bottomley
2024-12-11 11:16 ` Christian Brauner
2024-12-11 12:39 ` James Bottomley
2024-12-23 19:52 ` James Bottomley
2024-12-23 20:05 ` Al Viro
2024-12-23 21:39 ` James Bottomley
2024-12-23 22:56 ` James Bottomley
2024-12-23 23:12 ` Al Viro
2024-12-24 4:04 ` James Bottomley
2024-12-24 4:44 ` Al Viro
2024-12-24 13:07 ` James Bottomley
2024-12-24 15:09 ` James Bottomley
2024-12-27 14:52 ` James Bottomley
2024-12-19 17:14 ` James Bottomley
2024-12-22 10:12 ` Christian Brauner
2024-12-23 19:44 ` James Bottomley
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=20241210170224.19159-1-James.Bottomley@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=ardb@kernel.org \
--cc=jk@ozlabs.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.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