Skip to contentSkip to conversation

efivarfs: Add uid/gid mount options

PATCH Superseded Jiao Zhou 1 participant 1 message Sep 7, 2023

Subsystems (3)
lore
Share & tools
lore

Jiao Zhou

author
#0 lore raw

PATCH v5 1/1 efivarfs: Add uid/gid mount options

Allow UEFI variables to be modified by non-root processes in order to run sandboxed code. This doesn't change the behavior of mounting efivarfs unless uid/gid are specified;
by default both are set to root.

---
Changelog since v1:
- Add missing sentinel entry in fs_parameter_spec[] array.
- Fix a NULL pointer dereference.

Changelog since v2:
- Format the patch description.

Changelog since v3:
- Add gid and uid check to make sure that ids are valid.
- Drop the indentation for one block.
- Use sizeof(*sfi) to allocate memory to avoids future problems if sfi ever changes type.

Changelog since v4:
- Fix the use of sizeof.

---
 fs/efivarfs/inode.c    |  4 +++
 fs/efivarfs/internal.h |  9 +++++
 fs/efivarfs/super.c    | 74 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 84 insertions(+), 3 deletions(-)
fs/efivarfs/inode.c +4 -0
index db9231f0e77b..06dfc73fda04 100644
@@ -20,9 +20,13 @@ struct inode *efivarfs_get_inode(struct super_block *sb,
 				const struct inode *dir, int mode,
 				dev_t dev, bool is_removable)
 {
+	struct efivarfs_fs_info *fsi = sb->s_fs_info;
 	struct inode *inode = new_inode(sb);
+	struct efivarfs_mount_opts *opts = &fsi->mount_opts;
 
 	if (inode) {
+		inode->i_uid = opts->uid;
+		inode->i_gid = opts->gid;
 		inode->i_ino = get_next_ino();
 		inode->i_mode = mode;
 		inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
fs/efivarfs/internal.h +9 -0
index 8ebf3a6a8aa2..c66647f5c0bd 100644
@@ -9,6 +9,15 @@
 #include <linux/list.h>
 #include <linux/efi.h>
 
+struct efivarfs_mount_opts {
+	kuid_t uid;
+	kgid_t gid;
+};
+
+struct efivarfs_fs_info {
+	struct efivarfs_mount_opts mount_opts;
+};
+
 struct efi_variable {
 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
 	efi_guid_t    VendorGuid;
fs/efivarfs/super.c +71 -3

116 lines not on this page · raw message

Signature · 1 line
2.42.0.283.g2d96d420d3-goog