Commit Graph

84503 Commits

Author SHA1 Message Date
Lennart Poettering
36e10dc5a5 tar-util: make sure we can unpack hardlinked symlinks
This is something ostree does. Yuck. But let's make t work.
2025-11-07 14:04:36 +01:00
Lennart Poettering
0ab316ff14 chase: fix typo in log message
(While we are at it, add quotes around user provided strings)
2025-11-07 14:04:19 +01:00
Yu Watanabe
82b6dc1a17 sd-json: accept NULL path in sd_json_parse_file_at() too, port one manual fdopen() to it (#39538) 2025-11-05 01:40:27 +09:00
jouyouyun
2b8c7adbec cgls: print error messages when --unit and --user-unit are used together
Mixing the `--unit` and `--user-unit` options will result in error messages.
During the parsing phase, only the `arg_show_unit` record of the last
occurrence of the option is used; all names are placed in the same `arg_names`,
thus mixing the two types of units in the query.

For example, `-u foo --user-unit bar` will also treat `foo` as a user unit and
query it in the user service.
2025-11-05 01:38:18 +09:00
Chris Down
a8c3ac6672 systemctl: Fix shutdown time parsing across DST changes
When parsing an absolute time specification like `hh:mm` for the
`shutdown` command, the code interprets a time in the past as "tomorrow
at this time". It currently implements this by adding a fixed 24-hour
duration (`USEC_PER_DAY`) to the timestamp.

This assumption breaks across DST transitions, as the day might not be
24 hours long. This can cause the shutdown to be scheduled at the wrong
time (typically off by one hour in either direction).

Change the logic to perform calendar arithmetic instead of timestamp
arithmetic. If the calculated time is in the past, we increment
`tm.tm_mday` and call `mktime_or_timegm_usec()` a second time.

This delegates all date normalization logic to `mktime()`, which
correctly handles all edge cases, including DST transitions, month-end
rollovers, and leap years.

Fixes: https://github.com/systemd/systemd/issues/39232
2025-11-05 01:36:47 +09:00
jouyouyun
05b880ac46 nss-myhostname: use FAMILY_ADDRESS_SIZE instead of the integer 16 when copying ip addr
To avoid copying extra characters when using IPv4.
2025-11-05 01:33:31 +09:00
Daan De Meyer
9d129ea34e machined/import: allow running in per-user mode (#38728) 2025-11-04 17:27:43 +01:00
Quentin Deslandes
6971798864 core: use proper service type of TEST-07-PID.user-namespace-path.sh
TEST-07-PID.user-namespace-path.sh is flaky as Type=simple is used
(implicitly), explicitly use Type=exec instead to ensure the namespaces
are created before starting another service reusing the same namespaces.

Fixes #39546.
2025-11-04 15:54:06 +00:00
Luca Boccassi
22311a1291 test: stop piping post-test journalctl commands to /failed
We can't see what the actual issues are when tests fail at that point, eg:

https://github.com/systemd/systemd/actions/runs/19034752357/job/54356278052
2025-11-04 15:53:23 +00:00
Lennart Poettering
9a1d72fe99 update TODO 2025-11-04 14:12:39 +01:00
Lennart Poettering
4248b02c44 test: add test case 2025-11-04 14:12:39 +01:00
Lennart Poettering
78a738f4cf tar-util: squash high UIDs in user mode 2025-11-04 14:12:39 +01:00
Lennart Poettering
4ded7f7a43 tar-util: add support for acls 2025-11-04 14:12:39 +01:00
Lennart Poettering
e1e170feca tar-util: add support for file flags 2025-11-04 14:12:39 +01:00
Lennart Poettering
a54f4520f3 tar-util: properly deal with sparse files
The extractor already deals with sparse files properly (because
archive_read_data_into_fd() does).

Let's also make sure the archiver also does this, and attaches the
necessary sparse file metadata to each file.
2025-11-04 14:12:39 +01:00
Lennart Poettering
63bf3ca8b0 tar-util: recognize hardlinks when generating tarballs 2025-11-04 14:12:39 +01:00
Lennart Poettering
d4d94fceba tar-util: include xattrs in generated tarballs
We can already unpack them, let's pack them up to.
2025-11-04 14:12:39 +01:00
Lennart Poettering
f89c914968 acl-util: add new acl_set_perm() helper 2025-11-04 14:12:39 +01:00
Lennart Poettering
030f239a19 varlink-idl: add infra to test our enum parsers against varlink IDL enums
In many cases we want to expose enums for which we have the usual
xyz_to_string()/xyz_from_string() via Varlink as enums. Let's add some
infra to test the tables against each other, to automatically detect
when they deviate.

In order to implement this properly, let's export/introduce clean
json_underscorefy()/json_dashify(), for dealing with the fact that our
enums usually use dash separates ames, but Varlink doesn't allow that.

(This does not add the test cases for all enum types we expose right
now, but only adds the general infra).
2025-11-04 11:46:17 +00:00
Quentin Deslandes
79dd24cf14 core: Add UserNamespacePath=
This allows a service to reuse the user namespace created for an
existing service, similarly to NetworkNamespacePath=. The configuration
is the initial user namespace (e.g. ID mapping) is preserved.
2025-11-04 10:55:04 +01:00
Mike Yuan
d98c783516 sysupdated: port to sd_json_parse_file_at() 2025-11-04 10:46:01 +01:00
Mike Yuan
89b9a68e5f sd-json: accept NULL path in sd_json_parse_file_at() too 2025-11-03 22:32:57 +01:00
Mike Yuan
eaebc33220 fileio: mask off O_NOFOLLOW in xfopenat_regular() for fd_reopen()
in a similar fashion as xopenat_full()
2025-11-03 22:32:25 +01:00
Zbigniew Jędrzejewski-Szmek
9218e4eacc mkosi: update fedora commit reference to 8e2833a5b64f7e2ce62ea0a2d0ec9e393e718dfa
* 8e2833a5b6 Automatically figure out the name of the top-level tar dir
* dffbf2beba Make sure fallback source is listed first
* 1d3b892105 Enable sysupdate and sysupdated
2025-11-03 13:31:22 +01:00
jouyouyun
10cdb58690 backlight: fix typo 2025-11-03 11:07:46 +00:00
jouyouyun
49ca2d8778 bootctl: fix typo 2025-11-03 11:30:42 +01:00
Lennart Poettering
f8fcf7de7c kernel-install: move staging area to /var/tmp/
The generated files (UKIs...) can potentially be huge, hence create them
in /var/tmp/, rather than /tmp/.
2025-11-03 09:01:44 +01:00
Lennart Poettering
8f62d20b73 Add support for nvindex-based additional PCRs for TPM2, aka "NvPCRs" (#39463)
This is based on the code from #33276, but is cleaned up, and goes for a
modified approach:

the original PR allocated nvindexes fully dynamically, and that created
big headaches, because the assignments needed to be propagated into the
early boot process, and that meant stuffing them as sidecards to the
boot UKIs.

The TCG then offered us a fixed nvindex range assigned to us, and
happily said yes to that, but since then the discussion stalled, we
couldn't get any answer from TCG on this anymore.

This code uses the range that was hinted to us to use, but not
officially assigned to us by default, but makes it build time
configurable so that downstreams can change this.

(This does *not* make it runtime configurable, because that's really
hard, because of the early boot issue again).

This PR comes with a CI test and full docs. And I think this is really a
version should that be merged.

Fixes: https://github.com/systemd/systemd/issues/29877
2025-11-03 09:00:41 +01:00
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