Merge ~xypron/grub:efivarfs into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by Heinrich Schuchardt
Status: Merged
Merge reported by: Julian Andres Klode
Merged at revision: d999baebe05d973f675a5173530e577afb0e90a0
Proposed branch: ~xypron/grub:efivarfs
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 93 lines (+79/-0)
2 files modified
debian/patches/efivar-check-that-efivarfs-is-writeable.patch (+78/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+417185@code.launchpad.net

This proposal supersedes a proposal from 2022-03-21.

Commit message

efivar: check that efivarfs is writeable

Some UEFI implementations (notably U-Boot) don't implement the
SetVariable() runtime service. On these systems the GRUB installation
must be completed manually. Write a warning in this case but avoid
throwing an error. (LP: #1965288)

Signed-off-by: Heinrich Schuchardt <email address hidden>

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/patches/efivar-check-that-efivarfs-is-writeable.patch b/debian/patches/efivar-check-that-efivarfs-is-writeable.patch
0new file mode 1006440new file mode 100644
index 0000000..7b10aa5
--- /dev/null
+++ b/debian/patches/efivar-check-that-efivarfs-is-writeable.patch
@@ -0,0 +1,78 @@
1From 18ae3304569894091c3f9c87cdab3c26a919889c Mon Sep 17 00:00:00 2001
2From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
3Date: Fri, 18 Mar 2022 15:21:33 +0100
4Subject: [PATCH 1/1] efivar: check that efivarfs is writeable
5
6Some UEFI implementations (notably U-Boot) don't implement the
7SetVariable() runtime service. On these systems the GRUB installation
8must be completed manually. Write a warning in this case but avoid
9throwing an error. (LP: #1965288)
10
11Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
12---
13 grub-core/osdep/unix/efivar.c | 34 ++++++++++++++++++++++++++++++++++
14 1 file changed, 34 insertions(+)
15
16diff --git a/grub-core/osdep/unix/efivar.c b/grub-core/osdep/unix/efivar.c
17index d34df0f70..732f93982 100644
18--- a/grub-core/osdep/unix/efivar.c
19+++ b/grub-core/osdep/unix/efivar.c
20@@ -38,7 +38,10 @@
21 #include <grub/misc.h>
22 #include <grub/emu/exec.h>
23 #include <grub/emu/getroot.h>
24+#include <linux/magic.h>
25 #include <sys/types.h>
26+#include <sys/vfs.h>
27+#include <sys/statvfs.h>
28 #include <ctype.h>
29 #include <errno.h>
30 #include <stdbool.h>
31@@ -511,6 +514,29 @@ devices_equal (const_efidp a, const_efidp b)
32 return false;
33 }
34
35+/**
36+ * efivar_is_rw - detect if the efivar file system exists and is writeable
37+ *
38+ * Return: true if efivarfs is writeable
39+ */
40+static bool
41+efivar_is_rw (void)
42+{
43+ int ret;
44+ const char *mount = "/sys/firmware/efi/efivars";
45+ struct statfs stat;
46+
47+ ret = statfs(mount, &stat);
48+ if (ret == -1)
49+ return false;
50+ if (stat.f_type != EFIVARFS_MAGIC)
51+ return false;
52+ if (stat.f_flags & ST_RDONLY)
53+ return false;
54+
55+ return true;
56+}
57+
58 int
59 grub_install_efivar_register_efi (grub_device_t efidir_grub_dev,
60 const char *efidir, const char *efifile_path,
61@@ -528,6 +554,14 @@ grub_install_efivar_register_efi (grub_device_t efidir_grub_dev,
62 int rc;
63 bool is_boot_efi;
64
65+ /* Check if EFI variable can be written */
66+ if (!efivar_is_rw ())
67+ {
68+ grub_util_warn ("EFI variables cannot be set on this system");
69+ grub_util_warn ("You will have to complete the GRUB setup manually");
70+ return 0;
71+ }
72+
73 is_boot_efi = strstr (efidir, "/boot/efi") != NULL;
74 efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
75 efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
76--
772.34.1
78
diff --git a/debian/patches/series b/debian/patches/series
index 7942ada..0a4b388 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -121,3 +121,4 @@ ubuntu-os-prober-auto.patch
121efi-correct-struct-grub_efi_boot_services.patch121efi-correct-struct-grub_efi_boot_services.patch
122efi-implement-grub_efi_run_image.patch122efi-implement-grub_efi_run_image.patch
123fat-fix-listing-the-root-directory.patch123fat-fix-listing-the-root-directory.patch
124efivar-check-that-efivarfs-is-writeable.patch

Subscribers

People subscribed via source and target branches