Skip to contentSkip to conversation

commands/efi: add command to dump all uefi runtime variables

PATCH Superseded khaalid cali 2 participants 2 messages May 11, 2025

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 commands/efi: add command to dump all uefi runtime variables

From: khaalid <[email protected]>

I followed the suggestion and implemented the option parsing using extcmd.
However, I feel this command is not ideal to have any arguments. Similar commands like
lsefi, lsefimmap, and lsefisystab don’t take arguments—they simply dump data.
Since this command also just dumps variables and doesn’t do anything more, adding options might introduce inconsistency.

Returning grub_err_t for dump_variable_data isn't ideal neither for
two reasons:
- First the only place the function fail is if grub_efi_get_variable_with_attributes fail; this function returns EFI_STATUS mostly, so even if it fails and sets errno then grub_error already overrided it so we get GRUB_ERR_IO always.
- Second dump_variable_data is expected to fail because not every
variable can neccessarily retrieved, some will fail due security restrictions. So it is better if we skip failed variables and move on to the next one.
Let me know what do you think.

---
 grub-core/Makefile.core.def       |   6 ++
 grub-core/commands/efi/lsefivar.c | 133 ++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 grub-core/commands/efi/lsefivar.c
grub-core/Makefile.core.def +6 -0
index f70e02e69..8b9cf2a68 100644
@@ -840,6 +840,12 @@ module = {
   enable = efi;
 };
 
+module = {
+  name = lsefivar;
+  efi = commands/efi/lsefivar.c;
+  enable = efi;
+};
+
 module = {
   name = blocklist;
   common = commands/blocklist.c;
grub-core/commands/efi/lsefivar.c new file +133 -0

133 lines not on this page · raw message

Signature · 7 lines
2.49.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 10 lines · khaalid cali

From: khaalid <[email protected]>

I followed the suggestion and implemented the option parsing using extcmd. However, I feel this command is not ideal to have any arguments. Similar commands like
lsefi, lsefimmap, and lsefisystab don’t take arguments—they simply dump data.
Since this command also just dumps variables and doesn’t do anything more, adding options might introduce inconsistency.

Quoted 12 lines

Returning grub_err_t for dump_variable_data isn't ideal neither for two reasons:
- First the only place the function fail is if
grub_efi_get_variable_with_attributes
fail; this function returns EFI_STATUS mostly, so even if it fails and
sets errno then
grub_error already overrided it so we get GRUB_ERR_IO always.
- Second dump_variable_data is expected to fail because not every variable can neccessarily retrieved, some will fail due security
restrictions. So it is better
if we skip failed variables and move on to the next one.

If you want to ignore error, you need to reset grub_errno to GRUB_ERR_NONE, not call grub_error. Then you can keep it void

Quoted 16 lines
grub-core/commands/efi/lsefivar.c new file +9 -0
+static void
+dump_variable_data(const char *variable_name, grub_guid_t *variable_guid)
+{
+    grub_efi_status_t status;
+    grub_efi_uint32_t attributes;
+    grub_size_t data_size;
+    void *data;
+
+    status = grub_efi_get_variable_with_attributes(variable_name,

variable_guid,
+ &data_size, &data,
&attributes);

grub-core/commands/efi/lsefivar.c new file +3 -0
+    if (status != GRUB_EFI_SUCCESS)
+    {
+        grub_error(GRUB_ERR_IO, "failed to retrieve variable data 0x%"
Quoted 2 lines

PRIxGRUB_EFI_UINTN_T, status);

Already said.

+ return;

grub-core/commands/efi/lsefivar.c line 54

Quoted 4 lines
grub-core/commands/efi/lsefivar.c new file +3 -0
+    }
+
+    grub_printf(_("Attributes:\n"));

Actually grub_puts_ is preferred when they're are no arguments. Sorry, I forgot this.

Quoted 4 lines

+ variable_name = grub_realloc(variable_name,
variable_name_size * sizeof(grub_efi_char16_t));
+ if (variable_name == NULL)

Please have a look at how to handle errors with realloc. You need to keep a copy of old pointer in case you have to free it. Some places in our codebase have similar memory leaks but it's not a reason to introduce more.

Review

Quoted 4 lines
(quoted diff) +2 -0
+                               return grub_errno;
+               }

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel