Commit graph

4016 commits

Author SHA1 Message Date
Frantisek Sumsal 0e97a910a6 pkcs11-util: don't mask return value of the first asprintf()
Fixes CID#1409666
2020-01-07 10:30:52 +09:00
Kai Krakow bc5ea049f2 nspawn: Generate unique short veth names
This commit lowers the chance of having veth name conflicts for machines
created with similar names.

Replaces: #12865
Fixes: #13417
2020-01-02 20:05:42 +01:00
Lennart Poettering b355d0c9af udev: move naming-scheme.[ch] into src/shared/
That way we can use it from non-udev code too, for example nspawn.
2020-01-02 19:34:00 +01:00
Greg "GothAck" Miell e6627f2392 unit drop-in: Fix ordering of special type.d drop-ins 2019-12-27 15:10:24 +00:00
Anita Zhang e5f10cafe0 core: create inaccessible nodes for users when making runtime dirs
To support ProtectHome=y in a user namespace (which mounts the inaccessible
nodes), the nodes need to be accessible by the user. Create these paths and
devices in the user runtime directory so they can be used later if needed.
2019-12-18 11:09:30 -08:00
Zbigniew Jędrzejewski-Szmek b012a1f455 Make openssl dependency optional again 2019-12-18 11:24:44 +01:00
Zbigniew Jędrzejewski-Szmek 1b49e3e3c4 shared/loop-util: rename function
As suggested in https://github.com/systemd/systemd/pull/14261#pullrequestreview-332398625.
2019-12-18 08:48:33 +01:00
Topi Miettinen 7a670b1dd9 shared/dropin: fix assert for invalid drop-in
Don't try to show top level drop-in for non-existent units or when trying to
instantiate non-instantiated units:

$ systemctl cat nonexistent@.service
Assertion 'name' failed at src/shared/dropin.c:143, function unit_file_find_dirs(). Aborting.
$ systemctl cat systemd-journald@.service
Assertion 'name' failed at src/shared/dropin.c:143, function unit_file_find_dirs(). Aborting.
2019-12-18 08:43:40 +01:00
Lennart Poettering 9652d74092 varlink: add varlink_close_unref() helper 2019-12-17 20:05:46 +01:00
Lennart Poettering e10720818e chown-recursive: add fd based API 2019-12-17 20:03:40 +01:00
Lennart Poettering 417a6eece8 chown-recursive: move src/core/chown-recursive.[ch] → src/shared/
We want to use it outside of the core, hence let's moved it to the
shared code directory.
2019-12-17 20:03:40 +01:00
Lennart Poettering 13b6c4c8de
Merge pull request #14267 from poettering/pkcs11-cryptsetup
just the pkcs11 hookup for classic cryptsetup (/etc/crypttab) split out of the homed PR
2019-12-17 15:30:32 +01:00
Yu Watanabe 3267cb45e9
Merge pull request #14208 from poettering/json-homed-prepare
json bits from homed PR
2019-12-17 23:10:08 +09:00
Lennart Poettering c16782577b
Merge pull request #14241 from keszybz/resume-timeout
Bump resume timeout to infinity
2019-12-17 10:34:43 +01:00
Yu Watanabe e16f18bddf
Merge pull request #14339 from keszybz/invalid-enablement-logs
Small enhancements to logs for enabling of invalid units
2019-12-17 15:04:14 +09:00
Zbigniew Jędrzejewski-Szmek e51712963b shared/install: log syntax error for invalid DefaultInstance=
Ideally, we would want to report this over back over dbus. But that is pretty hard,
because the unitfile parsing logic doesn't provide any feedback.
systemd-analyze verify also doesn't notice the issue, because it doesn't look
at the [Install] section at all. Let's print a message in the logs at least.
2019-12-16 14:19:49 +01:00
Lennart Poettering c84d9b3b71
Merge pull request #14261 from keszybz/loop-utils-and-efivars
Fixes for networkd, shared/loop-util, basic/efivars
2019-12-16 09:27:46 +01:00
Yu Watanabe a5053a158b udev: support AlternativeName= setting in .link file 2019-12-16 10:52:22 +09:00
Zbigniew Jędrzejewski-Szmek 0181314861 shared/loop-util: spin on open() returning ENOENT too
https://github.com/systemd/systemd/pull/14261#discussion_r355001559
2019-12-15 21:06:42 +01:00
Zbigniew Jędrzejewski-Szmek a97abb30e7 shared/efi-loader: add some debugging statements
Should make it easier to figure out why some operations fail...
2019-12-15 21:06:42 +01:00
Zbigniew Jędrzejewski-Szmek f2d9213fee shared/loop-util: spin on LOOP_CTL_REMOVE
If we call LOOP_CLR_FD and LOOP_CTL_REMOVE too rapidly, the kernel cannot deal
with that (5.3.13-300.fc31.x86_64 running on dual core
Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz).

$ sudo strace -eioctl build/test-dissect-image /tmp/foobar3.img
ioctl(3, TCGETS, 0x7ffcee47de20)        = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(4, LOOP_CTL_GET_FREE)             = 9
ioctl(5, LOOP_SET_FD, 3)                = 0
ioctl(5, LOOP_SET_STATUS64, {lo_offset=0, lo_number=0, lo_flags=LO_FLAGS_READ_ONLY|LO_FLAGS_AUTOCLEAR|LO_FLAGS_PARTSCAN, lo_file_name="", ...}) = 0
ioctl(5, BLKGETSIZE64, [299999744])     = 0
ioctl(5, CDROM_GET_CAPABILITY, 0)       = -1 EINVAL (Invalid argument)
ioctl(5, BLKSSZGET, [512])              = 0
Waiting for device (parent + 0 partitions) to appear...
Found root partition, writable of type btrfs at #-1 (/dev/block/7:9)
ioctl(5, LOOP_CLR_FD)                   = 0
ioctl(3, LOOP_CTL_REMOVE, 9)            = -1 EBUSY (Device or resource busy)
Failed to remove loop device: Device or resource busy

This seems to be clear race condition, and attaching strace is generally enough
to "win" the race. But even with strace attached, we will fail occasionally.
Let's wait a bit and retry. With the wait, on my machine, the second attempt
always succeeds:

...
Found root partition, writable of type btrfs at #-1 (/dev/block/7:9)
ioctl(5, LOOP_CLR_FD)                   = 0
ioctl(3, LOOP_CTL_REMOVE, 9)            = -1 EBUSY (Device or resource busy)
ioctl(3, LOOP_CTL_REMOVE, 9)            = 9
+++ exited with 0 +++

Without the wait, all 64 attempts will occasionally fail.
2019-12-15 21:06:42 +01:00
Zbigniew Jędrzejewski-Szmek e8af3bfd63 shared/loop-util: fix error handling in loop_device_make_full()
The function no longer returns the fd. This complicated semantics, because it
wasn't clear what holds the ownership: the return value or the output
parameter.  There were no users of the fd in the return value, so let's
simplify things conceptually and only return the fd once.

Reduce the scope of variables.

LOOP_CLR_FD was called on the wrong fd. Let's use a cleanup function to make
this automatic and reduce chances of a mixup in the future.

CID 1408498.
2019-12-15 21:06:42 +01:00
Zbigniew Jędrzejewski-Szmek d7ceaf7261 shared/install: provide a nicer error message for invalid WantedBy=/Required= values
$ build/systemctl --user cat badinstall
 # /home/zbyszek/.config/systemd/user/badinstall.service
[Service]
ExecStart=true

[Install]
WantedBy=asdf

$ build/systemctl --user enable badinstall
Failed to enable unit: "asdf" is not a valid unit name.

Fixes #4209.
2019-12-13 19:30:36 +01:00
Zbigniew Jędrzejewski-Szmek d9c1c43e67 shared/install: remove duplicated check
install_info_add() does the exact same check.
2019-12-13 19:30:36 +01:00
Lennart Poettering 5905d7cf5b tree-wide: use SD_ID128_STRING_MAX where appropriate 2019-12-10 11:56:18 +01:00
Lennart Poettering b5ea030d65 id128: introduce ID128_UUID_STRING_MAX for sizing UUID buffers 2019-12-10 11:56:18 +01:00
Lennart Poettering 839fddbe50 shared: add pkcs11-util.[ch] 2019-12-09 19:25:25 +01:00
Lennart Poettering 3f63701983 shared: add openssl helpers 2019-12-09 18:38:59 +01:00
Zbigniew Jędrzejewski-Szmek b069c2a3f2 shared/seccomp: avoid possibly writing bogus errno code in debug log
CID 1409488.

This code was added in 903659e7b2. The change
that is done here is a simple fix to avoid use of a
unitialized/wrongly-initialized variable, but the bigger issue is that nothing
looks at the returned result to distinguish between 0 and a positive return
value.
2019-12-06 15:12:40 +01:00
Zbigniew Jędrzejewski-Szmek 6b2a8b80b4 shared/loop-util: drop inline function with one use 2019-12-06 10:56:49 +01:00
Zbigniew Jędrzejewski-Szmek ba5450f411 shared/loop-util: fix leak of fd in error path 2019-12-06 10:40:20 +01:00
Zbigniew Jędrzejewski-Szmek 1163a2e98a shared/loop-util: operate on the right fd
'loop' is always -1 at this point in the code.
2019-12-06 10:39:14 +01:00
Lennart Poettering 9929fe8c95
Merge pull request #14252 from keszybz/growfs-port-resizefs
Port growfs over to resizefs
2019-12-06 08:55:30 +01:00
Lennart Poettering 5face5a50a
Merge pull request #14167 from cpaelzer/fix-MemoryDenyWriteExecute-x86-s390-bug-1853852-UPSTREAM
Fix memory_deny_write_execute on x86 and s390 with libseccomp 2.4.2
2019-12-06 08:54:54 +01:00
Zbigniew Jędrzejewski-Szmek 68296b8b83
Merge pull request #14221 from poettering/homed-preparatory-resizefs
preparatory fs resizing support split out of homed PR
2019-12-05 10:17:10 +01:00
Zbigniew Jędrzejewski-Szmek d6f1e66076 growfs: port over to resize_fs() 2019-12-05 10:15:49 +01:00
Christian Ehrhardt 5ef3ed97e3
seccomp: use per arch shmat_syscall
At the beginning of seccomp_memory_deny_write_execute architectures
can set individual filter_syscall, block_syscall, shmat_syscall values.
The former two are then used in the call to add_seccomp_syscall_filter
but shmat_syscall is not.

Right now all shmat_syscall values are the same, so the change is a
no-op, but if ever an architecture is added/modified this would be a
subtle source for a mistake so fix it by using shmat_syscall later.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2019-12-05 07:19:12 +01:00
Christian Ehrhardt 903659e7b2
seccomp: ensure rules are loaded in seccomp_memory_deny_write_execute
If seccomp_memory_deny_write_execute was fatally failing to load rules it
already returned a bad retval.
But if any adding filters failed it skipped the subsequent seccomp_load and
always returned an rc of 0 even if no rule was loaded at all.

Lets fix this requiring to (non fatally-failing) load at least one rule set.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2019-12-05 07:19:12 +01:00
Christian Ehrhardt bed4668d1d
seccomp: fix multiplexed system calls
Since libseccomp 2.4.2 more architectures have shmat handled as multiplexed
call. Those will fail to be added due to seccomp_rule_add_exact failing
on them since they'd need to add multiple rules [1].
See the discussion at https://github.com/seccomp/libseccomp/issues/193

After discussions about the options rejected [2][3] the initial thought of
a fallback to the non '_exact' version of the seccomp rule adding the next
option is to handle those now affected (i386, s390, s390x) the same way as
ppc which ignores and does not block shmat.

[1]: https://github.com/seccomp/libseccomp/issues/193
[2]: https://github.com/systemd/systemd/pull/14167#issuecomment-559136906
[3]: https://github.com/systemd/systemd/commit/469830d1
2019-12-05 07:19:07 +01:00
Anita Zhang adae5eb977
Merge pull request #14219 from poettering/homed-preparatory-loop
preparatory /dev/loopN support split out of homed PR
2019-12-04 16:07:41 -08:00
Lennart Poettering b7aa08ca15
Merge pull request #14111 from keszybz/unknown-section-warning
Warn about unknown sections
2019-12-04 14:12:24 +01:00
Zbigniew Jędrzejewski-Szmek 41ab3b7a85
Merge pull request #13953 from SpencerMichaels/systemd-boot-efistub-id-fix
boot: Fix default/oneshot selection for EFISTUB entries
2019-12-04 13:30:52 +01:00
Lennart Poettering 28937bcc6c shared: add new wrapper for online fs resizing ioctls 2019-12-04 11:02:14 +01:00
Lennart Poettering 6b636c2d27 main-func: send main exit code to parent via sd_notify() on exit
So far we silently convert negative return values from run() as
EXIT_FAILURE, which is how UNIX expects it. In many cases it would be
very useful for the caller to retrieve the actual error number we exit
with. Let's generically return that via sd_notify()'s ERRNO= attribute.
This means callers can set $NOTIFY_SOCKET and get the actual error
number delivered at their doorstep just like that.
2019-12-04 10:59:59 +01:00
Lennart Poettering b51d61fec6
Merge pull request #14177 from keszybz/use-initrd.target
Use initrd.target in the initramfs
2019-12-04 10:30:32 +01:00
Topi Miettinen 7477451b69 core: swap priority can be negative
Negative priorities are useful for swap targets which should be only used as
last resort.
2019-12-04 08:57:08 +01:00
Zbigniew Jędrzejewski-Szmek 7cecc56316 cryptsetup-generator: unconfuse writing of the device timeout
The code was using timeout=0 as the default option string. This option string
was ultimately passed to generator_write_timeouts(), which only looks for
comment=systemd.device-timeout= or x-systemd.device-timeout=, i.e. the whole
call path was bogus. Let's rework this: generator_write_timeouts() now writes
any timeouts if configured by the user. create_disk() writes out it's own
timeout, but with lower priority. Since the code path that was calling
timeout=0 was not effective, the only change is that we stop overwriting the
timeout if explicitly configured by the user.

In both code paths, ignore failure to write.
2019-12-03 17:20:19 +01:00
Lennart Poettering 10c1b18888 valgrind: temporarily handle that valgrind still doesn't know LOOP_GET_STATUS64
Should be removed once valgrind learns it.
2019-12-02 10:06:56 +01:00
Lennart Poettering 50d046993b loop-util: if we fail to fully set up a loop device, detach it again 2019-12-02 10:06:45 +01:00
Lennart Poettering b26c39ad2c loop-util: fill in the loopback number, even a posteriori 2019-12-02 10:06:34 +01:00