Commit Graph

22087 Commits

Author SHA1 Message Date
Arseny Maslennikov a0d415da3a udev: Disable HW-address-based naming for IB NICs
An InfiniBand network address is 20 bytes long. Only the least
significant 8 bytes can be interpreted as a persistent hardware unit
identifier; the other 12 are transiently derived at runtime from metadata
specific to the protocol stack.

However, since the network interface name length is hard-capped by
IFNAMSIZ at 16 chars and the 2-byte type prefix with '\0' at the end
leave us only at 13, we cannot squeeze a descriptive representation of a
HW address into an interface name. Thus, it makes the most sense to drop
the scheme for IPoIB interfaces entirely.

Currently udev just gets confused and does what it has been taught
to do: fetches the first six bytes and puts them into a permanent
device attribute.
2018-09-18 20:13:42 +03:00
Arseny Maslennikov 938d30aa98 udev: Introduce predictable naming for InfiniBand NICs
We've long neglected IP-over-InfiniBand network interfaces, let's treat
them the same way we treat anyone else.

IPoIB interfaces will retain the 'ib' prefix; otherwise the naming scheme
is the same one we use for other network interfaces. E.g. a IPoIB network
device provided by a PCI card at bus 21 slot 0 function 6 will be named
'ibp21s0f6'.
2018-09-18 20:13:42 +03:00
Zbigniew Jędrzejewski-Szmek 6058516a14 detect-virt: do not try to read all of /proc/cpuinfo
Quoting https://github.com/systemd/systemd/issues/10074:
> detect_vm_uml() reads /proc/cpuinfo with read_full_file()
> read_full_file() has a file max limit size of READ_FULL_BYTES_MAX=(4U*1024U*1024U)
> Unfortunately, the size of my /proc/cpuinfo is bigger, approximately:
> echo $(( 4* $(cat /proc/cpuinfo | wc -c)))
> 9918072
> This causes read_full_file() to fail and the Condition test fallout.

Let's just read line by line until we find an intersting line. This also
helps if not running under UML, because we avoid reading as much data.
2018-09-18 16:53:36 +02:00
Yu Watanabe 010d436e02 verbs: reset optind (#10116)
optind may be used in each verb, e.g., udevadm. So, let's initialize
optind before calling verbs.

Without this, e.g., udevadm -d hwdb --update causes error in parsing arguments.
2018-09-18 16:24:58 +02:00
Alexander Filippov 047de7e1b1 core: fix the check if CONFIG_CGROUP_BPF is on
Since the commit torvalds/linux@fdb5c4531c
the syscall BPF_PROG_ATTACH return EBADF when CONFIG_CGROUP_BPF is
turned off and as result the bpf_firewall_supported() returns the
incorrect value.

This commmit replaces the syscall BPF_PROG_ATTACH with BPF_PROG_DETACH
which is still work as expected.

Resolves openbmc/linux#159
See also systemd/systemd#7054

Signed-off-by: Alexander Filippov <a.filippov@yadro.com>
2018-09-18 16:19:51 +02:00
Yu Watanabe aca835ed2e core/execute: do not use the negative errno when setup_namespace() returns -ENOANO
Without this, log shows meaningless error message 'No anode', e.g.,
===
Failed to unshare the mount namespace: Operation not permitted
foo.service: Failed to set up mount namespacing: No anode
foo.service: Failed at step NAMESPACE spawning /usr/bin/test: No anode
===

Follow-up for 1beab8b0d0.
2018-09-18 14:31:09 +09:00
Yu Watanabe 2e4a4faea8 core/namespace: add more log messages 2018-09-18 14:31:09 +09:00
Yu Watanabe 5485deee6e
sd-device: use qsort_safe() (#10099)
The number of found devices may be zero. So, let's use qsort_safe().

Follow-up for 0a1665890c.
Fixes #10096.
2018-09-16 23:46:58 +09:00
Zbigniew Jędrzejewski-Szmek 32397af3d4
Merge pull request #9928 from yuwata/libudev-cleanups
libudev: coding style updates
2018-09-15 22:36:38 +02:00
Zbigniew Jędrzejewski-Szmek 9035119518
Merge pull request #9958 from yuwata/sd-device-enum-set
sd-device: make sd_device_enumerator_get_*_next() not destroy the list
2018-09-15 18:33:18 +02:00
Yu Watanabe 0ac4f1a513
Merge pull request #10070 from keszybz/test-reporting
Test reporting improvements
2018-09-15 15:55:15 +09:00
Yu Watanabe 3332004e28 test-catalog: drop unused variable
Follow-up for 49cdae63d1.
2018-09-15 01:59:14 +09:00
Yu Watanabe 72a4d9f96c bus-util: use _printf_ attribute
Follow-up for eda193578e.

Fixes oss-fuzz#10350.
2018-09-15 01:50:59 +09:00
Franck Bui 10ce2e0681 socket-util: attempt SO_RCVBUFFORCE/SO_SNDBUFFORCE only if SO_RCVBUF/SO_SNDBUF fails
Both SO_SNDBUFFORCE and SO_RCVBUFFORCE requires capability 'net_admin'.

If this capability is not granted to the service the first attempt to increase
the recv/snd buffers (via sd_notify()) with SO_RCVBUFFORCE/SO_SNDBUFFORCE will
fail, even if the requested size is lower than the limit enforced by the
kernel.

If apparmor is used, the DENIED logs for net_admin will show up. These log
entries are seen as red warning light, because they could indicate that a
program has been hacked and tries to compromise the system.

It would be nicer if they can be avoided without giving services (relying on
sd_notify) net_admin capability or dropping DENIED logs for all such services
via their apparmor profile.

I'm not sure if sd_notify really needs to forcibly increase the buffer sizes,
but at least if the requested size is below the kernel limit, the capability
(hence the log entries) should be avoided.

Hence let's first ask politely for increasing the buffers and only if it fails
then ignore the kernel limit if we have sufficient privileges.
2018-09-14 13:00:38 +02:00
Zbigniew Jędrzejewski-Szmek 1327f272d3
Merge pull request #9920 from yuwata/udev-cleanup-4
udev: drop unused udev structs and use verbs in udevadm
2018-09-14 10:05:59 +02:00
Zbigniew Jędrzejewski-Szmek 730d989acc tests: add a helper function to skip with errno 2018-09-14 09:29:57 +02:00
Zbigniew Jędrzejewski-Szmek 6d7c403324 tests: use a helper function to parse environment and open logging
The advantages are that we save a few lines, and that we can override
logging using environment variables in more test executables.
2018-09-14 09:29:57 +02:00
Zbigniew Jędrzejewski-Szmek 8b81c382c3 test-condition: make function return void
We don't look at the result anyway.
2018-09-14 09:29:57 +02:00
Zbigniew Jędrzejewski-Szmek 317bb217d3 tests: add helper to unify skipping a test and exiting 2018-09-14 09:29:57 +02:00
Yu Watanabe 2b8b1056d9 test: unset $XDG_{CONFIG,DATA}_DIRS
When $XDG_DATA_DIRS is unset, then, the default value
'/usr/local/share:/usr/share' is used.
When $XDG_DATA_DIRS contain the default paths but the order
is inverted: '/usr/share:/usr/local/share', then test-path-lookup fails.

Fixes #10002.
2018-09-13 12:13:54 +02:00
Yu Watanabe fd1939fbe7 meson: do not build tests by default when '-Dtests=false'
[zj: it is still possible to build tests explicitly by calling
     ninja -C build test-name. This way we have full flexibility.]
2018-09-13 12:07:34 +02:00
Yu Watanabe 964bc0ad60 test: log when skipping tests in more cases
Follow-up for the previous commit.
2018-09-13 12:07:34 +02:00
Zbigniew Jędrzejewski-Szmek 08d541ca06 test: when skipping tests, always print something
It is quite confusing if the test "fails" without printing anything at all.

A typo in an 'if' statement is also fixed.
2018-09-13 12:07:34 +02:00
Zbigniew Jędrzejewski-Szmek 938be08926 meson: disable _all_ tests when -Dtests=false
Back in 08318a2c5a, value "false" was enabled for
'-Dtests=', but various tests were not conditionalized properly. So even with
-Dtests=false -Dslow-tests=false we'd run 120 tests. Let's make this consistent.
2018-09-13 12:07:34 +02:00
Zbigniew Jędrzejewski-Szmek f57d003cb6 test-barrier: just make this a slow test
test-barrier was using a custom mechanism to skip itself. Let's
just follow the normal scheme.
2018-09-13 12:07:34 +02:00
Zbigniew Jędrzejewski-Szmek 0cf29baac0 tests: centralize check for slow tests 2018-09-13 12:07:27 +02:00
Yu Watanabe fb2042dd55 core: add new environment variable $RUNTIME_DIRECTORY= or friends
The variable is generated from RuntimeDirectory= or friends.
If multiple directories are set, then they are concatenated with
the separator ':'.
2018-09-13 17:02:58 +09:00
Yu Watanabe a2917d3d2a test: replace swear words by 'hoge' 2018-09-13 17:02:58 +09:00
Yu Watanabe 474a595af7 test: add tests for strv_join_prefix() 2018-09-13 17:02:58 +09:00
Yu Watanabe 2b9a7d2e96 strv: introduce strv_join_prefix() 2018-09-13 17:02:58 +09:00
Yu Watanabe 7c1cb6f198 core: add one more assert() 2018-09-13 17:02:58 +09:00
Yu Watanabe 76a9460d44 core: fix assert() about number of built environment variables
Follow-up for 4b58153dd2 and
fd63e712b2.
2018-09-13 17:02:58 +09:00
afg 27b620b7db nspawn: use copy-static if systemd-resolved is up and image is writable 2018-09-12 20:48:21 +02:00
Lennart Poettering b0b3ba69c0
Merge pull request #10061 from xnox/fix-logindless-scheduled-shutdown
Fix logindless scheduled shutdown
2018-09-12 20:45:31 +02:00
Lennart Poettering b2b9edd4d1
Merge pull request #10060 from yuwata/property-take-value
bus-util: make --property= optionaly take value
2018-09-12 20:17:53 +02:00
Filipe Brandenburger 49cdae63d1 test: use ${builddir}/systemd-runtest.env for $SYSTEMD_CATALOG_DIR
This makes it so that tests no longer need to know the absolute paths to the
source and build dirs, instead using the systemd-runtest.env file to get these
paths when running from the build tree.

Confirmed that test-catalog works on `ninja test`, when called standalone and
also when the environment file is not present, in which case it will use the
installed location under /usr/lib/systemd/catalog.

The location can now also be overridden for this test by setting the
$SYSTEMD_CATALOG_DIR environment variable.
2018-09-12 09:49:03 -07:00
Filipe Brandenburger e2d413707f test: use ${builddir}/systemd-runtest.env to set $SYSTEMD_TEST_DATA
This simplifies get_testdata_dir() to simply checking for an environment
variable, with an additional function to locate a systemd-runtest.env file in
the same directory as the test binary and reading environment variable
assignments from that file if it exists.

This makes it possible to:
- Run `ninja test` from the build dir and have it use ${srcdir}/test for
  test unit definitions.
- Run a test directly, such as `build/test-execute` and have it locate
  them correctly.
- Run installed tests (from systemd-tests package) and locate the test
  units in the installed location (/usr/lib/systemd/tests/testdata), in
  which case the absence of the systemd-runtest.env file will have
  get_testdata_dir() use the installed location hardcoded into the
  binaries.

Explicit setting of $SYSTEMD_TEST_DATA still overrides the contents of
systemd-runtest.env.
2018-09-12 09:49:03 -07:00
Filipe Brandenburger 55890a40c3 test: remove support for suffix in get_testdata_dir()
Instead, use path_join() in callers wherever needed.
2018-09-12 09:49:03 -07:00
Yu Watanabe eda193578e bus-util: make --property= optionally take value 2018-09-12 12:11:25 +09:00
Michael Biebl 878f2dae77
Merge pull request #10046 from yuwata/fix-10045
test: use installed catalogs when test-catalog is not located at build dir
2018-09-11 23:30:16 +02:00
Dimitri John Ledkov 940bec70bb systemctl: correctly proceed to immediate shutdown if scheduling fails
Actually check the return code from logind_schedule_shutdown() and proceed to
immediate shutdown if that fails. Negative return codes can be returned if
systemctl is compiled without logind support, or if logind otherwise failed
(either too old, disabled/masked, or it is incomplete
systemd-shim/systemd-service implementation).
2018-09-11 10:41:56 +01:00
Yu Watanabe 8aae9a66fa sd-device,libudev: make an argument for *_set_sysattr_value() const 2018-09-11 12:45:21 +09:00
Yu Watanabe 7f9e03952a libudev-monitor: use assert_return() in many places 2018-09-11 12:45:21 +09:00
Yu Watanabe e38242b03a libudev-monitor: add missing error checks in udev_monitor_enable_receiving() 2018-09-11 12:45:21 +09:00
Yu Watanabe a9808d8445 libudev-monitor: introduce udev_monitor_send_sd_device()
And use it in udev_monitor_send_device().
2018-09-11 12:45:21 +09:00
Yu Watanabe 23c457a7fb libudev-monitor: re-implement udev_monitor_receive_sd_device() 2018-09-11 12:45:21 +09:00
Yu Watanabe 759d9f3f8d libudev-monitor: use Hashmap or Set to store filters 2018-09-11 12:45:21 +09:00
Yu Watanabe 5e1e4c247b libudev-monitor: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe a062a72f1b libudev-monitor: rename monitor_set_nl_address() and make it return negative errno 2018-09-11 12:45:21 +09:00
Yu Watanabe be1791ad6a libudev-monitor: rename udev_has_devtmpfs() and move it to mount-util.c
As the function itself is quite generic.
2018-09-11 12:45:21 +09:00
Yu Watanabe 3d01fa902c libudev-monitor: use structured initializer in bpf_*()
This also drop inline attribute from the functions.
2018-09-11 12:45:21 +09:00
Yu Watanabe 7f79720711 libudev-monitor: use 'unsigned' instead of 'unsigned int' 2018-09-11 12:45:21 +09:00
Yu Watanabe 02e7ae2fdc libudev-device: create sd_device at first in udev_device_new_from_*() 2018-09-11 12:45:21 +09:00
Yu Watanabe a7e9db150b libudev-device: drop prototypes of unexistent functions 2018-09-11 12:45:21 +09:00
Yu Watanabe 536cbd7fa6 libudev: drop a prototype of unexistent function 2018-09-11 12:45:21 +09:00
Yu Watanabe 76387b9abb libudev-device: coding style fixes 2018-09-11 12:45:21 +09:00
Yu Watanabe 33a03e6eff libudev-device: fix return value of udev_device_has_tag() 2018-09-11 12:45:21 +09:00
Yu Watanabe 1b6374d285 libudev-device: use original negative errno 2018-09-11 12:45:21 +09:00
Yu Watanabe 71074e3a10 libudev-device: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe 60fdee32bd libudev-enumerate: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe 2b19953a0d libudev-hwdb: use assert_return_errno() 2018-09-11 12:45:21 +09:00
Yu Watanabe 68b80b8557 libudev-hwdb: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe b485aa5852 libudev-hwdb: drop unused 'struct udev *udev' in udev_hwdb struct 2018-09-11 12:45:21 +09:00
Yu Watanabe f8cdabc0ec libudev-queue: coding style fixes 2018-09-11 12:45:21 +09:00
Yu Watanabe 09f638ebd9 libudev-queue: drop prototypes of nonexistent functions 2018-09-11 12:45:21 +09:00
Yu Watanabe 2dac88a9d1 libudev-queue: use _cleanup_ attribute and TAKE_FD() 2018-09-11 12:45:21 +09:00
Yu Watanabe d35c0e8d53 libudev-queue: use assert_return() 2018-09-11 12:45:21 +09:00
Yu Watanabe ccda7f87f5 libudev-queue: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe bc54df90e4 libudev: modernize code a bit 2018-09-11 12:45:21 +09:00
Yu Watanabe 5ccb44a53f libudev: use structured initializer 2018-09-11 12:45:21 +09:00
Yu Watanabe 2454727d5a libudev: drop unused element in udev struct 2018-09-11 12:45:21 +09:00
Yu Watanabe ff6f97f0cf libudev: drop outdated comments 2018-09-11 12:45:21 +09:00
Yu Watanabe 3c6ac21929 libudev: use DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC() macro where applicable 2018-09-11 12:45:21 +09:00
Yu Watanabe 50d2158901 libudev-monitor: use safe_close() in udev_monitor_disconnect() 2018-09-11 12:45:21 +09:00
Thomas Haller a507737e5c dhcp: fix assertion starting DHCP client without MAC address (#10054)
An assertion in dhcp_network_bind_raw_socket() is triggered when
starting an sd_dhcp_client without setting a MAC address first.

  - sd_dhcp_client_start()
    - client_start()
      - client_start_delayed()
        - dhcp_network_bind_raw_socket()

In that case, the arp-type and MAC address is still unset. Note that
dhcp_network_bind_raw_socket() already checks for a valid arp-type
and MAC address below, so we should just gracefully return -EINVAL.

Maybe sd_dhcp_client_start() should fail earlier when starting without
MAC address. But the failure here will be correctly propagated and
the start aborted.

Fixes: 76253e73f9
2018-09-11 09:45:47 +09:00
Yu Watanabe d9b6baa699 test: make test-catalog relocatable
Fixes #10045.
2018-09-11 09:19:36 +09:00
Yu Watanabe 8cb10a4f4d test: introduce test_is_running_from_builddir() 2018-09-11 09:17:22 +09:00
Franck Bui 03d0f4b58e nspawn: always use mode 555 for /sys
When a network namespace is needed, /sys is mounted as tmpfs (see commit
d8fc6a000f for details).

But in this case mode 755 was used as initial permissions for /sys whereas the
default mode for sysfs is 555.

In practice using 755 doesn't have any impact because /sys is mounted read-only
too but for consistency, let's use the correct mode.

Fixes: #10050
2018-09-11 00:34:00 +02:00
Dimitri John Ledkov cf9cda441a Revert "systemctl: if no logind, don't try to schedule shutdown"
This reverts commit c68867da32.
2018-09-10 19:54:12 +01:00
Dimitri John Ledkov 7f56c3d46e Revert "systemctl: fix compilation w/o logind"
This reverts commit 807690fb7f.
2018-09-10 19:53:59 +01:00
Jürg Billeter da0da5eccf pam_systemd: support use in PID namespaces
Pass 0 as leader PID to CreateSession to let logind use the PID from the
D-Bus credentials. This allows use of pam_systemd in PID namespaces.
2018-09-10 19:04:21 +02:00
Yu Watanabe 2bc54be485 udevadm-util: drop unused function print_version() 2018-09-10 18:27:36 +09:00
Yu Watanabe ee4a776d93 udevadm-info: make info_main() returns negative value on error
Also, this replaces fprintf(stderr, ...) by log_error().
2018-09-10 18:27:36 +09:00
Yu Watanabe bb084d42f8 udevadm-trigger: make trigger_main() returns negative value on error 2018-09-10 18:27:36 +09:00
Yu Watanabe 89e94ad333 udevadm-test: modernize code 2018-09-10 18:27:36 +09:00
Yu Watanabe 8450abf423 udevadm-test-builtin: modernize code 2018-09-10 18:27:36 +09:00
Yu Watanabe c71509028f udevadm-settle: modernize code 2018-09-10 18:27:36 +09:00
Yu Watanabe 2b25284ed0 udevadm-monitor: modernize code 2018-09-10 18:27:36 +09:00
Yu Watanabe bb291b7224 udevadm-control: modernize code a bit 2018-09-10 18:27:36 +09:00
Yu Watanabe b77200b6ba udevadm-hwdb: modernize code a bit 2018-09-10 18:27:36 +09:00
Yu Watanabe f73fc95ea5 strbuf: accept NULL for strbuf_cleanup() 2018-09-10 18:27:36 +09:00
Yu Watanabe 3d05193e67 udevadm: use dispatch_verb() and drop udevadm_cmd struct 2018-09-10 18:27:36 +09:00
Yu Watanabe bd696b953e udevd: drop unused refcount 2018-09-10 18:27:36 +09:00
Yu Watanabe 8f71a0d163 udev-ctrl: use DEFINE_TRIVIAL_REF_FUNC() macro or friends 2018-09-10 18:27:36 +09:00
Yu Watanabe 2024ed616e udev: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe 187e1d977a udev: drop unused udev_watch struct 2018-09-10 18:27:36 +09:00
Yu Watanabe 1544d17f73 libudev-util: adjust type of returned value by util_string_hash32() 2018-09-10 18:27:36 +09:00
Yu Watanabe 755c3fe9a7 libudev-util: drop unnecessary argument 'struct udev *udev' from util_resolve_subsys_kernel() 2018-09-10 18:27:36 +09:00
Yu Watanabe e5eadf53fe udev/net: replace udev_device by sd_device 2018-09-10 18:27:36 +09:00
Yu Watanabe 30e888c20a udev/scsi_id: drop never used code blocks 2018-09-10 18:27:36 +09:00
Yu Watanabe 057fc051a4 udev/scsi_id: coding style fixes 2018-09-10 18:27:36 +09:00
Yu Watanabe efc2774c25 udev/scsi_id: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe f1ff9e8dd9 udev/cdrom_id: drop duplicated logs 2018-09-10 18:27:36 +09:00
Yu Watanabe 20a744b795 udev/cdrom_id: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe 893e05590c udev/ata_id: coding style fixes 2018-09-10 18:27:36 +09:00
Yu Watanabe 3b77b4e12f udev/ata_id: drop unused udev struct 2018-09-10 18:27:36 +09:00
Yu Watanabe a168792c2d udev: drop collect 2018-09-10 18:27:36 +09:00
Yu Watanabe 209c6f03bc core/umount: use structured initializers 2018-09-10 16:48:37 +09:00
Yu Watanabe 8437c0593f tree-wide: replace device_enumerator_scan_devices()+FOREACH_DEVICE_AND_SUBSYSTEM() by FOREACH_DEVICE() 2018-09-10 16:48:37 +09:00
Yu Watanabe e132a04392 login/sysfs-show: use device_enumerator_get_devices() 2018-09-10 16:47:35 +09:00
Yu Watanabe 708474c5a0 sd-device: introduce device_enumerator_get_devices() 2018-09-10 16:47:35 +09:00
Yu Watanabe 0a1665890c sd-device: make sd_device_enumerator_get_*_next() not destroy the list 2018-09-10 16:47:35 +09:00
Zbigniew Jędrzejewski-Szmek 9d0798a2ed
Merge pull request #9832 from yuwata/fix-9831
network: fixes related to setting MTU
2018-09-08 17:17:07 +02:00
Zbigniew Jędrzejewski-Szmek a5404992cc
Merge pull request #9942 from lucaswerkmeister/9939
seccomp: fix #9939 and allow specifying multiple errnos for syscall
2018-09-08 12:08:54 +02:00
Evgeny Vereshchagin 231dca5579 tests: put fuzz_journald_processing_function in a .c file 2018-09-08 12:05:14 +02:00
Lucas Werkmeister 9d7fe7c65a seccomp: permit specifying multiple errnos for a syscall
If more than one errno is specified for a syscall in SystemCallFilter=,
use the last one instead of reporting an error. This is especially
useful when used with system call sets:

    SystemCallFilter=@privileged:EPERM @reboot

This will block any system call requiring super-user capabilities with
EPERM, except for attempts to reboot the system, which will immediately
terminate the process. (@reboot is included in @privileged.)

This also effectively fixes #9939, since specifying different errnos for
“the same syscall” (same pseudo syscall number) is no longer an error.
2018-09-07 21:44:13 +02:00
Yu Watanabe e8596ca5c4 backlight: do not unref parent device
Fixes double-free introduced by 9aadd28149.
2018-09-07 20:00:01 +02:00
Yu Watanabe 3457a7a939
Merge pull request #10009 from evverx/rework-journald-fuzzers
Add a fuzzer for server_process_native_message
2018-09-05 11:46:17 +09:00
Yu Watanabe 53253d9c54 sd-dhcp6: set requested time for DUID-LLT
Follow-up for 7e90a499ab.
2018-09-04 13:07:37 -07:00
Yu Watanabe 339697f081 sd-dhcp: drop meaningless checking
mac_addr is not dynamically allocated.

Fixes CID 1395162 and 1395164.
2018-09-04 13:07:37 -07:00
Michal Sekletar 70f5f48eb8 cryptsetup-generator: introduce basic keydev support
Dracut has a support for unlocking encrypted drives with keyfile stored
on the external drive. This support is included in the generated initrd
only if systemd module is not included.

When systemd is used in initrd then attachment of encrypted drives is
handled by systemd-cryptsetup tools. Our generator has support for
keyfile, however, it didn't support keyfile on the external block
device (keydev).

This commit introduces basic keydev support. Keydev can be specified per
luks.uuid on the kernel command line. Keydev is automatically mounted
during boot and we look for keyfile in the keydev
mountpoint (i.e. keyfile path is prefixed with the keydev mount point
path). After crypt device is attached we automatically unmount
where keyfile resides.

Example:
        rd.luks.key=70bc876b-f627-4038-9049-3080d79d2165=/key:LABEL=KEYDEV
2018-09-04 16:54:53 +02:00
Zbigniew Jędrzejewski-Szmek 807690fb7f systemctl: fix compilation w/o logind
Fixes #10006.
2018-09-04 09:34:16 +02:00
Dongsu Park 21224070e8 importd, basic/string-util: use case-insensitive comparison for HTTP headers
According to RFC2616[1], HTTP header names are case-insensitive. So
it's totally valid to have a header starting with either `Date:` or
`date:`.

However, when systemd-importd pulls an image from an HTTP server, it
parses HTTP headers by comparing header names as-is, without any
conversion. That causes failures when some HTTP servers return headers
with different combinations of upper-/lower-cases.

An example:
https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_developer_container.bin.bz2 returns `Etag: "pe89so9oir60"`,
while https://alpha.release.core-os.net/amd64-usr/current/coreos_developer_container.bin.bz2
returns `ETag: "f03372edea9a1e7232e282c346099857"`.
Since systemd-importd expects to see `ETag`, the etag for the Container Linux image
is correctly interpreted as a part of the hidden file name.
However, it cannot parse etag for Flatcar Linux, so the etag the Flatcar Linux image
is not appended to the hidden file name.

```
$ sudo ls -al /var/lib/machines/
-r--r--r--  1 root root 3303014400 Aug 21 20:07 '.raw-https:\x2f\x2falpha\x2erelease\x2ecore-os\x2enet\x2famd64-usr\x2fcurrent\x2fcoreos_developer_container\x2ebin\x2ebz2.\x22f03372edea9a1e7232e282c346099857\x22.raw'
-r--r--r--  1 root root 3303014400 Aug 17 06:15 '.raw-https:\x2f\x2falpha\x2erelease\x2eflatcar-linux\x2enet\x2famd64-usr\x2fcurrent\x2fflatcar_developer_container\x2ebin\x2ebz2.raw'
```

As a result, when the Flatcar image is removed and downloaded again,
systemd-importd is not able to determine if the file has been already
downloaded, so it always download it again. Then it fails to rename it
to an expected name, because there's already a hidden file.

To fix this issue, let's introduce a new helper function
`memory_startswith_no_case()`, which compares memory regions in a
case-insensitive way. Use this function in `curl_header_strdup()`.

See also https://github.com/kinvolk/kube-spawn/issues/304

[1]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
2018-09-03 22:59:27 +02:00
Harald Hoyer 15720d0340 boot/efi/stub.c: fix Dell LoadOptions
On Dell machines LoadOptions is filled with:
01 00 00 00 <name of BIOS Boot Loader Entry> ... <unknown bytes>

So, in case of meaningfull LoadOptions, better check if the first char
is a printable character.
2018-09-03 14:10:38 +02:00
Alan Jenkins 81375d8026 user-runtime-dir: fix selinux regression
Fix #9993.  When this code was split out to user-runtime-dir, it forgot to
include the call to mac_selinux_init().  So mkdir_label() stopped working.

Fixes: a9f0f5e501 ("logind: split %t directory creation to a helper
unit")
2018-09-03 14:09:21 +02:00
Yu Watanabe 7dd05e9472 network: drop an unused variable
Follow-up for 53cb501a13.
2018-09-03 14:08:30 +02:00
Evgeny Vereshchagin 9cdea02db5 tests: add a fuzzer for server_process_native_message 2018-09-03 07:16:52 +00:00
Evgeny Vereshchagin 21acb27b71 journald: make server_process_native_message compatible with fuzz_journald_processing_function 2018-09-03 07:03:52 +00:00
Evgeny Vereshchagin b1bd453f36 tests: rework the code fuzzing journald
This should make it easier to add a new fuzzer without a lot of
duplication.
2018-09-03 06:46:24 +00:00
Yu Watanabe 0de4876496 core/socket: fix memleak in the error paths in usbffs_dispatch_eps() 2018-09-03 14:25:08 +09:00
Renaud Métrich fd790d6f09 journald: fixed assertion failure when system journal rotation fails (#9893) 2018-09-03 12:42:39 +09:00
Evgeny Vereshchagin a70f343cac tests: add a rudimentary fuzzer for server_process_syslog_message (#9979) 2018-09-03 12:18:26 +09:00
Yu Watanabe 645461f0cf
cryptsetup: do not define arg_sector_size if libgcrypt is v1.x (#9990)
Follow-up for #9936.
2018-09-01 23:47:46 +09:00
Yu Watanabe 0c09cb0e78
Merge pull request #9977 from sourcejedi/no-remount-superblock3
Namespace fixes
2018-09-01 23:18:01 +09:00
Alan Jenkins fcac12d150 namespace: remove redundant .has_prefix=false
The MountEntry's added for EMPTY_DIR work very similarly to the TMPFS ones.
In both cases, .has_prefix is false.  In fact, .has_prefix is false in
*all* the MountEntry's we add except for the access mounts (READONLY etc).

But EMPTY_DIR stuck out by explicitly setting .has_prefix = false.
Let's remove that.
2018-09-01 17:23:01 +09:00
Alan Jenkins 4a756839e6 namespace: we always use a root_directory now
We changed to always setup the new namespace in a separate directory
(commit 0722b35)
2018-09-01 17:23:01 +09:00
Alan Jenkins ad8e66dcc4 namespace: fix mode for TemporaryFileSystem=
... when no mount options are passed.

Change the code, to avoid the following failure in the newly added tests:

exec-temporaryfilesystem-rw.service: Executing: /usr/bin/sh -x -c
'[ "$(stat -c %a /var)" == 755 ]'
++ stat -c %a /var
+ '[' 1777 == 755 ']'
Received SIGCHLD from PID 30364 (sh).
Child 30364 (sh) died (code=exited, status=1/FAILURE)

(And I spotted an opportunity to use TAKE_PTR() at the end).
2018-09-01 17:22:14 +09:00
Alan Jenkins 69338c3dfb namespace: don't try to remount superblocks
We can't remount the underlying superblocks, if we are inside a user
namespace and running Linux <= 4.17.  We can only change the per-mount
flags (MS_REMOUNT | MS_BIND).

This type of mount() call can only change the per-mount flags, so we
don't have to worry about passing the right string options now.

Fixes #9914 ("Since 1beab8b was merged, systemd has been failing to start
systemd-resolved inside unprivileged containers" ... "Failed to re-mount
'/run/systemd/unit-root/dev' read-only: Operation not permitted").

> It's basically my fault :-). I pointed out we could remount read-only
> without MS_BIND when reviewing the PR that added TemporaryFilesystem=,
> and poettering suggested to change PrivateDevices= at the same time.
> I think it's safe to change back, and I don't expect anyone will notice
> a difference in behaviour.
>
> It just surprised me to realize that
> `TemporaryFilesystem=/tmp:size=10M,ro,nosuid` would not apply `ro` to the
> superblock (underlying filesystem), like mount -osize=10M,ro,nosuid does.
> Maybe a comment could note the kernel version (v4.18), that lets you
> remount without MS_BIND inside a user namespace.

This makes the code longer and I guess this function is still ugly, sorry.
One obstacle to cleaning it up is the interaction between
`PrivateDevices=yes` and `ReadOnlyPaths=/dev`.  I've added a test for the
existing behaviour, which I think is now the correct behaviour.
2018-08-30 11:17:16 +01:00
Yu Watanabe 7a3c343cb8 tree-wide: use '#pragma once' for header guard
Follow-up for a2b635eb39 (#9959).
2018-08-30 06:10:43 +03:00
Lucas Werkmeister 851ee70a3d seccomp: improve error reporting
Only report OOM if that was actually the error of the operation,
explicitly report the possible error that a syscall was already blocked
with a different errno and translate that into a more sensible errno
(EEXIST only makes sense in connection to the hashmap), and pass through
all other potential errors unmodified. Part of #9939.
2018-08-29 21:42:03 +02:00
Alan Jenkins 8f8112f916 resolve: update comment, avoid alarming wrongness
`systemd-resolved.service` runs as `User=systemd-resolved`, and uses certain
Capabilit{y,ies} magic. By my understanding, this means it is started with a
number of "privileges".  Indeed, `capabilities(7)` explains

> Linux divides  the  privileges  traditionally
> associated  with  superuser into distinct units, known as capabilities,
> which can be independently enabled and disabled."

This situation appears to contradict our current code comment which said

> If we are not running as root we assume all privileges are already dropped.

This appears to be a confusion in the comment only.  The rest of the code
tells a much clearer story.  (Don't ask me if the story is correct.
`capabilities(7)` scares me).  Let's tweak the comment to make it consistent
and avoid worrying readers about this.
2018-08-29 18:07:06 +02:00
Sjoerd Simons 9e2acd1d24 fd-util: accept that kcmp might fail with EPERM/EACCES
In a container the kcmp call might well be blocked; Accept that and fall
back to fstat in that case.
2018-08-29 17:53:00 +02:00
Samuel Morris c68867da32 systemctl: if no logind, don't try to schedule shutdown
If logind is not supported, don't try to schedule a shutdown,
immediately poweroff. This is the behavior indicated by the current
message given to the user, but the command is returning an error. I
believe this was broken on this commit:
7f96539d45
2018-08-29 17:51:53 +02:00
Zbigniew Jędrzejewski-Szmek 31e775ec38
Merge pull request #9959 from yuwata/small-fixes
tiny fixes and a cleanup
2018-08-29 17:47:00 +02:00
Yu Watanabe efa1463693 test: fix a memleak
Follow-up for #9901.

Fixes #9968.
2018-08-29 17:45:37 +02:00
Dimitri John Ledkov a9fc640671 cryptsetup: add support for sector-size= option (#9936)
Bug-Ubuntu: https://launchpad.net/bugs/1776626

Closes #8881.
2018-08-29 23:38:09 +09:00
Yu Watanabe a2b635eb39 sd-boot: fix header guard
Follow-up for a42d7cf165.
2018-08-29 23:05:15 +09:00
Yu Watanabe 3343021755 dynamic-user: drop unnecessary initialization 2018-08-29 23:04:26 +09:00
Zbigniew Jędrzejewski-Szmek 030836923d
Merge pull request #9901 from peterbaouoft/pr/preset_enable_multiple_instances
install: allow instantiated units to be enabled via presets
2018-08-29 14:22:27 +02:00
Yu Watanabe 22ac37aa00 string-table: do not ignore 'scope' argument 2018-08-28 12:40:25 +09:00
Yu Watanabe e094eb1188
Merge pull request #9950 from yuwata/macro-ref-unref
tree-wide: introduce macros to define *_ref() and *_unref() functions
2018-08-28 10:43:25 +09:00
Ruixin Bao 1e475a0ab4 install: small refactor to combine two function calls into one function
Combine consecutive function calls of install_info_discover and
install_info_may_process into one short helper function.
2018-08-27 23:56:31 +00:00
Ruixin Bao 4c9565eea5 install: allow instantiated units to be enabled via presets
This patch implements https://github.com/systemd/systemd/issues/9421.

The .preset file now is able to take a rule in the format of:(e.g)
enable foo@.service bar0 bar1 bar2

In the above example, when preset-all is called, all three instances of
foo@bar0.service, foo@bar1.service and foo@bar2.service will be enabled.

When preset is called on a single service(e.g: foo@bar1.service), only
the mentioned one(foo@bar1.service) will be enabled.

Tests are added for future regression.
2018-08-27 23:56:24 +00:00
Yu Watanabe 4005d3215e sd-device: sd_device_enumerator_get_subsystem_next() requests the device list is uptodate 2018-08-28 05:09:40 +09:00
Yu Watanabe 6116d2b275 sd-device: use structured initializers 2018-08-28 05:09:40 +09:00
Yu Watanabe 1c71f7f329 libsystemd: use DEFINE_ATOMIC_REF_UNREF_FUNC or frineds where applicable 2018-08-28 05:09:40 +09:00
Yu Watanabe 1d3044e275 refcnt: introduce DEFINE_ATOMIC_REF_UNREF_FUNC() macro and friends 2018-08-28 05:09:40 +09:00
Yu Watanabe 6b6e07415c sd-netlink: fix indentation 2018-08-28 05:09:40 +09:00
Yu Watanabe 61e21d4ca1 sd-hwdb: drop unused variable 2018-08-28 05:09:40 +09:00
Yu Watanabe 288ca7af8c dynamic-user: fix potential segfault 2018-08-28 05:09:00 +09:00
Zbigniew Jędrzejewski-Szmek 649010a53d
Merge pull request #9935 from pfl/dhcp6_pd_assignment_fix
Dhcp6 pd assignment fix
2018-08-27 14:49:11 +02:00
Thomas Haller 3301f9eb97 link: allocate correct number of bytes in ethtool_set_features()
sfeatures is a "struct ethtool_sfeatures". Use sizeof() on the correct
data type.

Since "struct ethtool_gstrings" is larger than "struct ethtool_sfeatures",
this had no serious consequences.

Fixes: 50725d10e3
2018-08-27 14:14:30 +02:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Yu Watanabe a6a08596ef macro: introduce DEFINE_TRIVIAL_REF_UNREF_FUNC() macro and friends 2018-08-27 14:01:27 +09:00
Yu Watanabe cf4b2f9906 tree-wide: use unsigned for refcount 2018-08-27 13:48:04 +09:00
Patrik Flykt eb75b919e8 networkd-dhcp6: Improve logging on DHCPv6 PD assignment
Print out prefixes assigned to links in addition to the DHCPv6
prefix it was delegated from.
2018-08-24 09:53:46 -06:00
Patrik Flykt ef5df4e5c5 networkd-dhcp6: Fix logging of DHCPv6 prefix
Pretty-print log messages with DHCPv6 prefixes after the prefixes
have been set instead of some random unassigned stack values.
2018-08-24 09:53:46 -06:00
Patrik Flykt 37f52406d9 networkd-dhcp6: Fix PD prefix length for subnet assignment
When computing the next network prefix to assign, compute the next
prefix to allocate based on the intended /64 assignment, not the
given prefix length for the whole prefix, e.g. /48, given to
systemd-networkd.

Fixes #9626.
2018-08-24 09:53:46 -06:00
Patrik Flykt 3ec8303fdc networkd-dhcp6: Log warning with PD prefixes shorter than 48
Log a warning message in case the network prefix delegated is shorter
than /48.
2018-08-24 09:53:45 -06:00
Yu Watanabe 7ecc4799a9
dissect: rescan devices before creating partition list (#9930)
Fixes #9924 which is caused by 3c1f2cee0a.
2018-08-24 22:34:13 +09:00
Franck Bui 49679ff70f logind: make use of vtnr_from_tty() in seat_read_active_vt() (#9923)
No functional changes.
2018-08-24 16:20:51 +09:00
Yu Watanabe 593a5213ce
Merge pull request #9917 from keszybz/cleanups
Some unrelated fixups for recent PRs
2018-08-24 10:43:41 +09:00
Zbigniew Jędrzejewski-Szmek e6a2feb57d
Merge pull request #8135 from shawnl/arg_host
sd-bus: rework host handling
2018-08-23 13:46:54 +02:00
Zbigniew Jędrzejewski-Szmek e3bb989b6f network: adjust some error messages
The option is now called simply "Encapsulation=".

Also, "ignoring" is rather misleading, because we use to to mean that some line
is being ignored. Here the whole tunnel is dropped.
2018-08-23 11:43:28 +02:00
Zbigniew Jędrzejewski-Szmek ab4dd98476 network: reword some error messages
Use "falling back" instead of "fallback".

Also, it's not an application-specific machine ID, but rather an
application-and-machine-specific ID.  Let's call it "app-machine-speicific" for
short.
2018-08-23 11:32:55 +02:00
Zbigniew Jędrzejewski-Szmek 181c4ba750 test-socket-util: avoid "memleak" reported by valgrind
valgrind reports the allocation done in the short-lived child as a leak.
Let's restructure the code to avoid this.
2018-08-23 11:30:57 +02:00
Zbigniew Jędrzejewski-Szmek b5d6f7ead6 analyze: use temporary var to simplify code 2018-08-23 11:30:57 +02:00
Susant Sahani 53cb501a13 networkd and sd-netlink: add support for Generic netlink And FooOverUDP to IPIP tunnel
This work add support to generic netlink to sd-netlink.
See https://lwn.net/Articles/208755/

networkd: add support FooOverUDP support to IPIP tunnel netdev
https://lwn.net/Articles/614348/

Example conf:

/lib/systemd/network/1-fou-tunnel.netdev
```
[NetDev]
Name=fou-tun
Kind=fou

[FooOverUDP]
Port=5555
Protocol=4

```

/lib/systemd/network/ipip-tunnel.netdev
```
[NetDev]
Name=ipip-tun
Kind=ipip

[Tunnel]
Independent=true
Local=10.65.208.212
Remote=10.65.208.211
FooOverUDP=true
FOUDestinationPort=5555
```

$ ip -d link show ipip-tun
```
5: ipip-tun@NONE: <POINTOPOINT,NOARP> mtu 1472 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ipip 10.65.208.212 peer 10.65.208.211 promiscuity 0
    ipip remote 10.65.208.211 local 10.65.208.212 ttl inherit pmtudisc encap fou encap-sport auto encap-dport 5555 noencap-csum noencap-csum6 noencap-remcsum numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
```
2018-08-23 11:30:37 +02:00
Zbigniew Jędrzejewski-Szmek c07fe6d0df Merge pull request #9406 from yuwata/rfe-9228
Trivial conflict solved in merge and include net/if_arp.h added.
2018-08-23 11:11:13 +02:00
Susant Sahani 708c425d0a Networkd: Start DHCP server when link is up.
Closes #9479
2018-08-23 10:03:30 +02:00
Yu Watanabe 152d0efa2b udev: move udev cleanup functions from udev-util.h to udev.h 2018-08-23 04:57:39 +09:00
Yu Watanabe 05becb11e8 udev-util: drop unused function udev_device_new_from_stat_rdev() 2018-08-23 04:57:39 +09:00
Yu Watanabe e156d24b0a login/sysfs-show: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 4f209af7da logind: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 4366e598ae core: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 6bcf00eda3 core/umount: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 21384b8129 rfkill: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe f55b0d3fd6 nspawn: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 8bebb09ce7 journal: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe ad5944d71c sd-device: introduce device_new_from_stat_rdev() 2018-08-23 04:57:39 +09:00
Yu Watanabe 3c1f2cee0a dissect: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 85624f018d gpt-auto-generator: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe dcd265239b mount-tool: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 9aadd28149 backlight: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 3782454c41 libudev: introduce udev_monitor_receive_sd_device() 2018-08-23 04:57:39 +09:00
Yu Watanabe 7c7be5515f libudev: move cleanup functions from udev-util.h to libudev-private.h 2018-08-23 04:57:39 +09:00
Yu Watanabe 3938f568a2 libudev: accept NULL as the argument 'struct udev*' for udev_monitor_new() or friends
As udev_monitor struct or friends are now almost independent of udev
struct. So, generating these objects without udev struct is reasonable.
2018-08-23 04:57:39 +09:00
Tejun Heo 6ae4283cb1 core: add IODeviceLatencyTargetSec
This adds support for the following proposed latency based IO control
mechanism.

  https://lkml.org/lkml/2018/6/5/428
2018-08-22 16:46:18 +02:00
Yu Watanabe 71d1700afa selinux-util: drop unused variables
Follow-up for 7e531a5265.
2018-08-22 16:32:35 +02:00