Commit Graph
166 Commits
Author SHA1 Message Date
David Tardon 088d71f8ed tree-wide: use TAKE_STRUCT 2023-04-14 10:15:44 +02:00
Ludwig Nussel 4bc14b1790 bootctl: show report state and type in json output 2023-04-07 10:22:37 +02:00
Daan De Meyer f461a28da7 chase-symlinks: Rename chase_symlinks() to chase()
Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
2023-03-24 13:43:51 +01:00
Daan De Meyer 06344330a1 chase-symlinks: Remove unused ret_fd arguments 2023-03-14 13:46:58 +01:00
Ludwig Nussel e443cc7c05 bootspec: show efi entry too 2023-01-13 10:50:18 +09:00
Jan Janssen 6e689dc6ee bootctl: Fix NULL pointer dereference
Fixes: #25952
2023-01-06 10:39:41 +01:00
Lennart Poettering 4a6c6d35e4 bootspec: show default/selected entry info in JSON output
Fixes: #25889
2023-01-06 10:38:03 +01:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-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.
2022-12-19 15:00:57 +01:00
Lennart Poettering a579990277 Merge pull request #25180 from keszybz/ukify
ukify: add helper to create UKIs
2022-12-08 15:11:18 +01:00
Yu Watanabe 46dc071985 bootspec: fix null-dereference-read
Fixes [oss-fuzz#53578](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53578).
Fixes #25450.
2022-12-02 14:23:45 +01:00
Yu Watanabe 6c2d70ce9f tree-wide: fix typo 2022-12-02 13:27:08 +09:00
Zbigniew Jędrzejewski-Szmek c3f0bff945 bootctl: use output mode where "[]" is written instead for empty output
It's easier for the caller if output is always a list, even if there are no
entries.
2022-12-01 18:14:52 +01:00
Zbigniew Jędrzejewski-Szmek b570204a97 bootctl: make --json output normal json
We would output a sequence of concatenated JSON strings. 'jq' accepts such
output without fuss, and can even automatically build an array with --slurp/-s.
Nevertheless, parsing this format is more effort for the reader, since it's not
"standard JSON". E.g. Python's json module cannot do this out-of-the-box, but
needs some loop with json.JSONDecoder.raw_decode() and then collecting the
objects into an array. Such streaming output make sense in case of logs, where
we stream the output and it has no predefined length. But here we expect at
most a few dozen entries, so it's nicer to write normal JSON that is trivial to
parse.

I'm treating this is a bugfix and not attempting to provide compatibility
backwards. I don't think the previous format was seeing much use, and it's
trivial to adapt to the new one.
2022-12-01 18:00:49 +01:00
Zbigniew Jędrzejewski-Szmek 5a65d2e535 bootctl: use grey-and-slash prefix for source in list too
Follow-up for 7851732262. The source
field also shows a path relative to $BOOT, so it should be displayed
in the same fashion.
2022-11-22 01:40:20 +01:00
Jason A. Donenfeld 47b3e96647 boot: remove random-seed-mode
Now that the random seed is used on virtualized systems, there's no
point in having a random-seed-mode toggle switch. Let's just always
require it now, with the existing logic already being there to allow not
having it if EFI itself has an RNG. In other words, the logic for this
can now be automatic.
2022-11-22 01:30:03 +01:00
Zbigniew Jędrzejewski-Szmek b8d6b1608e Merge pull request #24555 from medhefgo/bootctl
bootctl: Small improvements
2022-11-16 12:27:30 +01:00
Lennart Poettering b353d5eee9 bootctl,bootspec: make use of CHASE_PROHIBIT_SYMLINKS whenever we access the ESP/XBOOTLDR
Let's make use of the new flag whenever we access the ESP or XBOOTLDR.
The resources we make use of in these partitions can't possibly use
symlinks (because UEFI knows no symlink concept), and they are untrusted
territory, hence under no circumstances we should be tricked into
following symlinks that shouldn't be there in the first place.

Of course, you might argue thta ESP/XBOOTLDR are VFAT and thus don#t
know symlinks. But the thing is, they don#t have to be. Firmware can
support other file systems too, and people can use efifs to gain access
to arbitrary Linux file systems from EFI. Hence, let's better be safe
than sorry.
2022-11-13 17:46:34 +09:00
Daan De Meyer ddfdf86f81 stat-util: Move inode_hash_ops to stat-util
TO make it usable in other code.
2022-11-10 15:59:18 +01:00
Jan Janssen 7941f11acb boot: Correctly handle @saved default patterns 2022-10-12 15:13:14 +02:00
Jan Janssen 7851732262 bootctl: Also display the root for entry paths
People apparently expect the bootloader to magically know the userspace
filesystem tree and get confused when boot files aren't found because of
this. Printing the root of entry paths will hopefully make it easier for
people to understand a bad configuration.

To hopefully make it clear that the prefix should not be used inside of
a config snipped, it is greyed out and uses an extra path separator:
    <gray>/root/</gray>/boot/loader/path
2022-10-12 15:11:14 +02:00
Lennart Poettering 8c87f2473f bootctl: don't start "bootctl list" output with a title line
Let's not output a title line given that we don't output multiple
different things here anyway, and the "bootctl list" command is about
listing boot entries anyway and it's documented that way.

Having titles for sections if we have mutliple sections of output
definitely makes sense, but if there's only one kind of information we
list it's redundant clutter.
2022-09-08 13:14:05 +02:00
Lennart Poettering f2c513048c bootspec: don't follow symlinks when opening type1/type2 files
let's not follow symlinks when going from enumeraiton dir to enumerated
file either.
2022-09-08 13:14:05 +02:00
Lennart Poettering 2683ae2d73 bootspec: use chase_symlinks() where appropriate
Let's better be safe than sorry, and follow symlinks in ESP + XBOOTLDR
via chase_symlinks() relative to the root of these files systems. This is
not a big issue given that ESP/XBOOTLDR are supposed to be VFAT where
symlinks don't exist, but the specs don't strictly require this, and by
loading efifs drivers in uefi it would be possible to support symlinks,
but we'd rather not have that here.

No real change in behaviour, just stricter rules to make me sleep better
at night.
2022-09-08 13:14:05 +02:00
Yu Watanabe 28340719f2 bootspec: shorten code a bit 2022-09-04 00:01:09 +09:00
Yu Watanabe 4d49d19e9d bootspec: do not build two many json object at once
This is a workaround for an issue in the memory sanitizer.
If a function is called with too many arguments, then the sanitizer
triggers the following false-positive warning:

==349==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f8b247134a7 in json_buildv /work/build/../../src/systemd/src/shared/json.c:3213:17
    #1 0x7f8b24714231 in json_build /work/build/../../src/systemd/src/shared/json.c:4117:13
    #2 0x7f8b24487fa5 in show_boot_entries /work/build/../../src/systemd/src/shared/bootspec.c:1424:29
    #3 0x4a6a1b in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-bootspec.c:119:16
    #4 0x4c6693 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #5 0x4c5e7a in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #6 0x4c7ce4 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:826:7
    #7 0x4c7f19 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:857:3
    #8 0x4b757f in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #9 0x4e0bd2 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #10 0x7f8b23ead082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #11 0x41f69d in _start (build-out/fuzz-bootspec+0x41f69d)

Follow-up for #24541.
Fixes #24551.
2022-09-03 23:32:50 +09:00
Lennart Poettering 293e224056 bootspec: clarify we knowingly ignore all errors but ENOMEM 2022-09-02 18:09:57 +02:00
Lennart Poettering 7f5780edfb bootspec: properly parse tries done/tries left from bootspec file names
This has been a long-time omission in the userspace parser of bootspec
files. Correct that.

Fixes: #16457
2022-09-02 18:09:57 +02:00
Lennart Poettering f70de82f9f bootspec: rename "id" function parameters to "fname"
It's really the file name, so name it like that. Just some renaming.

(This is preparation for later work, to extract tries-done/tries-left
info from filenames)
2022-09-02 16:22:46 +02:00
Lennart Poettering 9ac2a89a8f bootspec: complain about loader.conf lines without parameter 2022-09-02 16:22:46 +02:00
Lennart Poettering d68c6bea5e bootspec: port type1 parser to log_syntax() 2022-09-02 16:22:46 +02:00
Lennart Poettering da8f277c09 bootspec: let's actually use the result of strstrip() for further parsing
Also, given we are looking for whitespace as separators, just pass NULL
as separators, extract_first_word() defaults to whitespace after all.
2022-09-02 14:25:48 +02:00
Lennart Poettering bb9133bb46 bootspec: simplify paths + insist they are normalized
Inspired by #23913, let's complain if people use paths with ".."
in Type #1 bootspec entries.

Let's prefix all paths with "/" if it is missing.

Let's simplify all paths.

let's refuse paths/warn with "..".

Fixes: #23913
2022-09-02 14:25:46 +02:00
Luca Boccassi 80a2381d5c bootctl: add --root and --image
Operate on image/directory, and also take files to install from it
2022-07-08 16:58:15 +01:00
Jan Janssen 35148e8ff9 bootspec: Add PE file name to log messages
Fixes: #23783
2022-06-23 01:34:28 +09:00
Victor Westerhuis 87c7779599 Do not require a valid version when parsing sd-boot loader entries
This fixes #20820
2022-05-22 12:17:52 +02:00
Yu Watanabe df423851fc Merge pull request #23310 from keszybz/suppress-fuzzer-timeouts-and-errors
Suppress fuzzer timeouts and errors
2022-05-09 15:50:29 +09:00
Zbigniew Jędrzejewski-Szmek 2034c8b883 tree-wide: drop de-constifying casts for strv iteration
When the the iterator variable is declared automatically, it "inherits" the
const/non-const status from the argument. We don't need to cast a const
table to non-const. If we had a programming error and tried to modify the
string, the compiler could now catch this.
2022-05-08 22:47:50 +02:00
Zbigniew Jędrzejewski-Szmek d4f72d104f shared/bootspec: add missing terminator to table 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek b6bd2562eb shared/bootspec: avoid crashing on config without a value 2022-05-08 17:58:00 +02:00
Zbigniew Jędrzejewski-Szmek a847b539de shared/bootspec: also export boot_config_load_type1()
The reallocation of memory and counter incrementation is moved from
the only caller to the function. This way the callers can remain oblivious
of the BootConfig internals.
2022-05-08 17:57:57 +02:00
Zbigniew Jędrzejewski-Szmek 5ba1550fd8 shared/bootspec: expose more parts of the config parsing 2022-05-08 17:56:12 +02:00
Zbigniew Jędrzejewski-Szmek 432ce53737 Move printing of boot entries from bootctl.c to shared/
I want to use this for fuzzing, but also later to return jsonified
list of entries from logind.
2022-05-08 17:55:03 +02:00
Lennart Poettering 7176f06c9e basic: split out dev_t related calls into new devno-util.[ch]
No actual code changes, just splitting out of some dev_t handling
related calls from stat-util.[ch], they are quite a number already, and
deserve their own module now I think.

Also, try to settle on the name "devnum" as the name for the concept,
instead of "devno" or "dev" or "devid". "devnum" is the name exported in
udev APIs, hence probably best to stick to that. (this just renames a
few symbols to "devum", local variables are left untouched, to make the
patch not too invasive)

No actual code changes.
2022-04-13 16:26:31 +02:00
Lennart Poettering af9ae75026 bootspec: normalize function names/parameter lists
This normalizes naming of functions operating on BootConfig objects.
Let's always call them boot_config_xyz(), like our usual way to name
stuff.

moreover, move the BootConfig parameter to the beginning, as it's not a
return value (which we typically move to the end of the parameter list),
but simply an object, that even happens to be initialized already.

With these changes the functions are more like our usual way to call
things, and less surprises are good.
2022-03-28 16:02:15 +02:00
Lennart Poettering 3f8e42c038 bootspec: don't needlessly inline boot_config_find_entry()
the function contains a loop and if expressions and whatnot. Let's
define it as regular function, to make the header easier to read and let
the compiler more freedom on whether to inline this or not.
2022-03-28 16:01:58 +02:00
Lennart Poettering f7a7a5e267 bootspec: assess default/selected entries *after* we augmented entry list with entries from loader
Fixes: #22580
2022-03-28 16:01:36 +02:00
Lennart Poettering 92067ab672 bootspec: normalize oom handling in boot_load_efi_entry_pointers()
OOM should usually be fatal, hence make it so here, too.
2022-03-28 16:01:32 +02:00
Lennart Poettering 85e17916d3 bootspec: rename type1 parsers to say "type1" explicitly in the name
This just got too confusing for me. With this change we'll now have
_unified as common suffix for stuff loading unified kernels (i.e. type
1), and _type1 as common suffix for type1 entries.

Just some renaming.
2022-03-28 16:01:28 +02:00
Lennart Poettering d486a0eaaa bootspec: try harder to suppress duplicate enumerated entries
For testing purposes I run one of my system symlinking /boot/loader/ to
/efi/loader/. This triggers annoying behaviour in boot entry
enumeration: the code ends up iterating through the 'entries' subdir of
both, thinking one was actually in the ESP and the other in XBOOTLDR,
and thus distinct. This would result in duplicate entries.

Let's address that, and filter out duplicates via their inode numbers:
never process the same inode twice. This should protect us from any
confusion effectively, regardless which inodes are symlinked (or even
bind mounted).
2022-03-28 16:01:10 +02:00
Lennart Poettering 85f4ae2f50 bootspec: pass around BootConfig struct instead of entries/n_entries fields only
This simplifies the parameter lists quite a bit, at zero change in
behaviour.
2022-03-28 16:01:06 +02:00