Commit Graph

46504 Commits

Author SHA1 Message Date
Lennart Poettering a52dc0b6f3 update TODO 2020-09-02 15:04:06 +02:00
Lennart Poettering 0d12936d9a shared: make libcryptsetup dep dlopen
Let's make libcryptsetup a dlopen() style dep for PID 1 (i.e. for
RootImage= and stuff), systemd-growfs and systemd-repart. (But leave to
be a regulra dep in systemd-cryptsetup, systemd-veritysetup and
systemd-homed since for them the libcryptsetup support is not auxiliary
but pretty much at the core of what they do.)

This should be useful for container images that want systemd in the
payload but don't care for the cryptsetup logic since dm-crypt and stuff
isn't available in containers anyway.

Fixes: #8249
2020-09-02 15:04:06 +02:00
Lennart Poettering 1e2f32305c shared: rename crypt-util.c → cryptsetup-util.c
"crypt-util.c" is such a generic name, let's avoid that, in particular
as libc's/libcrypt's crypt() function is so generically named too that
one might thing this is about that. Let's hence be more precise, and
make clear that this is about cryptsetup, and nothing else.

We already had cryptsetup-util.[ch] in src/cryptsetup/ doing keyfile
management. To avoid the needless confusion, let's rename that file to
cryptsetup-keyfile.[ch].
2020-09-02 15:00:32 +02:00
Christian Göttsche 346543d6f9 selinux/systemctl: create unit file with default context on edit 2020-09-02 09:07:59 +02:00
Lennart Poettering e4ec78206c import: make sure gnu tar complains on tar files with trailing garbage
By default GNU tar will only read the first archive if multiple archives
are concatenated and ignore the rest. If an archive contains trailing
garbage this will hence not be recognized by tar as error, it simply
stops reading when the first archive is done (which might escalate to
SIGPIPE when invoked via a pipe).

Let's add --ignore-zeros to the tar command line when extracting. This
means:

1) if a tar archive was concatenated (i.e. generated with tar -A) we'll
   process it correctly.

2) if a tar archive contains trailing garbage tar will now generate an
   error message about it, instead of just throwing EPIPE, which makes
   things easier to debug as broken files are not silently processed.

I think it's OK for gnu tar to ignore trailing garbage when dealing with
classic tapes drives, i.e. mediums that do not have a size limit
built-in. However, this is not what we are dealing with: we are dealing
with OS images here, that hopefully someone generated with a clean build
system, that were signed and validated and hence should not contain
trailing garbage.  Hence it's better to refuse and complain thant to
silently eat up like for classic tape drives.

Fixes: #16605
2020-09-02 08:59:33 +02:00
Lennart Poettering 58cf204730 nspawn: let's make LinkJournal an extended boolean
Let's accept the usual boolean parameters for LinkJournal. It's
confusing otherwise.

Previously we'd accept "no" but not the other values we typically accept
for "false". We'd not accept any values for "true".

With this change we'll accept all true and false values and will do
something somewhat reasonable: any false value is treated like "no"
previously was reated. And any true value is now treated like "auto".

We don't document the new values, since this logic is mostly redundant,
and it's probably better if people consider this an enum rather than a
bool.

Fixes: #16888
2020-09-02 08:57:44 +02:00
Zbigniew Jędrzejewski-Szmek 47be8ddcee
Merge pull request #16882 from weblate/weblate-systemd-master
Translations update from Weblate
2020-09-02 08:55:40 +02:00
Zbigniew Jędrzejewski-Szmek 6ee37b1a7d
Merge pull request #16853 from poettering/udev-current-tag2
udev: make uevents "sticky"
2020-09-02 08:12:56 +02:00
Lennart Poettering 64a5384fd2 coredump: don't convert s → µs twice
We already append 000000 early on when parsing the cmdline args, let's
not do that a second time.

Fixes: #16919
2020-09-02 08:11:07 +02:00
afg ae0d36c161 firstboot: fill empty color if ansi_color unavailable from os-release 2020-09-02 08:10:47 +02:00
Zbigniew Jędrzejewski-Szmek 47b04ef632
Merge pull request #16925 from cgzones/selinux_create_label
selinux/core: create several file objects with default SELinux context
2020-09-01 22:19:52 +02:00
Lennart Poettering 004cfad218
Merge pull request #16911 from keszybz/userdb-json-invalid-utf8
Deal properly with invalid utf-8 in userdb entries
2020-09-01 20:34:22 +02:00
Zbigniew Jędrzejewski-Szmek 2c0e46735b
Merge pull request #16922 from keszybz/ordered-set-ensure-allocated
Ordered set ensure allocated
2020-09-01 19:44:28 +02:00
Lennart Poettering 278fdd064d man: document the new libudev APIs 2020-09-01 17:40:13 +02:00
Lennart Poettering bf6e5c574b NEWS: explain the "bind"/"unbind" situation a bit 2020-09-01 17:40:13 +02:00
Lennart Poettering 643bb92408 logind: always check current tag list before using a device 2020-09-01 17:40:13 +02:00
Lennart Poettering fccb48b286 logind: only apply ACLs for device currently tagged with "uaccess"
This is about security, hence let's be particularly careful here: only
devices currenlty tagged with "uaccess" will get ACL management, and
it's not sufficient if they once were (though that is used for
filtering).
2020-09-01 17:40:12 +02:00
Lennart Poettering 242c1c075a core: make sure to recheck current udev tag "systemd" before considering a device ready
Let's ensure that a device once tagged can become active/inactive simply
by toggling the current tag.

Note that this means that a device once tagged with "systemd" will
always have a matching .device unit. However, the active/inactive state
of the unit reflects whether it is currently tagged that way (and
doesn't have SYSTEMD_READY=0 set).

Fixes: #7587
2020-09-01 17:40:12 +02:00
Lennart Poettering 31abedbb03 test: add test for new "sticky" tags logic 2020-09-01 17:40:12 +02:00
Lennart Poettering 3b684be04b libudev: also expose API to check for current tags in libudev 2020-09-01 17:40:12 +02:00
Lennart Poettering e77b146f82 udev: make tags "sticky"
This tries to address the "bind"/"unbind" uevent kernel API breakage, by
changing the semantics of device tags.

Previously, tags would be applied on uevents (and the database entries
they result in) only depending on the immediate context. This means that
if one uevent causes the tag to be set and the next to be unset, this
would immediately effect what apps would see and the database entries
would contain each time. This is problematic however, as tags are a
filtering concept, and if tags vanish then clients won't hence notice
when a device stops being relevant to them since not only the tags
disappear but immediately also the uevents for it are filtered including
the one necessary for the app to notice that the device lost its tag and
hence relevance.

With this change tags become "sticky". If a tag is applied is once
applied to a device it will stay in place forever, until the device is
removed. Tags can never be removed again. This means that an app
watching a specific set of devices by filtering for a tag is guaranteed
to not only see the events where the tag is set but also all follow-up
events where the tags might be removed again.

This change of behaviour is unfortunate, but is required due to the
kernel introducing new "bind" and "unbind" uevents that generally have
the effect that tags and properties disappear and apps hence don't
notice when a device looses relevance to it. "bind"/"unbind" events were
introduced in kernel 4.12, and are now used in more and more subsystems.
The introduction broke userspace widely, and this commit is an attempt
to provide a way for apps to deal with it.

While tags are now "sticky" a new automatic device property
CURRENT_TAGS is introduced (matching the existing TAGS property) that
always reflects the precise set of tags applied on the most recent
events. Thus, when subscribing to devices through tags, all devices that
ever had the tag put on them will be be seen, and by CURRENT_TAGS it may
be checked whether the device right at the moment matches the tag
requirements.

See: #7587 #7018 #8221
2020-09-01 17:40:12 +02:00
Lennart Poettering 73484ecff9 test-functions: make sure we test our own libudev instead of the host libudev
When invoking "ldd" to find dependency libraries we already set
$LD_LIBRARY_PATH to point to our own build tree, so that our libraries
are checked, not the host libraries. This is not sufficient howeever, as
libudev is built in a subdir. Add that, too.
2020-09-01 17:40:12 +02:00
Lennart Poettering 895abf3fdd
Merge pull request #16727 from wusto/core-fix-securebits
core: fix securebits setting
2020-09-01 17:21:48 +02:00
Renaud Métrich 3e5f04bf64 socket: New option 'FlushPending' (boolean) to flush socket before entering listening state
Disabled by default. When Enabled, before listening on the socket, flush the content.
Applies when Accept=no only.
2020-09-01 17:20:23 +02:00
Zbigniew Jędrzejewski-Szmek ceaf24d4d3 TODO: add entry 2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek 5c0b738012 user-record-nss: check if strings from pwd/spwd/grp/sgrp are valid utf-8
strv_extend_strv_utf8_only() uses a temporary buffer to make the implementation
conscise. Otherwise we'd have to rewrite all of strv_extend_strv() which didn't
seem worth the trouble for this one use outside of a hot path.

If the data is not serializable, we just pretend it doesn't exists.
This fixes #16683 and https://bugs.gentoo.org/735072 in a second way.
2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek e60775cb7b shared: merge {user,group}-record-nss.{c,h}
They both are both short and contain similar parts and various helper will be
shared between both parts of the code so it's easier to use a single file.
2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek 4d7f51756a test-json: add function headers 2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek ea9afe0064 shared/json: reject non-utf-8 strings
JSON strings must be utf-8-clean. We also verify this in json_parse_string()
so we would reject a message with invalid utf-8 anyway.

It would probably be slightly cheaper to detect non-conformaning strings in
serialization, but then we'd have to fail serialization. By doing this early,
we give the caller a chance to handle the error nicely.

The test is adjusted to contain a valid utf-8 string after decoding of the
utf-32 encoding in json ("विवेकख्यातिरविप्लवा हानोपायः।", something about the
cessation of ignorance).
2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek 80ab31a435 shared/utf8: add utf8_is_valid_n()
Sometimes we need to check strings without the terminating NUL. Add a variant
that does that.
2020-09-01 16:48:40 +02:00
Zbigniew Jędrzejewski-Szmek f77d6ec953
Merge pull request #16877 from poettering/tmpfiles-statx
tmpfiles: use statx()
2020-09-01 16:32:50 +02:00
Christian Göttsche 63e00ccd8e selinux: create /run/systemd/userdb directory and sockets with default SELinux context 2020-09-01 16:26:12 +02:00
Christian Göttsche 45ae2f725e selinux: create systemd/notify socket with default SELinux context 2020-09-01 16:25:06 +02:00
Lennart Poettering df2f58176d doc: cross link sd_listen_fd() docs a bit
Let's make sure the sd_listen_fd() docs are really found from the
.socket file documentation as well as the FileDescriptorStoreMax=
documentation.

Let's also emphasize that that's where the order in which the fds are
passed are documented.

Fixes: #16647
2020-09-01 16:20:34 +02:00
Christian Göttsche a3f5fd964b selinux: create unit invocation links with default SELinux context 2020-09-01 15:48:53 +02:00
Zbigniew Jędrzejewski-Szmek 8a35af80fc basic/hashmap,set: move pointer symbol adjactent to the returned value
I think this is nicer in general, and here in particular we have a lot
of code like:
 static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
         return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));
 }
and it's visually appealing to use the same whitespace in the function
signature and the cast in the body of the function.
2020-09-01 13:45:51 +02:00
Zbigniew Jędrzejewski-Szmek e4126adf45 basic/hashmap,set: inline trivial set_iterate() wrapper
The compiler would do this to, esp. with LTO, but we can short-circuit the
whole process and make everything a bit simpler by avoiding the separate
definition.

(It would be nice to do the same for _set_new(), _set_ensure_allocated()
and other similar functions which are one-line trivial wrappers too. Unfortunately
that would require enum HashmapType to be made public, which we don't want
to do.)
2020-09-01 13:32:02 +02:00
Zbigniew Jędrzejewski-Szmek 1f25c71d9d basic: pass allocation info for ordered_set_new() and introduce ordered_set_ensure_put() 2020-09-01 12:42:35 +02:00
Susant Sahani b7847e05f5 basic: Introduce ordered_hashmap_ensure_put 2020-09-01 12:32:48 +02:00
Tobias Kaufmann dbdc4098f6 core: fix securebits setting
Desired functionality:
Set securebits for services started as non-root user.

Failure:
The starting of the service fails if no ambient capability shall be
raised.
... systemd[217941]: ...: Failed to set process secure bits: Operation
not permitted
... systemd[217941]: ...: Failed at step SECUREBITS spawning
/usr/bin/abc.service: Operation not permitted
... systemd[1]: abc.service: Failed with result 'exit-code'.

Reason:
For setting securebits the capability CAP_SETPCAP is required. However
the securebits (if no ambient capability shall be raised) are set after
setresuid.
When setresuid is invoked all capabilities are dropped from the
permitted, effective and ambient capability set. If the securebit
SECBIT_KEEP_CAPS is set the permitted capability set is retained, but
the effective and the ambient set are cleared.

If ambient capabilities shall be set, the securebit SECBIT_KEEP_CAPS is
added to the securebits configured in the service file and set together
with the securebits from the service file before setresuid is executed
(in enforce_user).
Before setresuid is executed the capabilities are the same as for pid1.
This means that all capabilities in the effective, permitted and
bounding set are set. Thus the capability CAP_SETPCAP is in the
effective set and the prctl(PR_SET_SECUREBITS, ...) succeeds.
However, if the secure bits aren't set before setresuid is invoked they
shall be set shortly after the uid change in enforce_user.
This fails as SECBIT_KEEP_CAPS wasn't set before setresuid and in
consequence the effective and permitted set was cleared, hence
CAP_SETPCAP is not set in the effective set (and cannot be raised any
longer) and prctl(PR_SET_SECUREBITS, ...) failes with EPERM.

Proposed solution:
The proposed solution consists of three parts
1. Check in enforce_user, if securebits are configured in the service
   file. If securebits are configured, set SECBIT_KEEP_CAPS
   before invoking setresuid.
2. Don't set any other securebits than SECBIT_KEEP_CAPS in enforce_user,
   but set all requested ones after enforce_user.
   This has the advantage that securebits are set at the same place for
   root and non-root services.
3. Raise CAP_SETPCAP to the effective set (if not already set) before
   setting the securebits to avoid EPERM during the prctl syscall.

For gaining CAP_SETPCAP the function capability_bounding_set_drop is
splitted into two functions:
- The first one raises CAP_SETPCAP (required for dropping bounding
  capabilities)
- The second drops the bounding capabilities

Why are ambient capabilities not affected by this change?
Ambient capabilities get cleared during setresuid, no matter if
SECBIT_KEEP_CAPS is set or not.
For raising ambient capabilities for a user different to root, the
requested capability has to be raised in the inheritable set first. Then
the SECBIT_KEEP_CAPS securebit needs to be set before setresuid is
invoked. Afterwards the ambient capability can be raised, because it is
in the inheritable and permitted set.

Security considerations:
Although the manpage is ambiguous SECBIT_KEEP_CAPS is cleared during
execve no matter if SECBIT_KEEP_CAPS_LOCKED is set or not. If both are
set only SECBIT_KEEP_CAPS_LOCKED is set after execve.
Setting SECBIT_KEEP_CAPS in enforce_user for being able to set
securebits is no security risk, as the effective and permitted set are
set to the value of the ambient set during execve (if the executed file
has no file capabilities. For details check man 7 capabilities).

Remark:
In capability-util.c is a comment complaining about the missing
capability CAP_SETPCAP in the effective set, after the kernel executed
/sbin/init. Thus it is checked there if this capability has to be raised
in the effective set before dropping capabilities from the bounding set.
If this were true all the time, ambient capabilities couldn't be set
without dropping at least one capability from the bounding set, as the
capability CAP_SETPCAP would miss and setting SECBIT_KEEP_CAPS would
fail with EPERM.
2020-09-01 10:53:26 +02:00
Tobias Kaufmann 57d4d284c9 capability-util: add new function for raising setpcap
Up to now the capability CAP_SETPCAP was raised implicitly in the
function capability_bounding_set_drop.

This functionality is moved into a new function
(capability_gain_cap_setpcap).

The new function optionally provides the capability set as it was
before raisining CAP_SETPCAP.
2020-09-01 10:53:26 +02:00
Zbigniew Jędrzejewski-Szmek e12b6e1951 json: split out string formatting to a separate function
It's complicated enough to deserve it's own function.

No functional change.
2020-09-01 10:48:10 +02:00
Zbigniew Jędrzejewski-Szmek 77472d06a4 varlink: do not parse invalid messages twice
Upon reception of a message which fails in json_parse(), we would proceed to
parse it again from a deferred callback and hang. Once we have realized that
the message is invalid, let's move the pointer in the buffer even if the
message is invalid. We don't want to look at this data again.

(before) $ build-rawhide/userdbctl --output=json user test.user
n/a: varlink: setting state idle-client
/run/systemd/userdb/io.systemd.Multiplexer: Sending message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test.user","service":"io.systemd.Multiplexer"}}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state idle-client → awaiting-reply
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state awaiting-reply → pending-disconnect
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state pending-disconnect → disconnected
^C

(after) $ n/a: varlink: setting state idle-client
/run/systemd/userdb/io.systemd.Multiplexer: Sending message: {"method":"io.systemd.UserDatabase.GetUserRecord","parameters":{"userName":"test.user","service":"io.systemd.Multiplexer"}}
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state idle-client → awaiting-reply
/run/systemd/userdb/io.systemd.Multiplexer: New incoming message: {...}
/run/systemd/userdb/io.systemd.Multiplexer: Failed to parse JSON: Invalid argument
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state awaiting-reply → pending-disconnect
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state pending-disconnect → processing-disconnect
Got lookup error: io.systemd.Disconnected
/run/systemd/userdb/io.systemd.Multiplexer: varlink: changing state processing-disconnect → disconnected
Failed to find user test.user: Input/output error

This should fix #16683 and https://bugs.gentoo.org/735072.
2020-09-01 10:48:10 +02:00
Zbigniew Jędrzejewski-Szmek f7dc8248d3 man: add hint how to show password strings with userdbctl
I started working on a command-line switch to show passwords also in
"pretty" mode. I can submit that code for review if anyone thinks that
woul be useful, but after writing the man page I realized that it's a
fairly niche case, and the hint in the man page is a sufficient
replacement.
2020-09-01 10:48:10 +02:00
Zbigniew Jędrzejewski-Szmek 4fcc9c4962 userdb: fix typo 2020-09-01 10:48:10 +02:00
Zbigniew Jędrzejewski-Szmek c4651e3156 userdbctl: add forgotten --output mode in help 2020-09-01 10:48:10 +02:00
Zbigniew Jędrzejewski-Szmek 52d3fbc83f shared: merge {user,group}-record-show.[ch]
It is natural to include both, and in total they declared three
functions. Let's merge them for simplicity.
2020-09-01 10:48:03 +02:00
Anita Zhang 0419dae715
Merge pull request #16885 from keszybz/rework-cache-timestamps
Rework cache timestamps
2020-08-31 23:21:12 -07:00
Anita Zhang 026a72c175
Merge pull request #16917 from poettering/contrib-rfe
CONTRIBUTING: be clearer about versions and RFE process
2020-08-31 17:25:36 -07:00
Lennart Poettering c4bc2e9343 CONTRIBUTING: be clearer about versions and RFE process
Fixes: #16550
2020-08-31 23:23:56 +02:00