Commit Graph

9269 Commits

Author SHA1 Message Date
Lennart Poettering
857ddc2e55 core: serialize API bus id and validate before deserializing bus tracks, plus several other bus util cleanups (#35970)
Follow-up for #35406
2025-01-14 14:39:58 +01:00
Lennart Poettering
5e35b6a5f7 lsm: improve logging about absence of lsm-bpf
In containers securityfs is typically not mounted. Our lsm-bpf code
so far detected this situation and claimed the kernel was lacking
lsm-bpf support. Which isn't quite true though, it might very well
support it. This made boots of systemd in systemd-nspawn a bit ugly,
because of the misleading log message at boot.

Let's improve things, and make clearer what is going on.
2025-01-14 09:53:56 +00:00
Mike Yuan
1446e3c392 core: serialize API bus id and validate before deserializing bus tracks 2025-01-13 21:52:19 +01:00
Mike Yuan
a9a8d2e12f bus-util: introduce bus_get_instance_id() 2025-01-13 21:52:19 +01:00
Mike Yuan
33eeea4128 bus-util: do not reset the count returned by sd_bus_track_count_name()
Follow-up for 8402ca04d1

While at it, turn the retval check for sd_bus_track_count_name()
into assertion, given we're working with already established tracks
(service_name_is_valid() should never yield false in this case).

Addresses https://github.com/systemd/systemd/pull/35406#discussion_r1912066774
2025-01-13 21:52:18 +01:00
Mike Yuan
38a2c2bf6a shared/serialize: introduce serialize_id128() 2025-01-13 21:52:13 +01:00
Mike Yuan
3f03d39ca3 shared/serialize: make input params const 2025-01-13 16:56:08 +01:00
Mike Yuan
91080bc973 shared/bus-util: move string set append/get funcs to bus-message-util and bus-get-properties, respectively 2025-01-13 16:55:42 +01:00
Mike Yuan
e3d37628aa shared/bus-util: move bus_message_hash_ops to bus-message-util 2025-01-13 16:24:44 +01:00
Mike Yuan
ab33edb05b shared/bus-util: move bus_message_read_id128() to bus-message-util 2025-01-13 16:24:44 +01:00
Lennart Poettering
8c0da3af28 tree-wide: port more code to namespace_open_by_type() 2025-01-10 14:09:48 +01:00
Lennart Poettering
fa8b70f2c8 userdb: define new 64K "foreign UID" range (#35932)
This is establish the basic concepts for #35685, in the hope to get this
merged first.

This defines a special, fixed 64K UID range that is supposed to be used
by directory container images on disk, that is mapped to a dynamic UID
range at runtime (via idmapped mounts).

This enables a world where each container can run with a dynamic UID
range, but this in no way leaks onto the disk, thus making supposedly
dynamic, transient UID range assignments persistent.

This is infrastructure later used for the primary part of #35685: unpriv
container execution with directory images inside user's home dirs, that
are assigned to this special "foreign UID range".

This PR only defines the ranges, synthesizes NSS records for them via
userdb, and then exposes them in a new "systemd-dissect --shift" command
that can re-chown a container directory tree into this range (and in
fact any range).

This comes with docs. But no tests. There are tests in #35685 that cover
all this, but they are more comprehensive and also test nspawn's hook-up
with this, hence are excluded from this PR.
2025-01-10 13:49:11 +01:00
Lennart Poettering
d8113a2863 Stash the subscriber list when we disconenct from the bus (#35406)
If we unexpectly disconnect from the bus, systemd would end up dropping
the list of subscribers, which breaks the ability of clients like logind
to monitor the state of units.

Stash the list of subscribers into the deserialized state in the event
of a disconnect so that when we recover we can renew the broken
subscriptions.

---

Fixes: #8672 #26744
2025-01-09 14:34:55 +01:00
Ivan Kruglov
8633bf5836 machine: introduce io.systemd.Machine.OpenRootDirectory 2025-01-09 10:51:18 +01:00
Ronan Pigott
8402ca04d1 dbus: stash the subscriber list when we disconenct from the bus
If we unexpectly disconnect from the bus, systemd would end up dropping
the list of subscribers, which breaks the ability of clients like logind
to monitor the state of units.

Stash the list of subscribers into the deserialized state in the event
of a disconnect so that when we recover we can renew the broken
subscriptions.
2025-01-08 15:50:56 -07:00
Lennart Poettering
44eb6b81db userdb: synthesize stub user records for the foreign UID 2025-01-08 21:41:03 +01:00
Lennart Poettering
ec0c10fc9d user-classification: add new "foreign" UID range
This makes the UID range configurable via build time options, but of
course it really shouldn't be changed. The default range I picked is
outside even of IPAs current (ridiculously large) allocation ranges,
hence hopefully minimizes conflicts.
2025-01-08 21:41:03 +01:00
Lennart Poettering
0ee1171cbb nsresource: optionally mangle userns names passed to nsresourced (#35900)
We enforce quite strict rules on naming userns we assign uid ranges to
for users. So strict that they are hard to get right for clients. hence,
let's optionally mangle provided strings so that they work for us.

This should make it much easier to work with the API, as something
reasonable happens regarldess what kind of garbage a client sets as
name.

mangling the name is opt-in for clients, so that there's tight control
for the client on the name, but also "fire and forget".
2025-01-08 21:36:37 +01:00
nl6720
96963e5615 dissect-image: mount the ESP with fmask=0177 (#35871)
Avoid showing the files on the ESP (i.e. a FAT formatted volume) as
executable by removing the execute permission from them.

IMO this makes the colored output of `ls` more sensible since the file
system will be mounted with `noexec` anyway.

Add a `fstype_can_fmask_dmask` function that checks if a file system
type can use the `fmask` and `dmask` mount options.

This replaces `fstype_can_umask` since it was only used in
`partition_pick_mount_options` which only cares about the file system
support for fmask & dmask now.

It somewhat reduces the coverage of the feature since there are more file
systems that support umask as opposed to those supporting dmask & dmask,
but it should not be much of an issue since fmask & dmask are supported
by vfat, exfat and ntfs3.
2025-01-08 15:19:33 +01:00
Lennart Poettering
ee6fd7ef82 nsresourced: add ability to mangle specified name if necessary
Let's optionally mangle any passed name on the server side so that it is
useful for identifying a userns, if it isn't suitable for that
right-away. This mostly means truncating it if too long.

It's just too nasty to leave this to the client side, since they'd have
to understand the precise rules for naming userns then.

While we are at it, add full Varlink IDL comments.
2025-01-08 15:12:02 +01:00
Lennart Poettering
0dfd89fa32 udev: introduce io.systemd.Udev varlink interface (#35721)
Replaces #25523.
2025-01-07 16:49:37 +01:00
Yu Watanabe
05db3fe7f9 ask-password: req must be non-NULL
After #35074, the parameter 'req' must be non-NULL.

Fixes CID#1586101, CID#1586102, and CID#1586103.
2025-01-07 13:12:08 +01:00
Yu Watanabe
2f0aa9a804 udev-varlink: introduce io.systemd.Udev varlink interface
Co-authored-by: David Tardon <dtardon@redhat.com>
2025-01-07 20:31:15 +09:00
Lennart Poettering
56a07d10a5 xopenat(): introduce new XO_REGULAR flag (#35834)
This is something I think we should have added a long time ago: a
flavour of open() that safely ensures the inode we are opening is a
regular file, before we open it. It does this by means of pinning the
inode via O_PATH first, and after verification actually opening it.

This ports some code over to this, but sooner or later we should
probably use this a lot more, so that we don't accidentally open weird
stuff such as device nodes or pipes, where we should not.
2025-01-07 08:55:56 +01:00
Lennart Poettering
20785351b1 pretty-print: drop extra ';' from progress reporting end sequence
This corrects the closing sequence for the ConEmu progress reporting
final sequence. We by mistake sent two final ;;, where only one was
expected. The terminals I tested this with didn't care, but Ghostty
apparently does. Let's fix things and generate the closing sequence as
per doc:

https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
2025-01-07 08:55:36 +01:00
Lennart Poettering
714b21da88 copy: port things over to XO_REGULAR 2025-01-06 23:37:45 +01:00
Ivan Kruglov
453f2359ff machine: introduce io.system.Machine.{CopyFrom, CopyTo} methods 2025-01-06 14:51:57 +01:00
Daan De Meyer
eaf0f79293 machine: several follow-ups for #35066 (#35868)
Addresses the post-merge review comments.
2025-01-06 11:59:55 +01:00
Lennart Poettering
336acebc77 basic: port various pidfd/pidref helpers to PIDFD_GET_INFO and PIDFD_GET_*_NAMESPACE (#35242)
Supersedes #35308 (cherry-picked one commit and replaced the rest)

(I left a few comments that's folded by GitHub. Please make sure to
check them too.)
2025-01-06 11:23:08 +01:00
Yu Watanabe
c192d87d83 machine: comment source and destination must be absolute
Addresses the post-merge review comment:
https://github.com/systemd/systemd/pull/35066#discussion_r1901841247
2025-01-06 17:14:26 +09:00
Yu Watanabe
be68dcdc20 firewall-util: allow to override the table and map names through env var
Then, use test specific names to make the test not conflict with
networkd.

Hopefully fixes #35526.
2025-01-05 01:48:29 +09:00
Mike Yuan
07610cafcf namespace-util: modernize fd_is_namespace() and is_our_namespace()
- Make fd_is_namespace() take NamespaceType
- Drop support for kernel without NS_GET_NSTYPE (< 4.11)
- Port is_our_namespace() to namespace_open_by_type()
  (preparation for later commits, where the latter
  would go by pidfd if available, avoiding procfs)
2025-01-04 17:07:59 +01:00
Mike Yuan
9a7b20b6a6 errno-util: add ERRNO_IS_IOCTL_NOT_SUPPORTED that checks EINVAL additionally 2025-01-04 17:07:58 +01:00
Yu Watanabe
8252b74f2d varlink: add comments for io.systemd.service interface 2025-01-04 23:17:47 +09:00
Yu Watanabe
4ea611b8a4 varlink: invert uid check to reduce call of getuid() 2025-01-04 20:57:06 +09:00
Yu Watanabe
93081be64b sd-json: introduce json_dispatch_log_level()
Then, use it in io.systemd.service.SetLogLevel method.
2025-01-04 20:57:06 +09:00
Yu Watanabe
aac9d150ed tpm2: tweaks to PCR mask parsing (#35835) 2025-01-04 12:42:54 +09:00
Lennart Poettering
b1fb2d971c nspawn: move uid shift/chown() code into shared/ 2025-01-04 12:23:31 +09:00
Lennart Poettering
9f97f2899a dissect-image: rename ReplyParameters → MountImageReplyParameters 2025-01-03 16:44:08 +01:00
Daan De Meyer
b0e9ac018d machine: introduce io.systemd.Machine.BindMount method (#35066)
This PR introduces io.systemd.Machine.BindMount method which is
alternative to DBus's BindMountMachine.
2025-01-03 13:19:48 +01:00
Lennart Poettering
3085782020 tpm2-util: refuse hash algorithm/value specification when we only parse a mask
tpm2_parse_pcr_argument_to_mask() is supposed to parse a PCR mask
string, and uses the full blown tpm2_parse_pcr_argument() call at its
core, which parses more than just a mask, i.e. values and algorithms
too. Which is very confusing at times, because commands such as
"systemd-cryptenroll --tpm2-device=auto
--tpm2-public-key-pcrs=1:sha1=09dbdbc7f6cdd8029cc90b57a915c19a0ac21bce"
are very confusing, since they suggest enrollment with a specific
algorithm and has value, but this is not in fact what happens: both are
entirely ignored.

That this was accepted this way was more an accident than intended,
which is already visible in the fact that extensive test case entirely
ignores the fact that strings like this are accepted.
2025-01-03 10:44:26 +01:00
Lennart Poettering
982e791f1c tpm2-util: optionally do wildcard hash check in tpm2_pcr_values_to_mask()
If TPM2_ALG_ERROR (aka "0") is specified as algorithm in
tpm2_pcr_values_to_mask() we'll simply match all algorithms. This allows
us to shorten tpm2_parse_pcr_argument_to_mask() a bit. The function
accepts but ignores a hash algorithm specification currently, hence this
should not really much effect.
2025-01-03 10:39:10 +01:00
Lennart Poettering
0db32a3bfb tpm2-util: drop ret_x prefix from two arguments that are not just return but also input params 2025-01-03 10:39:10 +01:00
Mike Yuan
dfe3fe77f7 shared/hibernate-util: handle the case where no swap has available backing dev (#35802)
Fixes https://github.com/systemd/systemd/issues/35798
Replaces https://github.com/systemd/systemd/pull/35801
2025-01-02 19:26:58 +01:00
Ivan Kruglov
d12b63f168 machine: introduce io.systemd.Machine.BindMount method 2025-01-02 16:58:16 +01:00
Lennart Poettering
7fd0ea6cf6 ask-password: add comment with well-known errors from ask_password_auto() 2025-01-02 16:39:30 +01:00
Lennart Poettering
066f6bfb62 ask-password: add Varlink API for querying passwords from the user
This turns systemd-ask-password into a small Varlink service, so that
there's an standard IPC way to ask for a password. It mostly directly
exposes the functionality of the Varlink service.
2025-01-02 16:39:05 +01:00
Lennart Poettering
d66894a7a5 ask-password-api: add new "hup_fd" field to AskPasswordReq
This new field allows specification of an fd on which the password
prompt logic will look for POLLHUP events for, and if seen will abort
the query.

The usecase for this is that when we query for a pw on behalf of a
Varlink client we can abort the query automatically if the client dies.
2025-01-02 16:38:44 +01:00
Lennart Poettering
c4a02a526d ask-password-api: move timeout into AskPasswordRequest structure too 2025-01-02 16:38:25 +01:00
Lennart Poettering
72068d9d25 ask-password-api: move tty_fd into AskPasswordRequest structure, too 2025-01-02 16:38:12 +01:00