Commit Graph
32830 Commits
Author SHA1 Message Date
Lennart Poettering d04faa4e19 tree-wide: make use of DISSECT_IMAGE_USR_NO_ROOT in various tools
Let's make use of the new dissection in all tools where this makes
sense, which are all tools that dissect images, except for those which
inherently operate on state/configuraiton and thus where an image
without state nor configuration is useless (e.g.
systemd-tmpfiles/systemd-firstboot/… --image= switch).
2021-03-16 14:57:27 +01:00
Lennart Poettering 7cf660302f dissect-image: support images without rootfs but with /usr/
Let's add support for images that include an /usr/ file system but no
root fs. Mount a tmpfs as root for images like this, all controlled by a
new flag DISSECT_IMAGE_USR_NO_ROOT.

This is useful for entirely stateless images, that come up pristine on
every single boot.
2021-03-16 14:56:48 +01:00
Yu Watanabe efd3be9de1 sd-event: re-check new epoll events when a child event is queued
Previously, when a process outputs something and exit just after
epoll_wait() but before process_child(), then the IO event is ignored
even if the IO event has higher priority. See #18190.

This can be solved by checking epoll event again after process_child().

However, there exists a possibility that another process outputs and
exits just after process_child() but before the second epoll_wait().
When the IO event has lower priority than the child event, still IO
event is processed.

So, this makes new epoll events and child events are checked in a loop
until no new event is detected. To prevent an infinite loop, the number
of maximum trial is set to 10.

Fixes #18190.
2021-03-16 13:35:20 +01:00
Luca Boccassi 65d325edb8 Merge pull request #18984 from poettering/event-test-timeout
sd-event: add test for timeout parameter of sd_event_wait()
2021-03-15 14:31:48 +00:00
Daan De Meyer 95ba433a5f boot: Move console declarations to missing_efi.h
These were added to eficonex.h in gnu-efi 3.0.13. Let's move them
to missing_efi.h behind an appropriate guard to fix the build with
recent versions of gnu-efi.
2021-03-13 13:13:54 +00:00
Yu Watanabe 925bd4c24e fstab-util: fix typo in comment 2021-03-13 12:26:10 +01:00
Kevin Backhouse 37ca78a35c ask-password-api: fix error handling on invalid unicode character
The integer overflow happens when utf8_encoded_valid_unichar() returns an error
code. The error code is a negative number: -22. This overflows when it is
assigned to `z` (type `size_t`). This can cause an infinite loop if the value
of `q` is 22 or larger.

To reproduce the bug, you need to run `systemd-ask-password` and enter an
invalid unicode character, followed by a backspace character.

GHSL-2021-052
2021-03-12 18:25:58 +01:00
Lennart Poettering 7cb45dbfa3 sd-event: fix error handling
Noticed by @keszybz, see #18973
2021-03-12 17:56:56 +01:00
Lennart Poettering c14e57ba6b sd-event: add a simple test for checking the timeout parameter of sd_event_wait()
Related to: #18973
2021-03-12 17:56:33 +01:00
Frantisek Sumsal cb72605436 Revert "sd-event: re-check new epoll events when a child event is queued"
This reverts commit 84e998c112.

Temporarily revert this commit, since it breaks CI.
2021-03-11 18:57:43 +01:00
Yu Watanabe 84e998c112 sd-event: re-check new epoll events when a child event is queued
Previously, when a process outputs something and exit just after
epoll_wait() but before process_child(), then the IO event is ignored
even if the IO event has higher priority. See #18190.

This can be solved by checking epoll event again after process_child().

However, there exists a possibility that another process outputs and
exits just after process_child() but before the second epoll_wait().
When the IO event has lower priority than the child event, still IO
event is processed.

So, this makes new epoll events and child events are checked in a loop
until no new event is detected. To prevent an infinite loop, the number
of maximum trial is set to 10.

Fixes #18190.
2021-03-11 23:09:04 +09:00
Yu Watanabe 7fe11e84c2 test: add log messages 2021-03-11 23:09:04 +09:00
Zbigniew Jędrzejewski-Szmek 47d1cae6cf Merge pull request #18915 from keszybz/reexec-bug
Fix crash during daemon-reexec with systemd-oomd running
2021-03-11 14:46:16 +01:00
Zbigniew Jędrzejewski-Szmek eb406c4e19 Merge pull request #18955 from keszybz/fstab-escaping
Fix handling of escaped characters in fstab
2021-03-11 14:45:11 +01:00
Zbigniew Jędrzejewski-Szmek e4645ca599 basic/group-util: optimize alloca use
Follow-up for 0fa7b50053.
2021-03-11 14:43:16 +01:00
Frantisek Sumsal 3a1bc3fcc0 repart: fix the loop dev support check
Since f17bdf8264 the test-repart was
effectively disabled, since `/dev/loop-control` is a character special
file, whereas `-f` works only on regular files. Even though we could use
`-c` to check specifically for character special files, let's use `-e`
just in case.
2021-03-11 14:42:33 +01:00
Zbigniew Jędrzejewski-Szmek ceffd6a961 Merge pull request #18962 from poettering/dissect-fixes
three image dissection fixes
2021-03-11 14:42:17 +01:00
Michal Sekletar 43b4e3058c install: refactor find_symlinks() and don't search for symlinks recursively
After all we are only interested in symlinks either in top-level config
directory or in .wants and .requires sub-directories.

As a bonus this should speed up ListUnitFiles() roughly 3-4x on systems
with a lot of units that use drop-ins (e.g. SSH jump hosts with a lot of
user session scopes).
2021-03-11 13:12:37 +01:00
Lennart Poettering 38db55ab0c dissect: fix trivial typo 2021-03-11 11:49:19 +01:00
Lennart Poettering 334eb5b099 dissect-image: fix volatile images
This makes sure nspawn's --volatile=yes switch works again: there we
have a read-only image that is overmounted by a tmpfs (with the
exception of /usr). This we need to mkdir all mount points even though
the image is read-only.

Hence, let's drop the optimizatio of avoiding mkdir() on images that are
read-only, it's wrong and misleading here, since the image itself might
be read-only but our mounts are not.
2021-03-11 11:48:31 +01:00
Lennart Poettering 9842905ede dissect-image: clean up meaning of DISSECT_IMAGE_MKDIR
Previously handling of DISSECT_IMAGE_MKDIR was pretty weird and broken:
it would control both if we create the top-level mount point when
mounting an image, and the inner mount points for images that consist of
multiple file systems. However, the latter is redundant, since
1f0f82f131 does this too, a few lines
further up – unconditionally!

Hence, let's make the meaning of DISSECT_IMAGE_MKDIR more strict: it
shall be only about the top-level mount point, not about the inner ones
(where we'll continue to create what is missing alwayway). Having a
separate flag for the top-level mount point is relevant, since the mount
point dir created by it will remain on the host fs – unlike the
directories we create inside the image, which will stay within the
image.

This slightly change of meaning is actually inline with what the flag is
actually used for and documented in systemd-dissect.
2021-03-11 11:48:31 +01:00
Zbigniew Jędrzejewski-Szmek d6cef552dc fstab-generator: get rid of fstab_extract_values()
This was a parallel implementation of option parsing that didn't
support escaping of separators. Let's port this over to the common code.

Fixes #18952.
2021-03-11 11:25:15 +01:00
Zbigniew Jędrzejewski-Szmek ff0c31bc27 shared/fstab-util: teach fstab_filter_options() a mode where all values are returned
Apart from tests, the new argument isn't used anywhere, so there should be no
functional change. Note that the two arms of the big conditional are switched, so the
diff is artificially inflated. The actual code change is rather small. I dropped the
path which extracts ret_value manually, because it wasn't supporting unescaping of the
escape character properly.
2021-03-11 11:25:15 +01:00
Zbigniew Jędrzejewski-Szmek 0264b404b9 shared/fstab-util: pass through the escape character
… when not used to escape the separator (,) or the escape character (\).
This mostly restores behaviour from before 0645b83a40,
but still allows "," to be escaped.

Partially fixes #18952.
2021-03-11 11:25:06 +01:00
Zbigniew Jędrzejewski-Szmek 3141089f53 basic/extract-word: rename flag
The flag enables "relaxed mode" for all kinds of unescaping, not just c-unescaping.
2021-03-11 09:21:07 +01:00
Zbigniew Jędrzejewski-Szmek 76c4e48ee6 basic/extract-word: allow escape character to be escaped
With EXTRACT_UNESCAPE_SEPARATORS, backslash is used to escape the separator.
But it wasn't possible to insert the backslash itself. Let's allow this and
add test.
2021-03-11 09:21:07 +01:00
Zbigniew Jędrzejewski-Szmek 8723c716c7 basic/extract_word: try to explain what the various options do
A test for stripping of escaped backslashes without any flags was explicitly
added back in 4034a06ddb. So it seems to be on
purpose, though I would say that this is at least surprising and hence deserves
a comment.

In test-extract-word, add tests for standalone EXTRACT_UNESCAPE_SEPARATORS.
Only behaviour combined with EXTRACT_CUNESCAPE was tested.
2021-03-11 09:21:04 +01:00
Zbigniew Jędrzejewski-Szmek 5fa2da1251 shared/fstab-util: immediately drop empty options again
In the conversion from strv_split() to strv_split_full() done in
7bb553bb98, EXTRACT_DONT_COALESCE_SEPARATORS was
added. I think this was just by mistake… We never look for "empty options", so
whether we immediately ignore the extra separator or store the empty string in
strv, should make no difference.
2021-03-11 09:19:54 +01:00
Zbigniew Jędrzejewski-Szmek 924f650305 generators: warn but ignore failure to write timeouts
When we failed to split the options (because of disallowed quoting syntax, which
might be a bug in its own), we would silently fail. Instead, let's emit a warning.
Since we ignore the value if we cannot parse it anyway, let's ignore this error
too.
2021-03-11 09:19:00 +01:00
Lennart Poettering 48f813c4aa coredumpctl: fflush() stdout before invoking gdb
Fixes: #18936
2021-03-11 08:55:20 +01:00
Frantisek Sumsal a174da59c2 coredump: omit coredump info when -q is used with the debug verb
Skip printing the coredump info table when using the `debug` verb in
combination with the `-q/--quiet` option. Useful when trying to gather
coredump info non-interactively via scripted gdb commands.

Fixes: systemd/systemd#18935
2021-03-10 17:35:21 +01:00
Zbigniew Jędrzejewski-Szmek 1677b88d01 fstab-generator: do not propagate error if we fail to canonicalize
r is used for the return value of the function, so we shouldn't
use it a non-fatal check.
2021-03-10 16:54:18 +01:00
Zbigniew Jędrzejewski-Szmek 749c4c8ed1 Merge pull request #18553 from Werkov/cgroup-user-instance-controllers
Make (user) instance aware of delegated cgroup controllers
2021-03-10 09:41:40 +01:00
Zbigniew Jędrzejewski-Szmek ffea01856f Merge pull request #18942 from keszybz/sd-netlink-prettification
sd-nelink prettification
2021-03-10 09:18:06 +01:00
Lennart Poettering e5f8ce13bb socket-util: refuse ifnames with embedded '%' as invalid
So Linux has this (insane — in my opinion) "feature" that if you name a
network interface "foo%d" then it will automatically look for the
interface starting with "foo…" with the lowest number that is not used
yet and allocates that.

We should never clash with this "magic" handling of ifnames, hence
refuse this, since otherwise we never know what the name is we end up
with.

We should probably switch things from a deny list to an allow list
sooner or later and be much stricter. Since the kernel directly enforces
only very few rules on the names, we'd need to do some research what is
safe and what is not first, though.
2021-03-10 11:11:52 +09:00
Zbigniew Jędrzejewski-Szmek c7209bcfe1 sd-netlink: shorten things a bit 2021-03-09 17:26:24 +01:00
Zbigniew Jędrzejewski-Szmek 4fa024683c sd-netlink: use setsockopt_int() also for NETLINK_ADD/DROP_MEMBERSHIP
We use 'unsigned' as the type, but netlink(7) says the type is 'int'.
It doesn't really matter, since they are both the same size. Let's use
our helper to shorten the code a bit.
2021-03-09 17:26:24 +01:00
Zbigniew Jędrzejewski-Szmek 64a65bab59 sd-netlink: use structured initialization
The casts look somewhat ugly and type-unsafe, but they are equivalent
to what was there before (we initialized a variable from a void*).
2021-03-09 17:26:24 +01:00
Lennart Poettering 9813d8354c fs-util: port symlink_idempotent() to path_extract_directory() 2021-03-09 14:37:23 +00:00
Zbigniew Jędrzejewski-Szmek 9ca6d78061 logind: add …WithFlags methods to policy
Without this, privilege escalation through polkit does not work, because all
methods fail with permission errors.

Forgotten in 8885fed4e3.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1933335.
2021-03-09 14:37:08 +00:00
Zbigniew Jędrzejewski-Szmek a19c1a4baa oomd: "downgrade" level of message
PID1 already logs about the service being started, so this line isn't necessary
in normal use. Also, by the time it is emitted, the service has already
signalled readiness, so let's not say "starting" but "started".
2021-03-09 14:05:49 +01:00
Zbigniew Jędrzejewski-Szmek 39ad3f1c09 varlink: avoid using dangling ref in varlink_close_unref()
Fixes #18025, https://bugzilla.redhat.com/show_bug.cgi?id=1931034.

We drop the reference stored in Manager.managed_oom_varlink_request in two code paths:
vl_disconnect() which is installed as a disconnect callback, and in manager_varlink_done().
But we also make a disconnect from manager_varlink_done(). So we end up with the following
call stack:

(gdb) bt
 0  vl_disconnect (s=0x112c7b0, link=0xea0070, userdata=0xe9bcc0) at ../src/core/core-varlink.c:414
 1  0x00007f1366e9d5ac in varlink_detach_server (v=0xea0070) at ../src/shared/varlink.c:1210
 2  0x00007f1366e9d664 in varlink_close (v=0xea0070) at ../src/shared/varlink.c:1228
 3  0x00007f1366e9d6b5 in varlink_close_unref (v=0xea0070) at ../src/shared/varlink.c:1240
 4  0x0000000000524629 in manager_varlink_done (m=0xe9bcc0) at ../src/core/core-varlink.c:479
 5  0x000000000048ef7b in manager_free (m=0xe9bcc0) at ../src/core/manager.c:1357
 6  0x000000000042602c in main (argc=5, argv=0x7fff439c43d8) at ../src/core/main.c:2909

When we enter vl_disconnect(), m->managed_oom_varlink_request.n_ref==1.
When we exit from vl_discconect(), m->managed_oom_varlink_request==NULL. But
varlink_close_unref() has a copy of the pointer in *v. When we continue executing
varlink_close_unref(), this pointer is dangling, and the call to varlink_unref()
is done with an invalid pointer.
2021-03-09 14:05:49 +01:00
Zbigniew Jędrzejewski-Szmek 8b0f54c929 pid1: return varlink error on the right connection 2021-03-09 13:49:02 +01:00
Luca Boccassi 1d2e9c48e5 Merge pull request #18930 from anitazha/oomdfixleak
oomd: fix memory leak
2021-03-09 11:37:10 +00:00
Anita Zhang 50c0578b61 oomd: wrap paths in oomd_insert_cgroup_context with empty_to_root 2021-03-09 09:23:22 +01:00
Yu Watanabe 2eaed57bd4 Merge pull request #18932 from poettering/filename-max
Drop use of FILENAME_MAX
2021-03-09 14:15:49 +09:00
Zbigniew Jędrzejewski-Szmek 03a81441b1 timedated: fix skipping of comments in config file
Reading file '/usr/lib/systemd/ntp-units.d/80-systemd-timesync.list'
Failed to add NTP service "# This file is part of systemd.", ignoring: Invalid argument
Failed to add NTP service "# See systemd-timedated.service(8) for more information.", ignoring: Invalid argument

:(
2021-03-09 14:04:21 +09:00
Luca Boccassi a2aa51b740 Merge pull request #18927 from poettering/dissect-alloca-fix
dissect-image: don't mix two forms of stack allocation in one line
2021-03-08 22:42:55 +00:00
Anita Zhang 45da27fa05 oomd: move TAKE_PTR to end of oomd_insert_cgroup_context()
Fixes #18926
2021-03-08 14:37:15 -08:00
Anita Zhang 399d80ba8c oomd: add unit test to repro #18926 2021-03-08 14:36:24 -08:00