Skip to content
This repository was archived by the owner on Nov 15, 2025. It is now read-only.

Commit 484f4e5

Browse files
committed
efi: honour SYSTEMD_EFI_OPTIONS even if we wouldn't honour SystemdOptions EFI var due to SecureBoot
Fixes: systemd#14864
1 parent f46ba93 commit 484f4e5

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/basic/efivars.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ int systemd_efi_options_variable(char **line) {
313313
return 0;
314314
}
315315

316+
/* In SecureBoot mode this is probably not what you want. As your cmdline is cryptographically signed
317+
* like when using Type #2 EFI Unified Kernel Images (https://systemd.io/BOOT_LOADER_SPECIFICATION/)
318+
* The user's intention is then that the cmdline should not be modified. You want to make sure that
319+
* the system starts up as exactly specified in the signed artifact.
320+
*
321+
* (NB: to make testing purposes we still check the $SYSTEMD_EFI_OPTIONS env var above, even when in
322+
* SecureBoot mode.) */
323+
if (is_efi_secure_boot()) {
324+
_cleanup_free_ char *k;
325+
326+
k = efi_variable_path(EFI_VENDOR_SYSTEMD, "SystemdOptions");
327+
if (!k)
328+
return -ENOMEM;
329+
330+
/* Let's be helpful with the returned error and check if the variable exists at all. If it
331+
* does, let's return a recognizable error (EPERM), and if not ENODATA. */
332+
333+
if (access(k, F_OK) < 0)
334+
return errno == -ENOENT ? -ENODATA : -errno;
335+
336+
return -EPERM;
337+
}
338+
316339
r = efi_get_variable_string(EFI_VENDOR_SYSTEMD, "SystemdOptions", line);
317340
if (r == -ENOENT)
318341
return -ENODATA;

src/basic/proc-cmdline.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ int proc_cmdline(char **ret) {
3939
return read_one_line_file("/proc/cmdline", ret);
4040
}
4141

42-
/* In SecureBoot mode this is probably not what you want. As your cmdline is
43-
* cryptographically signed like when using Type #2 EFI Unified Kernel Images
44-
* (https://systemd.io/BOOT_LOADER_SPECIFICATION/) The user's intention is then
45-
* that the cmdline should not be modified. You want to make sure that the
46-
* system starts up as exactly specified in the signed artifact. */
47-
static int systemd_options_variable(char **line) {
48-
if (is_efi_secure_boot())
49-
return -ENODATA;
50-
51-
return systemd_efi_options_variable(line);
52-
}
53-
5442
static int proc_cmdline_extract_first(const char **p, char **ret_word, ProcCmdlineFlags flags) {
5543
const char *q = *p;
5644
int r;
@@ -131,7 +119,7 @@ int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, ProcCmdlineF
131119

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

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

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

264252
line = mfree(line);
265-
r = systemd_options_variable(&line);
253+
r = systemd_efi_options_variable(&line);
266254
if (r == -ENODATA)
267255
return false; /* Not found */
268256
if (r < 0)

0 commit comments

Comments
 (0)