Commit Graph

84475 Commits

Author SHA1 Message Date
Lennart Poettering
330e66f15e doc: document NvPCRs briefly 2025-11-02 21:26:13 +01:00
Lennart Poettering
34c687f2b3 ci: add some test for the new nvpcr infra 2025-11-02 21:26:13 +01:00
Lennart Poettering
a9d02df0c7 ci: never go to raw tpm device, always go via resource manager 2025-11-02 21:14:35 +01:00
Lennart Poettering
d73d369133 analyze: add new verb for determining NvPCR values 2025-11-02 21:14:35 +01:00
Lennart Poettering
e5a2e78665 cryptsetup: automatically measure used keyslot and mechanism (i.e. fido2, tpm2, pkcs11) to an NvPCR
Fixes: #29877
2025-11-02 21:14:35 +01:00
Lennart Poettering
8a6e77f1a8 tpm2-setup: measure "anchor" extension early at boot into nvpcrs 2025-11-02 21:14:35 +01:00
Lennart Poettering
2da86d62ff tpm2-setup: split out SRK setup into a function of its own 2025-11-02 21:14:35 +01:00
Lennart Poettering
0196abbd10 pcrextend: automatically measure SMBIOS product ID at boot
Now that PCRs are not that expensive anymore, let's use them to measure
the SMBIOS product ID to one.
2025-11-02 21:14:35 +01:00
Lennart Poettering
2b90bf1730 pcrextend: make use new nvindex-based PCRs 2025-11-02 21:14:35 +01:00
Lennart Poettering
f5f26332fa catalog: improve PCR extended catalog entry 2025-11-02 21:14:35 +01:00
Lennart Poettering
b0c5c6aad8 tpm2-util: add infra for allocating nvindex-based PCRs (aka "NvPCRs")
We'd like to measure various additional things into PCRs, but all
available ones to the OS are already used for various purposes. Hence,
let's introduce a new concept of "NV Index based PCRs", i.e. let's use
TPM2 nv indexes of type TPM2_NT_EXTEND that mostly behave like real
PCRs, but which we can allocate relatively freely from the nv index
space. Let's call these "fake" PCRs "NvPCRs".

My original intention was to get a fixed NV index range assigned from
the TCG, either for Linux or for systemd as a project, but this stalled
with no further updates from the TCG for more than a year and a half
now. I was told an NV index range to use though, even if it never was
officially assigned, hence this PR uses this by default. But the range
is configurable at build time, on purpose, so that downstreams have some
flexibility to change this if they want. To abstract the actual nvindex
number away we introduce a naming concept, so that nvindexes are
referenced by name string rather than number.

NvPCRs are defined in little JSON snippets in /usr/lib/nvpcr/*.nvpcr,
that match up index number and name, as well as pick a hash algorithm.

There's one complication: these nvindex (like any nvindex) can be
deleted by anyone with access to the TPM, and then be recreated. This
could be used to reset the NvPCRs to zero during runtime, which defeats
the whole point of them. Our way out: we measure a secret as first thing
after creation into the NvPCRs. (Or actually, we measure a per-NvPCR
secret we derive from a system secret via an HMAC of the NvPCR name) and
the nvindex handle). This "anchoring" secret is stored in /run/ +
/var/lib/ + ESP/XBOOTLDR (the latter encrypted as credential, locked to
the TPM), to make it available at the whole runtime of the OS.
2025-11-02 21:14:35 +01:00
Lennart Poettering
b7e072f3fa tpm2-util: move parse for tpm2 hash algorithms up 2025-11-02 21:14:35 +01:00
Lennart Poettering
260b9e8489 tpm2-util: make tpm2_undefine_policy_nv_index() generic
We can use this to remove any kind of nvindex, hence give it a generic
name.

Also instead of passing "NONE" as session if none is specified, pass
PASSWORD instead, so that the function actually becomes useful if no
session is specified (the only user so far, pcrlock always provides a
session, hence this is no change in behaviour).
2025-11-02 21:14:35 +01:00
Lennart Poettering
d412b1629c tpm2-util: rename tpm2_extend_bytes()→tpm2_pcr_extend_bytes() and make it take struct iovec
We soon want to add the ability to extend into nvindexes in addition to
PCRs, hence rename the function to make clear it is about pcr extension.

While we are at it, switch things over to "struct iovec" as we generally
try to do it now in tpm2-util.[ch] these days.
2025-11-02 21:14:35 +01:00
Lennart Poettering
b95912446e pcrlock: make sure we can parse nv_index measurement records in TCG CEL
Make the systemd-pcrlock tool compatible with TCG CEL records that
encode measurements into nvindexes rather than PCRs.

This doesn't add code for actually predicting them, but just makes sure
we can parse them correctly and display them reasonably.
2025-11-02 21:14:35 +01:00
Lennart Poettering
3e9ff7c0d8 creds-util: initialize default PCR mask in encrypt_credential_and_warn()
If UINT32_MAX is passed in the PCR masks pick some reasonable defaults
in encrypt_credential_and_warn().

These defaults copy what "systemd-creds encrypt" uses. By adding these
defaults to the internal functions any user of them can take benefit of
them.
2025-11-02 21:14:35 +01:00
Lennart Poettering
ffe958b98f creds-util: add helper for querying system credential dirs
The dirs are constant string, but let's make them overridable via env
vars for debugging purposes.
2025-11-02 21:14:35 +01:00
Lennart Poettering
c30e3d7290 creds-util: add automatic mode for tpm2 based creds
This reworkds TPM2 based creds a bit. Instead of mapping the key type
"tpm2" directly to a TPM2 key without PK, let's map it to an "automatic"
key type that either picks PK or doesn't, depending on what's available.
That should make things easier to grok for people, as the nitty gritty
details of PK or not PK are made autmatic. Moreover it gives us more
leverage to change the TPM2 enrollment types later (for example, we
definitely want to start pinning SRK, and hook up pcrlock too, for
creds, which we currently don't).

This hence adds a new _CRED_AUTO_TPM2
pseudo-type we automatically maps to CRED_AES256_GCM_BY_TPM2_HMAC_WITH_PK
or CRED_AES256_GCM_BY_TPM2_HMAC depending if PK as available. Similar,
_CRED_AUTO_HOST_AND_TPM2 is added, which does the same for the
host/nonhost cred type.

This does not introduce any new type on the wire, it just changes how we
select the right key type.

To make the code more readable this also adds some categorization macros
for the keys, instead of repeating the list of key types at multiple
places.
2025-11-02 21:14:35 +01:00
Lennart Poettering
d2d1fc59b4 conf-files: optionally truncate suffix from discovered files 2025-11-02 21:14:35 +01:00
Lennart Poettering
86279dc970 format-table: add field type that outputs hex values prefixed with 0x 2025-11-02 21:14:35 +01:00
Lennart Poettering
7ecc69c33b fileio: add new flag READ_FULL_FILE_VERIFY_REGULAR() that checks if file we operate on is regular 2025-11-02 21:14:35 +01:00
Lennart Poettering
1acec1c890 fileio: make filename/path argument optional in xfopenat_full(), read_full_file_full() 2025-11-02 21:14:35 +01:00
Zbigniew Jędrzejewski-Szmek
5fa2fb65a6 Enhance docs for ukify and direct kernel boots (#39516) 2025-11-02 18:04:15 +01:00
Zbigniew Jędrzejewski-Szmek
cde713bfe4 man: say "systemd-boot" instead of "sd-boot" consistently
As requested in

https://github.com/systemd/systemd/pull/39516#pullrequestreview-3407564896.
2025-11-02 15:20:59 +01:00
Zbigniew Jędrzejewski-Szmek
02539f008d man/ukify: mention all functionality in intro, add example of direct boot
Over the time, the functionality in ukify has grown. This should all be briefly
mentioned in the first section so the user does't have to read the whole page
to figure out what types of functionality are implemnted.

Also add an example of direct kernel boot. It's a nifty technology (and frankly
underutilized, considering how cool it is is).
2025-11-02 15:19:00 +01:00
Zbigniew Jędrzejewski-Szmek
4808c1686b man/sd-boot: add some meat to the direct kernel boot example
Unfortunately qemu still default to BIOS boot, so for the direct kernel
boot with an efi file to be of any use, the complex param used to switch
to UEFI mode needs to be provided.

Also add some links to qemu and OVMF.
2025-11-02 15:19:00 +01:00
Mike Yuan
a4dae3c118 rules.d/60-block.rules: fix typo 2025-11-02 10:56:31 +01:00
Yu Watanabe
c29e304562 Several OpenSSL related cleanups (#39455) 2025-11-02 17:21:51 +09:00
Alberto Planas
ab1f4e506f repart: support "nodatacow" in btrfs subvolumes
In btrfs-progs 6.15 it is planned to add a new parameter in mkfs.btrfs
--inode-flags, that can set attributes for subvolumes, directories, and
files.

The current supported attributes are "nodatacow", to disable CoW, and
"nodatasum", to disable the checksum.

This commit extend the "Subvolunes=" option to understand the
"nodatacow" flag for subvolums only.

If RepartOffline is enabled it will build the image without loopback
devices, using the correct --inode-flags parameters.

If RepartOffline is disabled it will use loopback devices and set the
btrfs attributes accordingly.

Signed-off-by: Alberto Planas <aplanas@suse.com>
2025-11-02 17:13:31 +09:00
Yu Watanabe
eeedea94da repart: fix typo
Follow-up for 15734190c7.
2025-11-02 17:03:03 +09:00
Yu Watanabe
4f589e8a50 resolvectl: fix typo
Follow-up for 7517e41a49.
2025-11-02 17:00:23 +09:00
Yu Watanabe
b7d752a67e openssl-util: drop unnecessary functions when OpenSSL support is disabled 2025-11-02 16:07:46 +09:00
Yu Watanabe
84946f12b5 openssl-util: sort cleanup functions 2025-11-02 16:07:46 +09:00
Yu Watanabe
c604b78b92 repart: drop OpenSSL specific logics when OpenSSL support is disabled 2025-11-02 16:07:46 +09:00
Yu Watanabe
e3ae29ead7 repart: merge common conditions
No functional change, just refactoring.
2025-11-02 16:07:46 +09:00
Yu Watanabe
6e91c5d8ea repart: make sign_verity_roothash() take Context
No functional change, just refactoring.
2025-11-02 16:07:46 +09:00
Yu Watanabe
0158eabb01 repart: load x509 certificate and private key after Context is allocated
This splits out context_load_keys() from parse_argv().
No functional change, just refactoring.
2025-11-02 16:07:46 +09:00
Yu Watanabe
219a67c131 bootctl: return earlier when secure boot auto-enrollment is requested but OpenSSL support is disabled 2025-11-02 16:07:46 +09:00
Yu Watanabe
1b48b63b51 bootctl: move conditions into corresponding functions 2025-11-02 16:07:46 +09:00
Yu Watanabe
61d1f394cc openssl-util: drop unused fake type definitions when OpenSSL is disabled 2025-11-02 16:07:46 +09:00
Yu Watanabe
09ae1c8ade pe-binary: drop pe_hash() and friends when OpenSSL support is disabled
These three functions are currently only used by sbsign, which requires
OpenSSL. Moreover, pe_hash() and uki_hash() anyway do not work if
OpenSSL is disabled. Let's only declare them when OpenSSL support is
enabled.
2025-11-02 16:07:46 +09:00
Yu Watanabe
ab9b3bec6a openssl-util: drop unused string_hashsum() and friends when OpenSSL is disabled 2025-11-02 16:07:46 +09:00
Yu Watanabe
a47a403ca2 resolvectl: return earlier from openpgp command when OpenSSL support is disabled
When OpenSSL is disabled, string_hashsum_sha256()/_sha224() in
resolve_openpgp() will fail anyway. Let's return earlier.
2025-11-02 16:07:46 +09:00
Yu Watanabe
a7807e66b7 coredump: several cleanups, modernizations, fixlets for corner cases (#39418) 2025-11-02 10:13:53 +09:00
Lennart Poettering
32f4e30be5 docs: add comment about requiring the mount hierarchy to be mounted MS_SHARED
This has been tripping up container manager people. let's document this
explicitly.

(Note that the container interface could really use some updates, i.e.
it was written before a time where cgroup namespacing was a thing. But I
am too lazy to fix that now, so let's just add this once facet.)
2025-11-02 00:19:57 +00:00
Yu Watanabe
ee3cd7890d Several cleanups for libcryptsetup dependency (#39452) 2025-11-02 08:07:15 +09:00
Lennart Poettering
d714edd26c repart: varlink support (#39421)
Split out of #38764

Replaces: #33741
2025-11-01 23:21:37 +01:00
Christoph Anton Mitterer
a983cf253f doc: indicate Type=oneshot also detects invocation failures
Type `simple` explicitly mentions that invocation failures like a missing binary
or `User=` name won’t get detected – whereas type `exec` mentions that it does.

Type `oneshot` refers to being similar to `simple`, which could lead one to
assume it doesn’t detect such invocation failures either – it seems however it
does.

Indicate this my changing its wording to be similar to `exec`.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2025-11-01 22:48:28 +01:00
Lennart Poettering
d1aa3860b2 ci: add testcases for recently added stuff 2025-11-01 22:01:35 +01:00
Lennart Poettering
5f076e44fe repart: report vendor/model/subsystem fields in ListCandidateDevices
Prompted by: #39435
2025-11-01 22:01:35 +01:00