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

Subscribers

People subscribed via source and target branches