Skip to content

Commit

Permalink
efi: honour SYSTEMD_EFI_OPTIONS even if we wouldn't honour SystemdOpt…
Browse files Browse the repository at this point in the history
…ions EFI var due to SecureBoot

Fixes: systemd#14864
  • Loading branch information
poettering committed Apr 30, 2020
1 parent f46ba93 commit 484f4e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
23 changes: 23 additions & 0 deletions src/basic/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,29 @@ int systemd_efi_options_variable(char **line) {
return 0;
}

/* In SecureBoot mode this is probably not what you want. As your cmdline is cryptographically signed
* like when using Type #2 EFI Unified Kernel Images (https://systemd.io/BOOT_LOADER_SPECIFICATION/)
* The user's intention is then that the cmdline should not be modified. You want to make sure that
* the system starts up as exactly specified in the signed artifact.
*
* (NB: to make testing purposes we still check the $SYSTEMD_EFI_OPTIONS env var above, even when in
* SecureBoot mode.) */
if (is_efi_secure_boot()) {
_cleanup_free_ char *k;

k = efi_variable_path(EFI_VENDOR_SYSTEMD, "SystemdOptions");
if (!k)
return -ENOMEM;

/* Let's be helpful with the returned error and check if the variable exists at all. If it
* does, let's return a recognizable error (EPERM), and if not ENODATA. */

if (access(k, F_OK) < 0)
return errno == -ENOENT ? -ENODATA : -errno;

return -EPERM;
}

r = efi_get_variable_string(EFI_VENDOR_SYSTEMD, "SystemdOptions", line);
if (r == -ENOENT)
return -ENODATA;
Expand Down
16 changes: 2 additions & 14 deletions src/basic/proc-cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ int proc_cmdline(char **ret) {
return read_one_line_file("/proc/cmdline", ret);
}

/* In SecureBoot mode this is probably not what you want. As your cmdline is
* cryptographically signed like when using Type #2 EFI Unified Kernel Images
* (https://systemd.io/BOOT_LOADER_SPECIFICATION/) The user's intention is then
* that the cmdline should not be modified. You want to make sure that the
* system starts up as exactly specified in the signed artifact. */
static int systemd_options_variable(char **line) {
if (is_efi_secure_boot())
return -ENODATA;

return systemd_efi_options_variable(line);
}

static int proc_cmdline_extract_first(const char **p, char **ret_word, ProcCmdlineFlags flags) {
const char *q = *p;
int r;
Expand Down Expand Up @@ -131,7 +119,7 @@ int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, ProcCmdlineF

/* We parse the EFI variable first, because later settings have higher priority. */

r = systemd_options_variable(&line);
r = systemd_efi_options_variable(&line);
if (r < 0 && r != -ENODATA)
log_debug_errno(r, "Failed to get SystemdOptions EFI variable, ignoring: %m");

Expand Down Expand Up @@ -262,7 +250,7 @@ int proc_cmdline_get_key(const char *key, ProcCmdlineFlags flags, char **ret_val
return r;

line = mfree(line);
r = systemd_options_variable(&line);
r = systemd_efi_options_variable(&line);
if (r == -ENODATA)
return false; /* Not found */
if (r < 0)
Expand Down

0 comments on commit 484f4e5

Please sign in to comment.