Commit Graph
324 Commits
Author SHA1 Message Date
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Antonio Alvarez Feijoo 4697ee9f43 bootctl: fix -q option
Follow up to 14e6e444dd
2023-11-06 16:36:38 +00:00
Zbigniew Jędrzejewski-Szmek eb98074b5c bootctl: use pager in help
The output is more than one page, let's enable the pager.
2023-09-14 22:32:20 +02:00
Lennart Poettering 0de0ed6e89 bootctl: don't advertise systemd-efi-options in --help/man anymore
The command is deprecated, as per NEWS of 254. Let's go one step further
and remove it from the help text and man page, so that people are not
inspired to use it at this time anymore.

This is how we usually have done this before: remove it from visibility,
but support it for a while still.
2023-08-09 14:25:46 +02:00
Lennart Poettering d5163f9c87 NEWS/--help: correct/be clearer on bootclt -R vs. -RR
The NEWS file was simply wrong. Let's also improve the --help text on
this.

Fixes: #28221
2023-07-04 12:50:22 +01:00
Mike Yuan 93d82cfcae bootctl: log correct error about device_path_make_canonical() 2023-06-23 23:57:49 +08:00
Lennart Poettering 2d0855154f bootctl: fix docs/--help to say that "bootctl random-seed" not just initializes but also refreshes ESP random seeds 2023-06-14 11:58:37 +01:00
Lennart Poettering 0b2aa2064f find-esp: change "unprivileged_mode" parameter to be tristate
Previously, unprivileged mode for find_esp_and_warn() and
find_xbootldr_and_warn() could be enabled or disabled. With this change
it can also be set to negative in which case the functions will enable
it automatically if found to be executing without privileges.

This just moves te geteuid() check we often do for the param inside of
the functions.

At the same time internally in the functions we also pass around the
VerifyESPFlags field across the various functions instead of booleans.

Both changes are just refactoring. No changes in behaviour.
2023-05-31 10:12:47 +02:00
Lennart Poettering a4b3e94236 dissect-image: port mount_image_privately_interactively() to use /run/systemd/mount-rootfs/ too
Let's use the same common directory as the unit logic uses.

This means we have less to clean up, and opens the door to eventually
allow unprivileged operation of the
mount_image_privately_interactively() logic.
2023-05-16 09:26:17 +02:00
Yu Watanabe 06e78680e3 image-policy: introduce parse_image_policy_argument() helper
Addresses
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1060130312,
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067927293, and
https://github.com/systemd/systemd/pull/25608/commits/84be0c710d9d562f6d2cf986cc2a8ff4c98a138b#r1067926416.

Follow-up for 84be0c710d.
2023-04-13 11:17:28 +02:00
Lennart Poettering 84be0c710d tree-wide: hook up image dissection policy logic everywhere 2023-04-05 20:45:30 +02:00
Zbigniew Jędrzejewski-Szmek 51214cf491 various: simplify calls to parse_boolean_argument()
parse_boolean_argument() returns the same information via both the output
argument and normal return.
2023-04-05 13:06:26 +08:00
Yu Watanabe 9e43296fd2 bootctl: split-out entry token related definitions into boot-entry.[ch]
No functional change, just preparation for later commits.
These can be used in kernel-install later.

Note, unlike the our usual coding style, the arguments for
boot_entry_token_ensure() and parse_boot_entry_token_type() are
referenced, updated, and may freed, hence, always pass initialized
values. That's why they are not named as 'ret_xyz'.
2023-03-27 09:51:18 +02:00
Yu Watanabe 87dc8b0851 bootctl: enable colored logging 2023-03-25 12:38:11 +09:00
Yu Watanabe 03221e746d bootctl: return 0 instead of EXIT_SUCCESS 2023-03-17 20:40:34 +09:00
Lennart Poettering c56be2c294 bootctl: add new --print-root-device option
We already have this nice code in system that determines the block
device backing the root file system, but it's only used internally in
systemd-gpt-generator. Let's make this more accessible and expose it
directly in bootctl.

It doesn't fit immediately into the topic of bootctl, but I think it's
close enough and behaves very similar to the existing "bootctl
--print-boot-path" and "--print-esp-path" tools.

If --print-root-device (or -R) is specified once, will show the block device
backing the root fs, and if specified twice (probably easier: -RR) it
will show the whole block device that block device belongs to in case it
is a partition block device.

Suggested use:

        # cfdisk `bootctl -RR`

To get access to the partition table, behind the OS install, for
whatever it might be.
2023-02-21 18:19:38 +01:00
Daan De Meyer a133d2c366 dissect-image: Return mount point fd if requested 2023-02-17 14:58:55 +01:00
Lennart Poettering e684d2d5f8 bootctl: remove space that should not be there 2023-01-20 18:42:25 +01:00
Lennart Poettering eab7061898 bootctl: split out boot loader spec + boot loader interface commands in --help text
grub (at least on fedora) nowadays implements the boot loader spec, but
not the boot loader interface. Hence let's split out the commands
specific to each in two groups in the --help text. This way the first
group just covers boot lodaer spec stuff (i.e. stuff on disk in the
ESP/XBOOTLDR partition). And the other covers talking to the boot loader
via EFI var.
2023-01-20 18:42:25 +01:00
Lennart Poettering 5bbf72bb9e bootctl: realign column in --help text
for some reason the descriptions of the switches and the commands
weren't aligned, one space off. Fix that.
2023-01-20 18:30:47 +01:00
Lennart Poettering 1e7d6cc072 bootctl: change section title for kernel image commands
Let's call them kernel *images*, not just *kernels*.
2023-01-20 18:30:06 +01:00
Lennart Poettering 2b197967bf bootctl: drop full stop at end of --help texts
We never do that, don't do so here either.
2023-01-20 18:29:15 +01:00
Gerd Hoffmann 24a3b37f12 bootctl: add kernel-inspect to --help text 2023-01-20 14:17:51 +00:00
Ludwig Nussel 8702496bfb bootctl: unlink and cleanup functions
The unlink command removes an entry from the ESP including
referenced files that are not referenced in other entries. That is
useful eg to have multiple entries that use the same kernel with
different options.

The cleanup command removes all files that are not referenced by any
entry.
2023-01-19 14:24:43 +01:00
Gerd Hoffmann a05255981b bootctl: add kernel-inspect command
Takes a kernel image as argument. Prints details about the kernel.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2023-01-18 14:32:14 +01:00
Gerd Hoffmann 53c368d71b bootctl: add kernel-identity command
The command takes a kernel as argument and checks what kind of kernel
the image is.  Returns one of uki, pe or unknown.
2023-01-18 14:32:14 +01:00
Lennart Poettering baafb202f8 bootctl: split out "install" verb too 2022-12-19 12:08:02 +01:00
Lennart Poettering da36788f65 bootctl: split out "status" verb too 2022-12-19 12:08:02 +01:00
Lennart Poettering 6d8ca25766 bootctl: split out "set-efivar" verbs, too 2022-12-19 12:06:33 +01:00
Lennart Poettering 6e975890a6 bootctl: also split out 'systemd-efi-options' verb 2022-12-19 11:52:09 +01:00
Lennart Poettering 85f875357b bootctl: split out random seed verb, too 2022-12-19 11:43:19 +01:00
Lennart Poettering 34ea7e0232 bootctl: let's start splitting up bootctl like we did for systemctl and others 2022-12-19 11:43:19 +01:00
Zbigniew Jędrzejewski-Szmek 2053593fcc treewide: drop "RUN_" from "RUN_WITH_UMASK"
RUN_WITH_UMASK was initially conceived for spawning externals progs with the
umask set. But nowadays we use it various syscalls and stuff that doesn't "run"
anything, so the "RUN_" prefix has outlived its usefulness.
2022-12-13 14:39:30 +01:00
Yu Watanabe 057bf780e9 sd-id128: make id128_read() or friends return -ENOPKG when the file contents is "uninitialized"
Then, this drops ID128_PLAIN_OR_UNINIT. Also, this renames
Id128Format -> Id128FormatFlag, and make it bitfield.

Fixes #25634.
2022-12-12 21:57:31 +09:00
Jason A. Donenfeld 0a1d8ac77a stub: handle random seed like sd-boot does
sd-stub has an opportunity to handle the seed the same way sd-boot does,
which would have benefits for UKIs when sd-boot is not in use. This
commit wires that up.

It refactors the XBOOTLDR partition discovery to also find the ESP
partition, so that it access the random seed there.
2022-11-23 00:56:45 +01:00
Jason A. Donenfeld a4eea6038c bootctl: install system token on virtualized systems
Removing the virtualization check might not be the worst thing in the
world, and would potentially get many, many more systems properly seeded
rather than not seeded. There are a few reasons to consider this:

- In most QEMU setups and most guides on how to setup QEMU, a separate
  pflash file is used for nvram variables, and this generally isn't
  copied around.

- We're now hashing in a timestamp, which should provide some level of
  differentiation, given that EFI_TIME has a nanoseconds field.

- The kernel itself will additionally hash in: a high resolution time
  stamp, a cycle counter, RDRAND output, the VMGENID uniquely
  identifying the virtual machine, any other seeds from the hypervisor
  (like from FDT or setup_data).

- During early boot, the RNG is reseeded quite frequently to account for
  the importance of early differentiation.

So maybe the mitigating factors make the actual feared problem
significantly less likely and therefore the pros of having file-based
seeding might outweigh the cons of weird misconfigured setups having a
hypothetical problem on first boot.
2022-11-21 15:13:26 +01:00
Lennart Poettering af1bed8e83 bootctl: rework how we handle referenced but absent EFI boot entries
Follow-up for #25368.

Let's consider ENOENT an expected error, and just debug log about it
(though, let's suffix it with `, ignoring.`). All other errors will log
loudly, as they are unexpected errors.
2022-11-19 05:27:50 +09:00
Jason A. Donenfeld 3daeef0884 random-seed: handle post-merge review nits
These are various misc things that came up after merging.
2022-11-17 12:22:27 +01:00
Luca Boccassi 39a306ba34 Merge pull request #25319 from zx2c4-forks/krngseed
boot: implement kernel EFI RNG seed protocol with proper hashing
2022-11-16 15:07:54 +01:00
Jason A. Donenfeld 0be72218f1 boot: implement kernel EFI RNG seed protocol with proper hashing
Rather than passing seeds up to userspace via EFI variables, pass seeds
directly to the kernel's EFI stub loader, via LINUX_EFI_RANDOM_SEED_TABLE_GUID.
EFI variables can potentially leak and suffer from forward secrecy
issues, and processing these with userspace means that they are
initialized much too late in boot to be useful. In contrast,
LINUX_EFI_RANDOM_SEED_TABLE_GUID uses EFI configuration tables, and so
is hidden from userspace entirely, and is parsed extremely early on by
the kernel, so that every single call to get_random_bytes() by the
kernel is seeded.

In order to do this properly, we use a bit more robust hashing scheme,
and make sure that each input is properly memzeroed out after use. The
scheme is:

    key = HASH(LABEL || sizeof(input1) || input1 || ... || sizeof(inputN) || inputN)
    new_disk_seed = HASH(key || 0)
    seed_for_linux = HASH(key || 1)

The various inputs are:
- LINUX_EFI_RANDOM_SEED_TABLE_GUID from prior bootloaders
- 256 bits of seed from EFI's RNG
- The (immutable) system token, from its EFI variable
- The prior on-disk seed
- The UEFI monotonic counter
- A timestamp

This also adjusts the secure boot semantics, so that the operation is
only aborted if it's not possible to get random bytes from EFI's RNG or
a prior boot stage. With the proper hashing scheme, this should make
boot seeds safe even on secure boot.

There is currently a bug in Linux's EFI stub in which if the EFI stub
manages to generate random bytes on its own using EFI's RNG, it will
ignore what the bootloader passes. That's annoying, but it means that
either way, via systemd-boot or via EFI stub's mechanism, the RNG *does*
get initialized in a good safe way. And this bug is now fixed in the
efi.git tree, and will hopefully be backported to older kernels.

As the kernel recommends, the resultant seeds are 256 bits and are
allocated using pool memory of type EfiACPIReclaimMemory, so that it
gets freed at the right moment in boot.
2022-11-14 15:21:58 +01:00
Yu Watanabe bf0d5cba56 Merge pull request #25368 from yuwata/bootctl-ignore-invalid-boot-entries
bootctl: ignore invalid boot entries
2022-11-14 10:51:33 +09: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
Yu Watanabe 78bfeeae50 bootctl: downgrade log message when firmware reports non-existent or invalid boot entry
Fixes #25359.
2022-11-13 14:41:28 +09:00
Yu Watanabe a7dcb75c53 bootctl: make boot entry id logged in hex
To make consistent with the printed boot id below and other tools e.g.
efibootmgr.
2022-11-13 14:36:09 +09:00
Zbigniew Jędrzejewski-Szmek d6b4d1c7c4 basic: move version() to build.h+c 2022-11-08 13:41:14 +01:00
Yu Watanabe e330f97a89 tree-wide: drop unused reference to DecryptedImage 2022-09-18 23:47:20 +09:00
Jan Janssen c0f86d66f3 tree-wide: Use correct format specifiers
gcc will complain about all these with -Wformat-signedness.
2022-08-30 12:03:28 +02:00
Lennart Poettering 3730dc5d5b bootctl: port some more code over to chase_symlinks() from prefix_roota()
This is far from complete, but let's start moving this way.
2022-08-22 14:07:45 +02:00
Rene Hollander d9bdb29bf5 Add --efi-boot-option-description argument to bootctl to control the name of the boot
entry.

By default an entry named "Linux Boot Manager" is created (which is the
previous behavior). With the flag the name of the entry can be
controlled, which is useful when installing systemd-boot to multiple ESP
partitions and having uniquely named entries.

Fixes #17044.
2022-08-19 14:55:31 +02:00
Frantisek Sumsal cd7ad0cbde Merge pull request #24054 from keszybz/initrd-no-reload
Don't do daemon-reload in the initrd
2022-08-18 13:15:14 +00:00