summaryrefslogtreecommitdiffstats
path: root/src/basic/efivars.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-2/+2
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* tree-wide: BLS and DPS are now on uapi-group websiteZbigniew Jędrzejewski-Szmek2022-11-211-1/+1
|
* efivarfs: rename a couple of return params to ret_xyz/retLennart Poettering2022-03-241-11/+11
|
* efivars: downgrade log level in systemd_efi_options_efivarfs_if_newer()Lennart Poettering2022-03-241-1/+2
| | | | | The only caller logs anyway, let's avoid duplicate logging above LOG_DEBUG.
* efivars: no need to convert ENOENT → ENODATA twiceLennart Poettering2022-03-241-4/+2
| | | | read_efi_options_variable() already does this, don#t do it again.
* efivars: tweak debug log message in efi_get_secure_boot_mode()Lennart Poettering2022-03-241-1/+2
| | | | mention what we'll do as effect of the error we are seeing and eat up.
* efivars: cache ENOENT as no efi secure bootLennart Poettering2022-03-241-2/+10
| | | | | | | | | | On systems lacking EFI or the SecureBoot efi var the caching of this info didn#t work, since we'd see ENOENT when reading the var, and cache that, which we then use as reason to retry next time. Let's fix that and convert ENOENT to "secure boot", because that's what it really means. All other errors are left as is (and reason to retry). But let's add some debug logging for that case.
* efivars: skip writing if variable is already in wanted stateAnssi Hannula2021-10-231-1/+25
| | | | | | | | | In order to minimize EFI variable NVRAM wear, do not rewrite variables if they are already in the wanted state (i.e. same data and attributes). This allows e.g. performing repeat calls of "bootctl install" (which always rewrites the EFI boot entry) without consuming EFI NVRAM write cycles.
* sd-boot: Be more precise about secure boot modesJan Janssen2021-10-221-5/+20
| | | | Fixes: #11559
* Merge pull request #20109 from keszybz/timestamp-macrosYu Watanabe2021-07-141-5/+2
|\ | | | | Add macros that define scratch buffer internally for timestamp/timespan formatting
| * tree-wide: add FORMAT_TIMESPAN()Zbigniew Jędrzejewski-Szmek2021-07-091-5/+2
| |
* | tree-wide: coccinelle fixesFrantisek Sumsal2021-07-091-1/+1
|/ | | | Yet another batch of Coccinelle fixes.
* bootctl: print SystemdOptions from efivarfs if newer than our cacheZbigniew Jędrzejewski-Szmek2021-06-151-3/+42
| | | | | | | | | | | | | | | The logic is that if the options are updated after boot, we *don't* use the new value. But we still want to print out the changed contents in bootctl as to not confuse people. Fixes #19597. Also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988450. $ build/bootctl systemd-efi-options quiet Note: SystemdOptions EFI variable has been modified since boot. New value: debug The hint is printed to stderr, so scripts should not be confused.
* basic/efivars: replace dynanamic creation of efivar names with static stringsZbigniew Jędrzejewski-Szmek2021-06-151-72/+25
| | | | | | | | | | | | | | | | | | | | | | | | Creating those string dynamically at runtime is slow and unnecessary. Let's use static strings with a bit of macro magic and the let the compiler coalesce as much as possible. $ size build/src/shared/libsystemd-shared-248.so{.old,} text data bss dec hex filename 2813453 94572 4584 2912609 2c7161 build/src/shared/libsystemd-shared-248.so.old 2812309 94564 4584 2911457 2c6ce1 build/src/shared/libsystemd-shared-248.so A nice side-effect is that the same form is used everywhere, so it's easier to figure out all variables that are used, and where each specific variable is used. C.f. 2b0445262ad9be2a9bf49956ab8e886ea2e48a0a. Note: 'const char *foo = alloca(…);' seems OK. Our coding style document and alloca(3) only warn against using alloca() in function invocations. Declaring both stack variable and alloca at the same time should be fine: no matter in which order they happen, i.e. if the pointer variable is above the contents, or the contents are above the pointer, or even if the pointer is elided by the compiler, everything should be fine.
* tree-wide: avoid uninitialized warning on _cleanup_ variablesLuca Boccassi2021-04-141-1/+1
| | | | | | | With some versions of the compiler, the _cleanup_ attr makes it think the variable might be freed/closed when uninitialized, even though it cannot happen. The added cost is small enough to be worth the benefit, and optimized builds will help reduce it even further.
* various: silence gcc warningsZbigniew Jędrzejewski-Szmek2021-04-011-1/+1
| | | | AFAICT, gcc is just being stupid in all those cases.
* tree-wide: fix links to systemd.io pagesZbigniew Jędrzejewski-Szmek2021-02-191-1/+1
| | | | | Having the extra slash at the end is not a problem, just inconsistent. But the links with .html or .md return 404.
* efivars: debug log if we fail to detect whether /sys/firmware/efi/ existsLennart Poettering2021-02-111-1/+4
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: avoid some loaded termsLennart Poettering2020-06-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | https://tools.ietf.org/html/draft-knodel-terminology-02 https://lwn.net/Articles/823224/ This gets rid of most but not occasions of these loaded terms: 1. scsi_id and friends are something that is supposed to be removed from our tree (see #7594) 2. The test suite defines an API used by the ubuntu CI. We can remove this too later, but this needs to be done in sync with the ubuntu CI. 3. In some cases the terms are part of APIs we call or where we expose concepts the kernel names the way it names them. (In particular all remaining uses of the word "slave" in our codebase are like this, it's used by the POSIX PTY layer, by the network subsystem, the mount API and the block device subsystem). Getting rid of the term in these contexts would mean doing some major fixes of the kernel ABI first. Regarding the replacements: when whitelist/blacklist is used as noun we replace with with allow list/deny list, and when used as verb with allow-list/deny-list.
* efi: Cache contents of EFI variable SystemdOptionsFilipe Brandenburger2020-06-131-20/+53
| | | | | | Cache it early in startup of the system manager, right after `/run/systemd` is created, so that further access to it can be done without accessing the EFI filesystem at all.
* basic/efivars: try re-reading efivars without delay firstZbigniew Jędrzejewski-Szmek2020-06-021-3/+5
| | | | | | | | | | | | | | | Quoting https://github.com/systemd/systemd/issues/14828#issuecomment-635212615: > [kernel uses] msleep_interruptible() and that means when the process receives > any kind of signal masked or not this will abort with EINTR. systemd-logind > gets signals from the TTY layer all the time though. > Here's what might be happening: while logind reads the EFI stuff it gets a > series of signals from the TTY layer, which causes the read() to be aborted > with EINTR, which means logind will wait 50ms and retry. Which will be > aborted again, and so on, until quite some time passed. If we'd not wait for > the 50ms otoh we wouldn't wait so long, as then on each signal we'd > immediately retry again.
* efi: add more logging for all EFI variable readsLennart Poettering2020-05-291-7/+10
|
* efi: explicitly update mtime of EFI variables when changing themLennart Poettering2020-05-291-0/+8
|
* efi: as extra paranoia NUL terminate UTF-16 strings with three NUL bytesLennart Poettering2020-05-291-3/+5
| | | | | | | This is a safey net anyway, let's make it fully safe: if the data ends on an uneven byte, then we need to complete the UTF-16 codepoint first, before adding the final NUL byte pair. Hence let's suffix with three NULs, instead of just two.
* efivars: log whenever an EFI variable read access is slowLennart Poettering2020-05-271-0/+14
| | | | | This should allow us to detect slowdowns caused by EFI variable read access a bit.
* basic/efivars: fix errno propagationZbigniew Jędrzejewski-Szmek2020-05-201-1/+1
| | | | Fixup for 484f4e5b2d62e885998fa3c09ed4d58b6c38f987. Should fix #15730.
* efi: honour SYSTEMD_EFI_OPTIONS even if we wouldn't honour SystemdOptions ↵Lennart Poettering2020-04-301-0/+23
| | | | | | EFI var due to SecureBoot Fixes: #14864
* efi: cache test results of boolean EFI state functionsLennart Poettering2020-04-301-5/+21
| | | | | | | | EFI variable access is nowadays subject to rate limiting by the kernel. Thus, let's cache the results of checking them, in order to minimize how often we access them. Fixes: #14828
* efivars: retry open and read operationsZbigniew Jędrzejewski-Szmek2020-04-281-6/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | On my laptop (Lenovo X1carbo 4th) I very occasionally see test-boot-timestamps fail with this tb: 262/494 test-boot-timestamps FAIL 0.7348453998565674 s (killed by signal 6 SIGABRT) 08:12:48 SYSTEMD_LANGUAGE_FALLBACK_MAP='/home/zbyszek/src/systemd/src/locale/language-fallback-map' SYSTEMD_KBD_MODEL_MAP='/home/zbyszek/src/systemd/src/locale/kbd-model-map' PATH='/home/zbyszek/src/systemd/build:/home/zbyszek/.local/bin:/usr/lib64/qt-3.3/bin:/usr/share/Modules/bin:/usr/condabin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/zbyszek/bin:/var/lib/snapd/snap/bin' /home/zbyszek/src/systemd/build/test-boot-timestamps --- stderr --- Failed to read $container of PID 1, ignoring: Permission denied Found container virtualization none. Failed to get SystemdOptions EFI variable, ignoring: Interrupted system call Failed to read ACPI FPDT: Permission denied Failed to read LoaderTimeInitUSec: Interrupted system call Failed to read EFI loader data: Interrupted system call Assertion 'q >= 0' failed at src/test/test-boot-timestamps.c:84, function main(). Aborting. Normally it takes ~0.02s, but here there's a slowdown to 0.73 and things fail with EINTR. This happens only occasionally, and I haven't been able to capture a strace. It would be to ignore that case in test-boot-timestamps or always translate EINTR to -ENODATA. Nevertheless, I think it's better to retry, since this gives as more resilient behaviour and avoids a transient failure. See https://github.com/torvalds/linux/blob/master/fs/efivarfs/file.c#L75 and https://github.com/torvalds/linux/commit/bef3efbeb897b56867e271cdbc5f8adaacaeb9cd.
* Disable reading SystemdOptions EFI Var when in SecureBoot modeArian van Putten2020-01-161-0/+36
| | | | | | | | | 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.
* efivars: properly NUL terminate EFI variables when readingLennart Poettering2019-12-161-2/+2
| | | | A follow-up for 35b9eb0a72b6254568a294f0ebd011da20958a64.
* basic/efivars: do not return EIO if an efivar read is shorten than fstat sizeZbigniew Jędrzejewski-Szmek2019-12-151-6/+7
| | | | | | | | | | | | | | | | On my machine stat returns size 22, but only 20 bytes are read: openat(AT_FDCWD, "/sys/firmware/efi/efivars/LoaderTimeInitUSec-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", O_RDONLY|O_NOCTTY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=22, ...}) = 0 read(3, "\6\0\0\0", 4) = 4 read(3, "7\0001\0001\0003\0005\0002\0007\0\0\0", 18) = 16 Failed to read LoaderTimeInitUSec: Input/output error Let's just accept that the kernel is returning inconsistent results. It seems to happen two only two variables on my machine: /sys/firmware/efi/efivars/LoaderTimeInitUSec-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f /sys/firmware/efi/efivars/LoaderTimeMenuUSec-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f so it might be related to the way we write them.
* Rename "system-options" to "systemd-efi-options"Zbigniew Jędrzejewski-Szmek2019-11-181-1/+1
| | | | | | | | | | | | | | | | This makes the naming more consistent: we now have bootctl systemd-efi-options, $SYSTEMD_EFI_OPTIONS and the SystemdOptions EFI variable. (SystemdEFIOptions would be redundant, because it is only used in the context of efivars, and users don't interact with that name directly.) bootctl is adjusted to use 2sp indentation, similarly to systemctl and other programs. Remove the prefix with the old name from 'bootctl systemd-efi-options' output, since it's redundant and we don't want the old name anyway.
* tree-wide: drop stdio.h when stdio-util.h is includedYu Watanabe2019-11-031-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-031-1/+0
|
* Add support for SystemdOptions EFI var to augment /proc/cmdlineZbigniew Jędrzejewski-Szmek2019-09-161-0/+25
| | | | | | | | | | | | In various circumstances, overriding the kernel commandline can be inconvenient. People have different bootloaders, and e.g. the grub config can be pretty scary. grubby helps, but it isn't always available. This option adds an alternative mechanism that can quite convenient on EFI systems. cmdline settings have higher priority, because they can be (usually) changed on the bootloader prompt. $SYSTEMD_EFI_OPTIONS can be used to override, same as $SYSTEMD_PROC_CMDLINE.
* util-lib: split shared/efivars into basic/efivars and shared/efi-loaderZbigniew Jędrzejewski-Szmek2019-09-161-0/+225
I want to use efivars.[ch] in proc-cmdline.c, but most of the efivars stuff is not needed in basic/. Move the file from shared/ to basic/, but then move back most of the higher-level functions to the new shared/efi-loader.c file.