Commit graph

74 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 673a1e6fb9 Add fmemopen_unlocked() and use unlocked ops in fuzzers and some other tests
This might make things marginially faster. I didn't benchmark though.
2019-04-12 11:44:57 +02:00
Zbigniew Jędrzejewski-Szmek 7f42be65b9 bootspec: remove now-unused boot_entry_type_table 2019-04-05 13:50:45 +02:00
Zbigniew Jędrzejewski-Szmek ce4c4f8108 bootctl: replace "type" with "source" in output
I think this is more useful (because it's easy to stick the path into an editor command
when one wants to change the options or inspect the files), and more self-explanatory.

Example output:
        title: Fedora 30 (Workstation Edition) (4.20.16-200.fc29.x86_64)
           id: 08a5690a2eed47cf92ac0a5d2e3cf6b0-4.20.16-200.fc29.x86_64
       source: /boot/efi/loader/entries/08a5690a2eed47cf92ac0a5d2e3cf6b0-4.20.16-200.fc29.x86_64.conf
      version: 4.20.16-200.fc29.x86_64
          ...

        title: Fedora 30 (Workstation Edition)
           id: fedora-30
       source: /boot/efi/EFI/Linux/linux-5.0.5-300.fc30.x86_64-08a5690a2eed47cf92ac0a5d2e3cf6b0.efi
        linux: EFI/Linux/linux-5.0.5-300.fc30.x86_64-08a5690a2eed47cf92ac0a5d2e3cf6b0.efi
          ...

        title: Reboot Into Firmware Interface
           id: auto-reboot-to-firmware-setup
       source: /sys/firmware/efi/efivars/LoaderEntries-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f
2019-04-05 13:50:34 +02:00
Yu Watanabe 18268197fa bootspec: fix memleak caused by setting invalid cleanup function 2019-03-31 23:31:29 +09:00
Yu Watanabe 7226337574 bootspec: add missing free() in boot_config_free() 2019-03-31 23:30:30 +09:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Zbigniew Jędrzejewski-Szmek a75fcef8fb shared/bootspec: avoid signed-unsigned comparison
../src/shared/bootspec.c: In function ‘find_sections’:
../src/shared/bootspec.c:425:23: warning: comparison of integer expressions of different signedness: ‘ssize_t’ {aka ‘int’} and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  425 |                 if (n != size)
      |                       ^~
2019-03-15 15:28:43 +01:00
Lennart Poettering cc5957dca0 bootspec: don't log in boot_entries_load_config_auto() about no ESP
Let's do it in the caller instead. That way, logind can stay silent
about it.

Fixes: #11950
2019-03-13 17:06:24 +01:00
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
Zbigniew Jędrzejewski-Szmek 388d2993ec shared/bootspec: avoid going through -1 when calculating array index
Coverity was complaining in CID#1399407 that config->entries might be used
while NULL. Let's add an assert to make sure it's not.

Also, let's quit early if we have no entries to loop through. The code was
not incorrect, but it's cleaner to avoid any negative indices.
2019-03-12 13:32:45 +01:00
Zbigniew Jędrzejewski-Szmek bd29f9de69 shared/bootspec: do not fail on errors when reading EFI vars
It seems that my EFI storage is corrupted. The kernel reports the file as present, but returns
an error when reading. Nevertheless, this shouldn't prevent me from reading the entry
list.

Fixes #11909.
2019-03-06 22:49:52 +01:00
Zbigniew Jędrzejewski-Szmek 1f18d94215 shared/bootspec: treat empty EFI vars as missing
We shouldn't really make any fuss about this. Also, change 'var' to 'variable'
for consistency with systemctl.c.
2019-03-06 22:45:37 +01:00
Zbigniew Jędrzejewski-Szmek f40999f878 shared/bootspec: minor simplification 2019-03-06 22:21:34 +01:00
Lennart Poettering eed7210a5c bootspec: validate bootpsec entry ids before we use them 2019-03-05 16:50:58 +01:00
Lennart Poettering 38bd74d67e bootspec: get rid of find_default_boot_entry() entirely
Now only two operations are left. Let's just move this into the caller,
since it should make things simpler, clearer and shorter, in particular
as there's only a single user for this.
2019-03-05 16:50:58 +01:00
Lennart Poettering b1a8771996 bootspec: rework find_default_boot_entry() to use boot_entries_load_config_auto()
it's pretty much the same code now, hence use it.
2019-03-05 16:50:58 +01:00
Lennart Poettering eea4ce1ec7 bootspec: introduce new helper boot_entries_load_config_auto()
It's a simple wrapper around boot_entries_load_config(), but determines
the ESP/XBOOTLDR paths automatically at first. Also, it looks for a path
/run/boot-loader-entries/ and loads the entries from there if it
exists. This is supposed to be a hook for other boot loaders to make our
tools aware of their own entries.
2019-03-05 16:50:58 +01:00
Lennart Poettering dba33c4a2c bootspec: correct error code shown in log msg 2019-03-05 16:50:58 +01:00
Lennart Poettering 93f14ce28d bootspec: move augmentation of loader-discovered entries into bootspec.c
Previously, bootctl would show boot loader entries discovered by the
boot loader which couldn't found locally separately in the output.

Let's move this code into bootspec.c, and beef it up a bit. This way we
can use it later on for logind, and correctly show automatically
discovered windows/macos entries too.
2019-03-05 16:50:58 +01:00
Lennart Poettering 5b1da1ba6d bootspec: simplify find_default_boot_entry()
If the only caller passes NULL for the two paths, let's remove the
parameter altogether.
2019-03-05 16:50:58 +01:00
Lennart Poettering 7800322ca5 bootspec: move log msg from systemctl.c to bootspec.c
find_default_boot_entry() is only used by systemctl.c, and currently
handles one log message in the caller instead of the callee. Let's
simplify that and move it over, too
2019-03-05 16:50:58 +01:00
Lennart Poettering 8312d69409 bootspec: stat() on an autofs mount point doesn't trigger it, let's hence do it explicitly 2019-03-01 12:41:32 +01:00
Lennart Poettering dd2bf34cd0 bootspec: only sort entries list once
Instead of re-sorting entries list each time we loaded enrties from a
specific source, let's just sort them once at the end.
2019-03-01 12:41:32 +01:00
Lennart Poettering 5e146a75b3 bootspec: also look for boot loader spec type 2 entries (i.e. unified kernel images)
sd-boot reads them, and hence we should from our userspace side too
2019-03-01 12:41:32 +01:00
Lennart Poettering 4a4994b68d bootspec: use verify_fsroot_dir() in verify_xbootldr() too
Let's share some code between verify_xbootldr() and verify_esp().
2019-03-01 12:41:32 +01:00
Lennart Poettering 85d021023f bootspec: also optoinally validate XBOOTLDR partition with udev insteado of blkid 2019-03-01 12:41:32 +01:00
Lennart Poettering 18ae9ef1a5 bootspec: split out code that validates whether directory is top-level dir of fs
Let's add a new function that checks whether some directory is the
top-level directory inside an fs, splitting out the code for this from
verify_esp().

While we are at it, let's slightly improve the code, so that we can
correctly work if we have no priviliges but the ESP is mounted
unaccessible: if we can't stat() the path "$ESP/.." then manually remove
the last component of $ESP and check that instead. Which is very similar
in behaviour, and hopefully good enough in the unprivileged case.
2019-03-01 12:41:32 +01:00
Lennart Poettering cedb9eec76 bootspec: if unprivileged validate partition data with udev rather than blkid directly
udev metadata access works unprivileged, which the blkid stuff doesn't
(as that needs raw device node access). Hence let's use udev if we lack
privs, and raw device access only if root.
2019-03-01 12:41:32 +01:00
Lennart Poettering ad95aa44d6 bootspec: also split out XBOOTLDR partition blkid code into its own function 2019-03-01 12:41:32 +01:00
Lennart Poettering 575d437032 bootspec: split out ESP blkid validation into function of its own
This makes it easier to add an alternative implementation for this that
uses sd-device instead of blkid directly.
2019-03-01 12:41:32 +01:00
Lennart Poettering 23953a3ef8 bootspec: add comment explaining verify_esp() return codes 2019-03-01 12:41:32 +01:00
Lennart Poettering a7afbd60e3 bootspec: use SYNTHETIC_ERRNO() where appropriate 2019-03-01 12:41:32 +01:00
Lennart Poettering a2f8664e9a bootspec: load entries from both the ESP and XBOOTLDR partitions
Let's simply search in both.
2019-03-01 12:41:32 +01:00
Lennart Poettering 43b736a84b bootspec: store 'root' field in each bootspec entry we load
This 'root' field contains the root path of the partition we found the
snippet in. The 'kernel', 'initrd', 'efi', … fields are relative to this
path.

This becomes particularly useful later when we add support for loading
snippets from both the ESP and XBOOTLDR, but already simplifies the code
for us a bit in systemctl.
2019-03-01 12:41:32 +01:00
Lennart Poettering 15cb6c9897 bootspec: add internal APIs to discover the XBOOTLDR partition 2019-03-01 12:41:32 +01:00
Lennart Poettering 46bba8a51c bootspec: use SYNTHETIC_ERRNO() at one more place 2019-03-01 12:41:32 +01:00
Lennart Poettering feb41f1ffe bootspec: update log message, to indicate the error is ignored 2019-03-01 12:41:32 +01:00
Lennart Poettering 54b22b2643 tree-wide: port various parts of the code over to the new device_major_minor_path() calls 2018-11-29 20:21:39 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Lennart Poettering cc7a0bfa15 bootspec: introduce SYSTEMD_ESP_PATH for overriding where to look for the ESP (#10834) 2018-11-20 12:37:01 +09:00
Lennart Poettering 8cbb7d8783 efi: allow ESP validity checks to be turned off
let's add an env var for this, as this really shouldn't be a top-level
feature, as it turning off the validity checks certainly isn't
advisable.

Fixes: #4925
2018-10-08 21:40:44 +02:00
Lennart Poettering 9c4a6c1319 bootspec: access EFI variables on on EFI boots 2018-10-08 21:40:44 +02:00
Lennart Poettering f91ed3dc81 bootspec: it's fine if loader.conf is absent
We shouldn't generate an error in that case, as the file is optional.
2018-10-08 21:40:44 +02:00
Lennart Poettering 0de2e1fd2e bootspec: reduce number of functions we export
Let's internalize these four calls as noone else calls them.
2018-10-08 21:40:44 +02:00
Lennart Poettering 21f7a622d5 bootspec: remove redundant logging
boot_loader_read_conf(), boot_entries_find(), boot_entries_load_config()
all log their errors internally, hence no need to log a second or third
time about the same error when they return.
2018-10-08 21:40:44 +02:00
Zbigniew Jędrzejewski-Szmek 2d3bfb6904 shared/bootspec: remember the full path to boot entry and use it in logging
It's much easier to understand what is going on when the full path is
logged.
2018-10-08 17:05:17 +02:00
Zbigniew Jędrzejewski-Szmek 1b20d88987 Move logic to find default sd-boot entry from systemctl to shared
In preparation for use in other places. No functional change.
2018-10-08 16:06:26 +02:00
Lennart Poettering 12580bc3ed bootspec: rename "filename" field to "id"
This follows the renaming done a few commits earlier too systemd-boot
itself.

Also, let's show the ID, since it's useful.
2018-09-27 17:31:37 +02:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Zbigniew Jędrzejewski-Szmek 58f21e63b4 Fix SPDX license tags 2018-06-14 13:05:41 +02:00