Commit Graph

6563 Commits

Author SHA1 Message Date
Lennart Poettering
eb2a610210 Merge pull request #25410 from DaanDeMeyer/mkfs-xfs-fixes
Followups for #25400
2022-11-18 14:45:48 +01:00
Lennart Poettering
fa4c01933d Merge pull request #25333 from yuwata/find-esp-part-entry-scheme
find-esp: downgrade and ignore error on retrieving PART_ENTRY_SCHEME
2022-11-17 15:28:54 +01:00
Daan De Meyer
48ac1fd132 Followups for aa6aa81c1e 2022-11-17 14:14:45 +01:00
Daan De Meyer
dd3c825294 tmpfile-util: Introduce fopen_temporary_child()
Instead of having fopen_temporary() create the file either next
to an existing file or in tmp/, let's split this up clearly into
two different functions, one for creating temporary files next to
existing files, and one for creating a temporary file in a directory.
2022-11-17 14:14:31 +01:00
Vitaly Kuznetsov
155c51293d shared/tpm2-util: Fix "Error: Esys invalid ESAPI handle (40000001)" warning
systemd-cryptenroll complains (but succeeds!) upon binding to a signed PCR
policy:

$ systemd-cryptenroll --unlock-key-file=/tmp/passphrase --tpm2-device=auto
  --tpm2-public-key=... --tpm2-signature=..." /tmp/tmp.img

ERROR:esys:src/tss2-esys/esys_iutil.c:394:iesys_handle_to_tpm_handle() Error: Esys invalid ESAPI handle (40000001).
WARNING:esys:src/tss2-esys/esys_iutil.c:415:iesys_is_platform_handle() Convert handle from TPM2_RH to ESYS_TR, got: 0x40000001
ERROR:esys:src/tss2-esys/esys_iutil.c:394:iesys_handle_to_tpm_handle() Error: Esys invalid ESAPI handle (40000001).
WARNING:esys:src/tss2-esys/esys_iutil.c:415:iesys_is_platform_handle() Convert handle from TPM2_RH to ESYS_TR, got: 0x4000000
New TPM2 token enrolled as key slot 1.

The problem seems to be that Esys_LoadExternal() function from tpm2-tss
expects a 'ESYS_TR_RH*' constant specifying the requested hierarchy and not
a 'TPM2_RH_*' one (see Esys_LoadExternal() -> Esys_LoadExternal_Async() ->
iesys_handle_to_tpm_handle() call chain).

It all works because Esys_LoadExternal_Async() falls back to using the
supplied values when iesys_handle_to_tpm_handle() fails:

    r = iesys_handle_to_tpm_handle(hierarchy, &tpm_hierarchy);
    if (r != TSS2_RC_SUCCESS) {
        ...
        tpm_hierarchy = hierarchy;
    }

Note, TPM2_RH_OWNER was used on purpose to support older tpm2-tss versions
(pre https://github.com/tpm2-software/tpm2-tss/pull/1531), use meson magic
to preserve compatibility.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2022-11-16 21:45:57 +01:00
Daan De Meyer
aa6aa81c1e mkfs-util: Add support for rootless xfs population
We use mkfs.xfs's protofile (-p) support to achieve this. The
protofile is a description of the files that should be copied into
the filesystem. The format is described in the manpage of mkfs.xfs.
2022-11-16 15:38:17 +01:00
Lennart Poettering
1282fec93f Merge pull request #25310 from jlinton/fpdt_dev_mem_alt
acpi-fpdt: Use kernel fpdt parsing
2022-11-16 14:55:17 +01:00
Lennart Poettering
155519f4a3 Merge pull request #25393 from poettering/tpm2-override
tpm2-util: force default TCTI to be "device" with parameter "/dev/tpm…
2022-11-16 14:30:26 +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
Daan De Meyer
bb8b8875f4 Merge pull request #24944 from DaanDeMeyer/repart-rootless
repart: Add support for running without root privileges
2022-11-16 09:09:06 +01:00
Lennart Poettering
50a085143f tpm2: add some extra validation of device string before using it
Let's add some extra validation before constructing and using the .so
name to load. This isn't really security sensitive, given that we
used secure_getenv() to get the device string (and it thus should have
been come from a trusted source) but let's better be safe than sorry.
2022-11-15 23:14:54 +01:00
Lennart Poettering
34906680af tpm2-util: force default TCTI to be "device" with parameter "/dev/tpmrm0"
Apparently some distros default to tss-abmrd. Let's bypass that and
always go to the kernel resource manager.

abmrd cannot really work for us, since we want to access the TPM already
in earliest boot i.e. in environments the abmrd service is not available
in.

Fixes: #25352
2022-11-15 23:14:13 +01:00
Pasha Vorobyev
d7fe0a6723 MemoryZSwapMax directive to configure new memory.zswap.max cgroup file 2022-11-15 21:15:37 +01:00
Daan De Meyer
e59678b2cf repart: Ensure files end up owned by root in generated filesystems
By forking off a user namespace before running mkfs and ID mapping
the user running repart to root in the user namespace, we can make
sure that files in the generated filesystems are all owned by root
instead of the user running repart.

To make this work we have to make sure that all the files in the
root directory that's passed to the mkfs binary are owned by the
user running repart, so we have to drop the shortcut for only a
single root directory in partition_populate_directory().
2022-11-15 20:23:51 +01:00
Daan De Meyer
48a09a8fff repart: Do offline encryption instead of online
Offline encryption can be done without mounting the luks device. For
now we still use loop devices to split out the partition we want to
write to but in a later commit we'll replace this with a regular file.

For offline encryption, we need to keep 2x the luks header size space
free at the end of the partition, so this means our encrypted partitions
will be 16M larger than before.
2022-11-15 20:07:54 +01:00
Daan De Meyer
bf3598beff mkfs-util: Add support to populate vfat without mounting using mcopy
mkfs.vfat doesn't support specifying a root directory to bootstrap
the filesystem from (see https://github.com/dosfstools/dosfstools/issues/183).
Instead, we can use the mcopy tool from the mtools package to copy
files into the vfat filesystem after creating it without needing to
mount the vfat filesystem.
2022-11-15 20:07:54 +01:00
Daan De Meyer
59e2be46cc mkfs-util: Add root support for ext and btrfs
For these filesysrems, it's useful to provide the filesystem upfront
so that we don't have to mount it later which requires root privileges.
2022-11-15 20:07:54 +01:00
Daan De Meyer
ddf615a11c mkfs-util: Make argument handling for mkfs binaries more flexible
Preparation for the next commit.
2022-11-15 20:07:54 +01:00
Daan De Meyer
c93b0efdb9 btrfs-util: Remove bogus assert()
If size is zero, BTRFS_IOC_CLONE_RANGE will copy until the end of
the source file.
2022-11-15 20:07:54 +01:00
Daan De Meyer
22e932f4d1 gpt: Expose GptPartitionType and get rid of SECONDARY/OTHER
Instead of exposing just the partition type UUID, let's expose the
GptPartitionType struct, which has a lot more information available
in a much more accessible way.

Also, let's get rid of SECONDARY/OTHER in PartitionDesignator. These
were only there to support preferred architectures in dissect-image.c,
but we can easily handle that by comparing architectures when we decide
whether to override a partition. This is done in a new function
compare_arch().
2022-11-15 13:27:15 +01:00
Daan De Meyer
32a3f802f6 Merge pull request #24908 from DaanDeMeyer/repart-minimize
repart: Add Minimize setting
2022-11-15 08:19:28 +01:00
Jeremy Linton
bc09c2d865 acpi-fpdt: Use kernel fpdt parsing
On some kernels/distros (RHEL/aarch64) /dev/mem is
turned off. This means that the ACPI FPDT data is
missing from systemd-analyze output when /dev/mem
fails to provide the boot times.

Instead recent kernels can export that data from
/sys/firmware/acpi/fpdt/boot/ entries. Use that
information if available first.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
2022-11-14 20:07:57 -06:00
Mike Yuan
dab0156f03 module-util: use the blacklist from module_blacklist= in cmdline
When a module is blacklisted using module_blacklist=
we shouldn't fail with 'Operation not permitted'.
Instead we check for it and skip it if this is the case.
2022-11-14 10:52:01 +09:00
Yu Watanabe
088377e092 dissect-image: do not try to close invalid fd
Fixes a bug introduced by f7725647bb.

Hopefully fixes #25348.
2022-11-13 21:02:53 +01:00
Yu Watanabe
d6c817358c Merge pull request #25338 from DaanDeMeyer/at-fixes
Followups for #24813
2022-11-13 22:59:40 +09:00
Yu Watanabe
87172c3df6 Merge pull request #25360 from poettering/strv-fixes
nulstr fixes
2022-11-13 20:17:10 +09:00
Yu Watanabe
8ce056c171 Merge pull request #25355 from poettering/chase-symlinks-no-symlink
chase_symlinks(): add CHASE_PROHIBIT_SYMLINKS
2022-11-13 20:16:34 +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
Lennart Poettering
76078ad850 nulstr-util: fix corner cases of strv_make_nulstr()
Let's change the return semantics of strv_make_nulstr() so that we can
properly distuingish the case where we have a no entries in the nulstr
from the case where we have a single empty string in a nulstr.

Previously we couldn't distuingish those, we'd in both cases return a
size of zero, and a buffer with two NUL bytes.

With this change, we'll still return a buffer with two NULL bytes, but
for the case where no entries are defined we'll return a size of zero,
and where we have two a size of one.

This is a good idea, as it makes sure we can properly handle all corner
cases.

Nowadays the function is used by one place only: ask-password-api.c. The
corner case never mattered there, since it was used to serialize
passwords, and it was known that there was exactly one password, not
less. But let's clean this up. This means the subtraction of the final
NUL byte now happens in ask-password-api.c instead.
2022-11-13 17:40:59 +09:00
Lennart Poettering
08af3cc5a5 strv: move nulstr utilities to nulstr-util.[ch]
Let's move them out of the generic, already very long strv.[ch] module
into the more specific nulst-util.[ch]

No code changes.
2022-11-13 17:39:08 +09:00
Lennart Poettering
d3a3a0fae3 format-table: teach table_add_cell_stringf_full() to generate TABLE_FIELD/TABLE_HEADER cells, too 2022-11-13 17:36:22 +09:00
Lennart Poettering
8f6469cbf9 format-table: introduce TABLE_HEADER cell type
This rework the logic for handling the "header" cells a bit. Instead of
special casing the first row in regards to uppercasing/coloring let's
just intrduce a proper cell type TABLE_HEADER which is in most ways
identical to TABLE_STRING except that it defaults to uppercase output
and underlined coloring.

This is mostly refactoring, but I think it makes a ton of sense as it
makes the first row less special and you could in fact insert
TABLE_HEADER (and in fact TABLE_FIELD) cells wherever you like and
something sensible would happen (i.e. a string cell is displayed with
a specific formatting).
2022-11-13 17:36:22 +09:00
Yu Watanabe
1c03f7f4ba ac-power: check battery existence and status
If a battery is not present or its status is not discharging, then
the battery should not be used as a power source.
Let's count batteries currently discharging.

Fixes #25316.
2022-11-13 17:35:27 +09:00
Yu Watanabe
388d14659d find-esp: include device sysname in the log message 2022-11-13 13:27:36 +09:00
Yu Watanabe
01f234c6f5 find-esp: downgrade and ignore error on retrieving PART_ENTRY_SCHEME when searching
Fixes #25332.
2022-11-13 13:22:31 +09:00
Luca Boccassi
0d217f6349 Merge pull request #25268 from PeterCxy/fido2-preflight
libfido2-util: Perform pre-flight check for credentials in token
2022-11-12 15:51:47 +01:00
Cristian Rodríguez
9264db1a0a shared|install: Use InstallChangeType consistently
gcc 13 -Wenum-int-mismatch, enabled by default, reminds us enum ! = int
2022-11-12 00:40:16 +00:00
MkfsSion
32f57b0986 libfido2-util: Perform pre-flight check for credentials in token
Do not attempt to decrypt using a key slot unless its corresponding
credential is found on an available FIDO2 token. Avoids multiple touches
/ confirmations when unlocking a LUKS2 device with multiple FIDO2 tokens
enrolled.

Partially fixes #19208 (when the libcryptsetup plugin is in use).
2022-11-11 18:51:07 -05:00
MkfsSion
15203f77a9 libfido2-util: Extract error handling logic from fido2_use_hmac_hash_specific_token 2022-11-11 18:51:07 -05:00
MkfsSion
098f72ceee libfido2-util: Commonize FIDO2 basic property settings
These properties are repeatedly set across multiple functions.
2022-11-11 18:51:07 -05:00
Daan De Meyer
12e2b70f9b nulstr-util: Declare NULSTR_FOREACH() iterator inline 2022-11-11 16:31:32 +01:00
Daan De Meyer
78b66c027e resize-fs: Bump xfs minimum partition size to 16MB
14MB leads to errors in mkfs.xfs when running repart.
2022-11-11 13:48:21 +01:00
Daan De Meyer
46fddd8eb6 Merge pull request #24803 from DaanDeMeyer/repart-copy-deny-list
repart: Don't descend into directories assigned to other partitions
2022-11-11 13:19:58 +01:00
Daan De Meyer
cc085ec65f Revert "rm-rf: Add rm_rf_physical_and_close()"
This reverts commit 56e2bceddc.

Doing destructive cleanup operations via unreliable /proc path
lookups is unsafe and should be avoided so let's remove this function.
2022-11-11 10:19:18 +01:00
Yu Watanabe
b27c803601 Merge pull request #25328 from poettering/vertical-tables
format-table: add concept of "vertical" table
2022-11-11 15:18:12 +09:00
Luca Boccassi
021397f776 Merge pull request #25325 from yuwata/resolve-cap-per-link-setting-by-global
resolve: provide effective mDNS or LLMNR settings
2022-11-10 23:20:40 +01:00
Lennart Poettering
c6bf9dff3a format-table: add an explicit "vertical" mode
Originally, the table formatting code was written to display a number of
records, one per line, and within each line multiple fields of the same
record. The first line contains the column names.

It was then started to be used in a "vertical" mode however,
i.e. with field names on the left instead of the top. Let's support such
a mode explicitly, so that we can provide systematic styling, and can
properly convert this mode to JSON.

A new constructor "table_new_vertical()" is added creating such
"vertical" tables. Internally, this is a table with two columns: "key"
and "value". When outputting this as JSON we'll output a single JSON
object, with key/value as fields. (Which is different from the
traditional output where we'd use the first line as JSON field names,
and output an array of objects).

A new cell type TABLE_FIELD is added for specifically marking the
"field" cells, i.e. the cells in the first column. We'll automatically
suffic ":" to these fields on output.
2022-11-10 23:09:18 +01:00
Daan De Meyer
58b4ad76ca gpt: Add gpt_partition_type_mountpoint_nulstr() 2022-11-10 16:40:33 +01:00
Daan De Meyer
dd8940235f gpt: Replace bitfields with designator field in GptPartitionType
To achieve this we move the PartitionDesignator enum from
dissect-image.h to gpt.h
2022-11-10 16:40:33 +01:00
Daan De Meyer
a424958aa6 copy: Support passing a deny list of files/directories to not copy 2022-11-10 16:40:31 +01:00