Commit graph

23022 commits

Author SHA1 Message Date
Lennart Poettering 92025e8f52 random-util: initialize srand() from RDRAND
It's cheap to get RDRAND and given that srand() is anyway not really
useful for trusted randomness let's use RDRAND for it, after all we have
all the hard work for that already in place.
2018-11-06 12:12:18 +01:00
Lennart Poettering 54bf23151f random-util: we don't intend to write to auxv, hence make it const 2018-11-06 12:12:18 +01:00
Yu Watanabe 6bee206591 udev-node: add one more debug log when failed to create symlink 2018-11-06 15:45:22 +09:00
Yu Watanabe a126a38a9f udev-node: drop redundant log message
As node_symlink() logs almost same message.
2018-11-06 15:45:22 +09:00
Yu Watanabe 6174a243f9 udev: setting the same log level to SYSTEMD realm
Otherwise, many debug logs from libsystemd are dropped.
2018-11-06 15:45:22 +09:00
Yu Watanabe a5db6debcd test: check returned value of sd_device_get_usec_since_initialized() 2018-11-06 15:45:22 +09:00
Yu Watanabe 754d6c26b4 test: show is_initialized flag in log message of test-sd-device
And drop devpath, as it is redundant for most cases.
2018-11-06 15:45:22 +09:00
Yu Watanabe ecbe9873a9 test: show name of testing functions in test-sd-device 2018-11-06 15:45:22 +09:00
Yu Watanabe c7d54daef9 sd-device: normalize debug messages 2018-11-06 15:45:22 +09:00
Yu Watanabe 38d1555d7c sd-device: drop subsystem from log_device_*()
The sd_device object always has syspath and sysname, but subsytem may not.
Also, it may take some costs to get subsystem.
So, let's drop subsystem from logs.
2018-11-06 15:45:22 +09:00
Yu Watanabe cc0bf5e148 udev-watch: adjust level of log messages 2018-11-06 11:15:39 +09:00
Yu Watanabe 7fe3324c5e udev-watch: make udev_watch_lookup() return 1 when device found 2018-11-06 11:15:39 +09:00
Yu Watanabe b7759e0403 udev: drop redundant log message and fix returned error code 2018-11-06 11:15:39 +09:00
Lennart Poettering 8912a99cea
Merge pull request #10606 from yuwata/udev-tests
test: mask hwdb-update.services in most tests
2018-11-05 23:14:42 +03:00
Lennart Poettering a54e373163
Merge pull request #10618 from yuwata/fix-10615
network: fix several issues in config parser
2018-11-05 17:37:25 +03:00
Yu Watanabe 3d8d1f13d5 test: add tests for config_parse_address() 2018-11-05 16:46:26 +09:00
Yu Watanabe b7cb445235 network: use in_addr_default_prefix_from_string_auto() in config_parse_address() 2018-11-05 16:46:26 +09:00
Yu Watanabe c1d58204b2 test: add tests for in_addr_default_prefix_from_string() or friend 2018-11-05 16:46:26 +09:00
Yu Watanabe a4798d4e6d util: introduce in_addr_default_prefix_from_string() and friends
It is similar to in_addr_prefix_from_string() but it determines
the prefix length from address if it is not specified.
2018-11-05 16:46:26 +09:00
Yu Watanabe 67944f5c26 util: use strndup() instead of strndupa()
As the input string may be comes from command line or config files.
2018-11-05 16:46:00 +09:00
Yu Watanabe a7cc45caad network: sort headers in wireguard.h 2018-11-05 13:19:02 +09:00
Yu Watanabe fc72155321 network: use structured initializers in wireguard.c 2018-11-05 13:19:02 +09:00
Yu Watanabe c195364da5 network: fix crash in wireguard_done()
Fixes another issue in #10629.
2018-11-05 13:19:02 +09:00
Yu Watanabe 56ba90c2df network: use destroy callback to unref netdev attached to event source 2018-11-05 13:19:02 +09:00
Yu Watanabe 8173d1d0ec network: use destroy callback to clear resolved wireguard endpoints 2018-11-05 13:19:02 +09:00
Yu Watanabe c4397d94c3 network: link_drop() and netdev_drop() remove reference from manager 2018-11-05 13:19:02 +09:00
Yu Watanabe 2382c9367b sd-event: add sd_event_source_{get,set}_floating() 2018-11-05 13:19:02 +09:00
Yu Watanabe b3ae7237c6 sd-resolve: introduce sd_resolve_query_{get,set}_floating() 2018-11-05 13:19:02 +09:00
Yu Watanabe a8319dea1d sd-resolve: introduce sd_resolve_query_{get,set}_destroy_callback() 2018-11-05 13:19:02 +09:00
Yu Watanabe 383bb2bc1a vlan-util: add assertions to parse_vlanid() 2018-11-04 00:31:46 +09:00
Yu Watanabe 2e5da68b7d network: add missing .sections element for vcan and vrf
Fixes #10629.
2018-11-04 00:31:46 +09:00
Yu Watanabe de4224aa22 network: fix memleak abot Address.label
Also fix possible memleak about Address.section.
Fixes #10628.
2018-11-04 00:31:46 +09:00
Yu Watanabe 7946d57f18 network: drop error cause in log message
Fixes for 21486d9e99.
2018-11-04 00:31:46 +09:00
Yu Watanabe ecee0abe77 network: fix memleak in static prefix
The fix by 744faf5e4e is not perfect,
as the section leaks if `hashmap_put()` in `prefix_new_static()` fails.
2018-11-04 00:31:46 +09:00
Yu Watanabe 6f1a96ded4 netdev: also support GENEVE.UDP6ZeroChecksum{Tx,Rx}=
After 53c06862c1, we prefer Checksum
instead of CheckSum. Let's do so for GENEVE netdev.
2018-11-04 00:31:46 +09:00
Yu Watanabe fd3005f9b8 network: fix worng offset for .network parser 2018-11-04 00:31:46 +09:00
Yu Watanabe 899f0d259d network: fix memleak in config_parse_hwaddr()
Fixes #10615.
2018-11-04 00:31:46 +09:00
Yu Watanabe 44386b449b network: improve readability of config_parse_ifalias() 2018-11-04 00:31:46 +09:00
Yu Watanabe 25ed70f76f network: fix possible memleak caused by multiple setting of Bridge=, Bond= or VRF= 2018-11-04 00:31:46 +09:00
Yu Watanabe 5f74e49e85 test: add test for radv_prefix_delegation_{from,to}_string() 2018-11-04 00:31:46 +09:00
Yu Watanabe 6b1dec6696 network: introduce radv_prefix_delegation_{from,to}_string() 2018-11-04 00:31:46 +09:00
Yu Watanabe 8a4871c7d1 network: fix indentation 2018-11-04 00:31:46 +09:00
Yu Watanabe 8627d1120a network: invert the order in comparison 2018-11-04 00:31:46 +09:00
Yu Watanabe 1176b054e1 network: shorten code a bit 2018-11-04 00:31:06 +09:00
Yu Watanabe 76281c6408 test: also run compile tests for libudev.h 2018-11-03 18:00:47 +09:00
Franck Bui 1d88bce2a0 coredump: only install coredump.conf when ENABLED_COREDUMP=true 2018-11-02 14:31:12 +01:00
Tobias Jungel 99f68ef02d networkd: add missing bonding options (#10542)
Add support for bonding options system prio, port key and actor system mac.

These options exist in the linux kernel since 4.2
(torvalds/linux@171a42c38c)

Details:
https://www.kernel.org/doc/Documentation/networking/bonding.txt
2018-11-02 10:31:20 +09:00
Yu Watanabe cb700a11d9 network: drop white space in log message 2018-11-01 23:41:29 +09:00
Yu Watanabe 0d7febd002 network: fix hash function for routing policy rule 2018-11-01 23:40:56 +09:00
Yu Watanabe e6b65ab760 network: fix return value of routing_policy_rule_get()
To distinguish source of rule.
2018-11-01 23:38:11 +09:00
Yu Watanabe a6276f0f3f network: fix memleak in routing policy
As set_put() may fail if input is duplicated.
2018-11-01 23:24:20 +09:00
Yu Watanabe 744faf5e4e network: fix memleak in static prefix
Fixes #10608.
2018-11-01 21:46:38 +09:00
Yu Watanabe f19ee68140 network: fix segfault in manager_free()
Fixes #10605.
2018-11-01 20:26:02 +09:00
Lennart Poettering 6619ad889d nspawn: beef up netns checking a bit, for compat with old kernels
Fixes: #10544
2018-10-31 21:42:45 +03:00
Xiang Fan c7b7d74e81 ask-password: check keyring in ask_password_tty and ask_password_agent
A race condition happens when calling ask_password_auto() multiple times
to unlock several disks on boot and effectively no password caching is
utilized. This patch fixes it by polling the cache when waiting for
the password.
2018-10-31 18:26:58 +01:00
Lennart Poettering 45313bd921
Merge pull request #10010 from msekletar/cryptsetup-generator-keydev-followups
cryptsetup-generator: keydev support - followups
2018-10-31 18:26:25 +01:00
Lennart Poettering e2d39e549f nspawn: add proper error message if setns() on network namespace fd fails
Addresses: https://github.com/systemd/systemd/pull/10589#issuecomment-434670595
2018-10-31 18:07:30 +01:00
Lennart Poettering 1ad6e8b302 core: split environment block mantained by PID 1's Manager object in two
This splits the "environment" field of Manager into two:
transient_environment and client_environment. The former is generated
from configuration file, kernel cmdline, environment generators. The
latter is the one the user can control with "systemctl set-environment"
and similar.

Both sets are merged transparently whenever needed. Separating the two
sets has the benefit that we can safely flush out the former while
keeping the latter during daemon reload cycles, so that env var settings
from env generators or configuration files do not accumulate, but
dynamic API changes are kept around.

Note that this change is not entirely transparent to users: if the user
first uses "set-environment" to override a transient variable, and then
uses "unset-environment" to unset it again things will revert to the
original transient variable now, while previously the variable was fully
removed. This change in behaviour should not matter too much though I
figure.

Fixes: #9972
2018-10-31 18:00:53 +01:00
Lennart Poettering bea1a01310 strv: wrap strv_new() in a macro so that NULL sentinel is implicit 2018-10-31 18:00:52 +01:00
Lennart Poettering fc03c53653
Merge pull request #10573 from faheel/master
Convert remaining docs to Markdown
2018-10-31 15:15:41 +01:00
Lennart Poettering 0aeff581cc
Merge pull request #10556 from yuwata/udev-event-cleanup-2
udev-event: several fixes for previous PR
2018-10-31 12:10:12 +01:00
Yu Watanabe 21486d9e99 network: also monitor udev 'change' event for network interfaces
If networkd starts earlier than all network interfaces are initialized,
then uninitialized interfaces are staying in pending state and cannot
become up.
With this, such interfaces are started after receiving 'change' event.
2018-10-31 12:08:34 +01:00
Joerg Behrmann 56ef8db9f5 core: apply WorkingDirectory after enforce_user
If WorkingDirectory is on NFS, root might only have the privileges of
nobody and the chdir to the WorkingDirectory might fail, even if the
user running the service would have the proper privileges to chdir to
that directory.

Fixes #10568
2018-10-31 12:07:24 +01:00
Zbigniew Jędrzejewski-Szmek 2f5ed71556 Drop copyright for Marius Vollmer
Ack in #9320.
2018-10-31 09:34:38 +01:00
Yu Watanabe fbd0aea17e dissect: do not store unused devnum 2018-10-31 09:29:51 +09:00
Yu Watanabe 4375dab58d udev-event: fix timeout log messages
Follow-up for e81c3a4c5f.
2018-10-31 09:29:51 +09:00
Yu Watanabe 7af1c7808b udev-event: do not store unused devnum 2018-10-31 09:29:51 +09:00
Yu Watanabe d4a95a952e udev-event: check whether device has devnum before calling udev_node_remove()
This fixes a bug in 'remove' event handling, which was introduced by
eb1f9e30ec, as 'devnum' variable may
not be initialized.
2018-10-31 09:29:51 +09:00
Faheel Ahmad eea984028f docs: Update links to updated docs 2018-10-30 23:01:20 +05:30
Insun fee04d7f3a core: don't drop timer expired but not yet processed when system date is changed
There is difference between time set by the user and real elapsed time because of accuracy feature.
If you change the system date(or time) between these times, the timer drops.

You can easily reproduce it with the following command.
-----------------------------------------------------------
$ systemd-run --on-active=3s ls; sleep 3; date -s "`date`"
-----------------------------------------------------------

In the following command, the problem is rarely reproduced. But it exists.
---------------------------------------------------------------------------------------------
$ systemd-run --on-active=3s --timer-property=AccuracySec=1us ls ; sleep 1; date -s "`date`"
---------------------------------------------------------------------------------------------

Note : Global AccuracySec value.
----------------------------------------------------------------------
$ cat /etc/systemd/system.conf
DefaultTimerAccuracySec=1min
----------------------------------------------------------------------
2018-10-30 15:38:45 +01:00
Lennart Poettering c1b785bb66
Merge pull request #10559 from yuwata/sd-device-prototype-change
sd-device: change prototype of sd_device_get_is_initialized()
2018-10-30 15:36:52 +01:00
Franck Bui 651b3b6c92 core: skip unit deserialization and move to the next one when unit_deserialize() fails
If unit_deserialize() fails (because one read line is overly long), it returns
an error and we would have assumed that the next read would point to the next
unit to deserialize.

But instead unit_deserialize() can leave the file offset in the middle of a
line.

Therefore we need to ignore and skip the current unit in this case too.

While at it, move unit deserialization in a dedicated functions. That should
make the code easier to read.
2018-10-30 14:52:13 +01:00
Lennart Poettering 8cb17a64c4
Merge pull request #10563 from keszybz/lz4-quickfix-quickfix
journal: adapt for new improved LZ4_decompress_safe_partial()
2018-10-30 14:51:55 +01:00
Zbigniew Jędrzejewski-Szmek 029427043b fuzz-compress: add fuzzer for compression and decompression 2018-10-30 11:04:53 +01:00
Zbigniew Jędrzejewski-Szmek e41ef6fd00 journal: adapt for new improved LZ4_decompress_safe_partial()
With lz4 1.8.3, this function can now decompress partial results into a smaller
buffer. The release news don't say anything interesting, but the test case that
was previously failing now works OK.

Fixes #10259.

A test is added. It shows that with *older* lz4, a partial decompression can
occur with the returned size smaller then the requested number of bytes _and_
smaller then the size of the compressed data:

(lz4-libs-1.8.2-1.fc29.x86_64)
Compressed 4194304 → 16464
Decompressed → 4194304
Decompressed partial 12/4194304 → 4194304
Decompressed partial 1/1 → -2 (bad)
Decompressed partial 2/2 → -2 (bad)
Decompressed partial 3/3 → -2 (bad)
Decompressed partial 4/4 → -2 (bad)
Decompressed partial 5/5 → -2 (bad)
Decompressed partial 6/6 → 6 (good)
Decompressed partial 7/7 → 6 (good)
Decompressed partial 8/8 → 6 (good)
Decompressed partial 9/9 → 6 (good)
Decompressed partial 10/10 → 6 (good)
Decompressed partial 11/11 → 6 (good)
Decompressed partial 12/12 → 6 (good)
Decompressed partial 13/13 → 6 (good)
Decompressed partial 14/14 → 6 (good)
Decompressed partial 15/15 → 6 (good)
Decompressed partial 16/16 → 6 (good)
Decompressed partial 17/17 → 6 (good)
Decompressed partial 18/18 → -16459 (bad)

(lz4-libs-1.8.3-1.fc29.x86_64)
Compressed 4194304 → 16464
Decompressed → 4194304
Decompressed partial 12/4194304 → 12
Decompressed partial 1/1 → 1 (good)
Decompressed partial 2/2 → 2 (good)
Decompressed partial 3/3 → 3 (good)
Decompressed partial 4/4 → 4 (good)
...

If we got such a short "successful" decompression in decompress_startswith() as
implemented before this patch, we could be confused and return a false negative
result. But it turns out that this only occurs with small output buffer
sizes. We use greedy_realloc() to manager the buffer, so it is always at least
64 bytes. I couldn't hit a case where decompress_startswith() would actually
return a bogus result. But since the lack of proof is not conclusive, the code
for *older* lz4 is changed too, just to be safe. We cannot rule out that on a
different architecture or with some unlucky compressed string we could hit this
corner case.

The fallback code is guarded by a version check. The check uses a function not
the compile-time define, because there was no soversion bump in lz4 or new
symbols, and we could be compiled against a newer lz4 and linked at runtime
with an older one. (This happens routinely e.g. when somebody upgrades a subset
of distro packages.)
2018-10-30 11:04:51 +01:00
Zbigniew Jędrzejewski-Szmek ba17efce44 test-compress: add test for short decompress_startswith calls
I thought this might fail with lz4 < 1.8.3, but it seems that because of
greedy_realloc, we always use a buffer that is large enough, and it always
passes.
2018-10-30 09:28:51 +01:00
Michal Sekletar 7949dfa73a cryptsetup-generator: allow whitespace characters in keydev specification
For example, <luks.uuid>=/keyfile:LABEL="KEYFILE FS" previously wouldn't
work, because we truncated label at the first whitespace character,
i.e. LABEL="KEYFILE".
2018-10-30 09:18:46 +01:00
Michal Sekletar 579875bc4a cryptsetup-generator: don't return error if target directory already exists 2018-10-30 09:02:34 +01:00
Zbigniew Jędrzejewski-Szmek e0a1d4b049 Drop support for lz4 < 1.3.0
lz4-r130 was released on May 29th, 2015. Let's drop the work-around for older
versions. In particular, we won't test any new code against those ancient
releases, so we shouldn't pretend they are supported.
2018-10-29 21:54:42 +01:00
Evgeny Vereshchagin 28ffcec2cb tests: add an lldp fuzzer
I went through my antique collection of fuzzers the other day
to see which ones I hadn't sent upstream yet. This one
seems to be nice to have and ready to be merged. As far as I can
tell, it hasn't managed to find anything useful yet,
but it's better to be safe than sorry especially when it comes to networking
code :-)
2018-10-29 15:24:16 +00:00
Evgeny Vereshchagin e0f768c356 journal: drop an unused variable clang is complaining about
../../src/systemd/src/journal/journal-file.c:3592:30: warning: unused variable 'p' [-Wunused-variable]
        _cleanup_free_ char *p = NULL;
                             ^
1 warning generated.

This is a follow-up to 6812765891.
2018-10-29 15:21:58 +00:00
Yu Watanabe 5a937ea2f6 sd-device: make sd_device_get_is_initialized() returns is_initialized by return value 2018-10-29 17:33:33 +09:00
Yu Watanabe 78ffb476f2 sd-device: make several sd_device_get_*() accepts NULL pointer for buffer of returned value
When only the existence of the value are important, then we can set
NULL now.
2018-10-29 17:18:00 +09:00
Yu Watanabe 7b32820444
Merge pull request #10551 from keszybz/two-trivial-cleanups
Two trivial cleanups
2018-10-29 12:03:27 +09:00
Yu Watanabe 898ce5e8b8 util: do not assign return value if it is not used (#10552) 2018-10-28 18:41:35 -07:00
Zbigniew Jędrzejewski-Szmek 2b68626089 test-chown-rec: use logging helper here too 2018-10-28 23:28:34 +01:00
Zbigniew Jędrzejewski-Szmek 910fd5317f test-network-tables: remove duplicate line 2018-10-28 18:27:48 +01:00
Zbigniew Jędrzejewski-Szmek 815628cdd4
Merge pull request #10512 from yuwata/udev-event-cleanup
udev-event: replace udev_device by sd_device
2018-10-28 13:00:14 +01:00
Dave Reisner e6b538d066 curl-util: fix error code check from curl_multi_socket_action
After curl 7.20.0, this function never returns negative error codes.
Make this consistent with the other call to this function and only
compare against CURLM_OK.
2018-10-27 12:04:45 +02:00
Yu Watanabe 9c3c438514
Merge pull request #10537 from poettering/sentinelimania
add some missing _sentinel_ decorators
2018-10-27 07:49:28 +09:00
Yu Watanabe 4cade7a15b udev-event: replace udev_device in subst_format_var() by sd_device 2018-10-27 07:25:27 +09:00
Yu Watanabe a315999de6 udev-event: drop prototype of nonexistent function 2018-10-27 07:25:27 +09:00
Yu Watanabe 9204d8023f udev-event: move definition of struct subst_map 2018-10-27 07:25:27 +09:00
Yu Watanabe eb1f9e30ec udev-event: replace udev_device in udev_event_execute_rules() by sd_device
Also, this adds many logs.
2018-10-27 07:25:27 +09:00
Yu Watanabe e52eaf5649 udev-event: move devnode handling logic to a new function
Also, replace udev_device by sd_device.
2018-10-27 07:25:27 +09:00
Yu Watanabe 2740750d40 udev-event: move conditions to rename network interface into rename_netif()
Also, replace udev_device by sd_device.
2018-10-27 07:24:03 +09:00
Yu Watanabe c1118ceba4 udev-event: rename udev_event_unref() to udev_event_free()
As struct udev_event does not have a reference counter.
2018-10-27 07:03:39 +09:00
Yu Watanabe d737197154 udev-event: fix memleak in udev_event
The leak was introduced by 29448498c7.
2018-10-27 07:03:39 +09:00
Yu Watanabe 89665d0920 udev-event: use structured initializer at one more place 2018-10-27 07:03:39 +09:00
Yu Watanabe a368732bc4 udev-event: add more assert() 2018-10-27 07:03:39 +09:00
Yu Watanabe dc8aec36a6 udev-event: check command is not empty before executing 2018-10-27 07:03:39 +09:00
Yu Watanabe e9343893f7 udev-event: include device name in error message one more place 2018-10-27 07:03:39 +09:00
Yu Watanabe 7606377e2c network,udev: drop unnecessary check whether ifindex is positive
As sd_device_get_ifindex() now returns positive ifindex when it
succeeds.
2018-10-27 07:03:39 +09:00
Yu Watanabe 5d062b4ef0 test: check sd_device_get_ifindex() returns positive ifindex when it succeeds 2018-10-27 07:03:39 +09:00
Yu Watanabe 1dfa960786 sd-device: return positive ifindex when sd_device_get_ifindex() succeeds
As valid ifindex is positive value, not non-negative value.

Follow-up for dcfbde3a43.
2018-10-27 07:03:38 +09:00
Lennart Poettering 6897dfe85a core: add free_and_replace() at one more place 2018-10-26 19:49:15 +02:00
Lennart Poettering 7593c3ecbf tree-wide: add a few missing _sentinel_ decorators 2018-10-26 19:49:15 +02:00
Lennart Poettering 46f84f955f cgroup-util: make definition of CGROUP_CONTROLLER_TO_MASK() unsigned
Otherwise doing comparing a CGroupMask (which is unsigned in effect)
with the result of CGROUP_CONTROLLER_TO_MASK() will result in warnings
about signedness differences.
2018-10-26 18:43:34 +02:00
Lennart Poettering f99850a0d4 cgroup-util: FLAGS_SET()ify all things 2018-10-26 18:43:34 +02:00
Lennart Poettering 03afd78029 cgroup: when discovering which controllers the kernel supports mask with what we support
Let's use our new CGROUP_MASK_V1 and CGROUP_MASK_V2 definitions for
this.
2018-10-26 18:43:34 +02:00
Lennart Poettering ab275f2386 cgroup-util: before operating on a mounted cgroup controller check if it actually can be mounted
We now have the "BPF" pseudo-controllers. These should never be assumed
to be accessible as /sys/fs/cgroup/<controller> and not through
"cgroup.subtree_control" either, hence always check explicitly before we
go to the file system. We do this through our new CGROUP_MASK_V1 and
CGROUP_MASK_V2 definitions.
2018-10-26 18:43:34 +02:00
Lennart Poettering 4edd65e4cf cgroup-util: add mask definitions for sets of controllers supported by cgroupsv1 vs. cgroupsv2 2018-10-26 18:43:34 +02:00
Lennart Poettering 604028de60 cgroup-util: disable buffering for cg_enable_everywhere() when writing to cgroup attributes
Let's better be safe than sorry.
2018-10-26 18:43:34 +02:00
Lennart Poettering 38a90d45ad cgroup-util: don't expect cg_mask_from_string()'s return value to be initialized
Also, when we fail, don't clobber the return value.

This brings the call more in-line with our usual coding style, and
removes surprises.

None of the callers seemed to care about this behaviour.
2018-10-26 18:43:34 +02:00
Lennart Poettering 0887fa711c cgroup-util: debug log if /proc/self/ns/cgroup is not available for unexpected reasons 2018-10-26 18:43:34 +02:00
Lennart Poettering 0d76d772d1
Merge pull request #10536 from keszybz/serialize-fixes
Tests for the new serialization functions
2018-10-26 17:56:43 +02:00
Lennart Poettering cb9e44db36 test: add test case for recursive chown()ing 2018-10-26 15:13:26 +02:00
Lennart Poettering cd6b7d50c3 chown-recursive: TAKE_FD() is your friend 2018-10-26 15:13:26 +02:00
Lennart Poettering f89bc84f32 chown-recursive: also drop ACLs when recursively chown()ing
Let's better be safe than sorry and also drop ACLs.
2018-10-26 15:13:26 +02:00
Lennart Poettering 5de6cce58b chown-recursive: let's rework the recursive logic to use O_PATH
That way we can pin a specific inode and analyze it and manipulate it
without it being swapped out beneath our hands.

Fixes a vulnerability originally found by Jann Horn from Google.

CVE-2018-15687
LP: #1796692
https://bugzilla.redhat.com/show_bug.cgi?id=1639076
2018-10-26 15:13:26 +02:00
Lennart Poettering 56abe1d107
Merge pull request #10508 from poettering/watchdog-original-fix
various service watchdog fixes
2018-10-26 14:50:17 +02:00
Lennart Poettering 0ea63f7a7d
Merge pull request #10534 from poettering/cmdline-fixlets
proc-cmdline.c fixlets
2018-10-26 14:49:53 +02:00
Zbigniew Jędrzejewski-Szmek 1c1d719aec Move tests for *serialize_environment into test-serialize.c
The implementation is in serialize.c.
2018-10-26 13:17:49 +02:00
Zbigniew Jędrzejewski-Szmek fa2951def7 test-serialize: allocate long_string dynamically 2018-10-26 13:17:44 +02:00
Lennart Poettering aa8c4bbf6a service: when starting a service make a copy of the watchdog timeout and use that
When we start a service process we pass the selected watchdog timeout to
it with the $WATCHDOG_USEC environment variable. If the unit file is
reconfigured later, we need to make sure to continue to honour the
original timeout, i.e. watch $WATCHDOG_USEC was set to, otherwise we'll
expect the ping at a different time as the service process is sending it
to us.

Hence, whenever we start a unit, save the watchdog timeout, and stick to
that for everything we do.

Fixes: #9467
2018-10-26 13:00:04 +02:00
Lennart Poettering 34b3f625f2 service: continue to use the overriden timeout when forking off again
Let's make sure we always use the right watchdog timeout: when a service
has overwritten it, then stick to it, also for follow-up processes of
the same service.
2018-10-26 13:00:04 +02:00
Lennart Poettering 95d0d8ed0a service: rename service_reset_watchdog_timeout() → service_override_watchdog_timeout()
This is what the function really does, hence name it that way.
2018-10-26 13:00:04 +02:00
Lennart Poettering ec35a7f6b0 service: rework service_extend_timeout()
Let's unify common code: let's extend the watchdog timeout and the
regular timeout with the same helper function.
2018-10-26 13:00:04 +02:00
Zbigniew Jędrzejewski-Szmek 40a4c4b38d test-serialize: a smoke test for the serialization functions 2018-10-26 12:56:53 +02:00
Zbigniew Jędrzejewski-Szmek 75e7d50e26 test: _cleanup_(unlink_tempfilep) in two more places 2018-10-26 12:56:53 +02:00
Zbigniew Jędrzejewski-Szmek d8351049a8 Introduce fmkostemp_safe and use it in tests
No functional change.
2018-10-26 12:56:51 +02:00
Lennart Poettering 9fb1cdb480 service: explicit stop the watchdog when we shall not use it
This is useful so that WATCHDOG_USEC=0 sent from a process does the
right thing if turning off the watchdog logic.
2018-10-26 12:53:17 +02:00
Lennart Poettering 2a1e0f2228 journalctl: in --follow mode watch stdout for POLLHUP/POLLERR and exit
Fixes: #9374
2018-10-26 12:28:38 +02:00
Lennart Poettering 7d95229ba7 proc-cmdline: teach proc_cmdline_get_key() the same flags magic as proc_cmdline_parse() 2018-10-26 12:03:32 +02:00
Lennart Poettering cb447ff5cc proc-cmdline: use FLAGS_SET() where appropriate
This was mostly prompted by seeing the expression "in_initrd() && flags
& PROC_CMDLINE_RD_STRICT", which uses & and && without any brackets.
Let's make that a bit more readable and hide all doubts about operator
precedence.
2018-10-26 12:00:37 +02:00
Lennart Poettering 9de12b2ef4 proc-cmdline: use our usual syntax for denoting bit mask enums 2018-10-26 12:00:01 +02:00
Lennart Poettering 923db66a16 fileio: drop FOREACH_LINE(), it's not used anymore 2018-10-26 10:52:41 +02:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00
Lennart Poettering cdd620e346 core: make manager_serialize() a bit easier to read by adding predicate function
The predicate function manager_timestamp_shall_serialize() simply says
whether to serialize or not serialize a timestamp, and should make
things a bit easier to read.
2018-10-26 10:40:01 +02:00
Lennart Poettering c475e57d67 core: strjoina() in a loop is never OK
Let's use plain strjoin() instead.
2018-10-26 10:40:01 +02:00
Lennart Poettering a2a444440f automount: fix deserialization of dev_t
let's prefer "unsigned long" rather than "unsigned", in case there are
archs that have 32bit int, but 64bit dev_t.

(Also one cast was wrong anyway.)
2018-10-26 10:40:01 +02:00
Lennart Poettering 3eac1bcae9 core: enforce a limit on STATUS= texts recvd from services
Let's better be safe than sorry, and put a limit on what we receive.
2018-10-26 10:40:01 +02:00
Lennart Poettering 8948b3415d core: when deserializing state always use read_line(…, LONG_LINE_MAX, …)
This should be much better than fgets(), as we can read substantially
longer lines and overly long lines result in proper errors.

Fixes a vulnerability discovered by Jann Horn at Google.

CVE-2018-15686
LP: #1796402
https://bugzilla.redhat.com/show_bug.cgi?id=1639071
2018-10-26 10:40:01 +02:00
Zbigniew Jędrzejewski-Szmek 84ac98faa8
Merge pull request #10525 from poettering/journal-vaccum-all
journald: add ability to vacuum active files too
2018-10-26 10:36:25 +02:00
Zbigniew Jędrzejewski-Szmek f4478c98fa
Merge pull request #10522 from lnykryn/initrd_debug
Let's make systemd-debug-generator usable also in initrd
2018-10-26 10:08:39 +02:00
Yu Watanabe dcdc2f61b1
sd-device: fix wrong assertion (#10530) 2018-10-26 10:16:00 +09:00
Yu Watanabe bf1d6be5b8
Merge pull request #10523 from poettering/fd-get-path-optimize
fd_get_path() optimization
2018-10-26 09:34:07 +09:00
Lennart Poettering 1d445eda4e core: reword polkit request a bit (#10524)
"killing" is very UNIX terminology, and not really what this is about.
Let's be more correct and say "send a UNIX signal" for the operation.

Otherwise things are really weird if users call "journalctl --rotate"
from the command line, which internally asks systemd to send SIGUSR2 to
to journald: when german locale is selected this asks the user — roughly
transliterated — whether they want to "eliminate" journald, which is
definitely not the intended meaning.
2018-10-26 06:01:41 +09:00
Lennart Poettering 971b52c485 journal-file: structured initialization is your friend 2018-10-25 21:44:48 +02:00
Lennart Poettering a33687b792 journald: when we are asked to rotate all files, let's also look at closed files
Before this when asked for rotation we'd only rotate files we have open
anyway. However there might be a number of other files on disk that are
active (i.e. not archived yet) but not open. Let's take care of those
too, so that rotation is always comprehensive, and the user gets the
guarantee that afterthe rotation all stored data is in archived files.

Fixes: #1017
2018-10-25 21:44:48 +02:00
Lennart Poettering e5b2d45c1d journalctl: fix error number in error message 2018-10-25 21:44:48 +02:00
Lennart Poettering 8df64fd01d journalctl: add ability to vacuum and rotate in one step
journalctl --vacuum-*= only vacuums archived files. To archive all
active files the rotate operation is used. Let's add a new switch that
combines both, so that the user a single command to first move all
running journal files into archival and then vacuum them.

See: #1017
2018-10-25 21:44:48 +02:00
Lennart Poettering d03077759e journald: log about an OOM condition 2018-10-25 21:44:48 +02:00
Lennart Poettering e859154447 journald: debug log when we cannot read the machine ID 2018-10-25 21:44:48 +02:00
Lennart Poettering 6812765891 journal-file: refactor journal_file_open_reliably()
Let's split out the part that actually renames the file in case we can't
open it into a new function journal_file_dispose().

This way we can reuse the function in other cases where we want to open
a file but can't.
2018-10-25 21:43:09 +02:00
Lennart Poettering 7a4d21ad20 journal-file: refactor journal_file_rotate()
Let's split the function in three: the part where we archive the old
file into journal_file_archive(), and the part where we initiate the
deferred closing into journal_file_initiate_close().
journal_file_rotate() then simply becomes a wrapper around these two
calls, and the opening of the new journal file.

This useful so that we can archive journal files without having to open
new ones, i.e. to do only the archival part of the rotation, without the
rotation part.
2018-10-25 21:43:09 +02:00
Lennart Poettering f760d8a858 journal: refactor out loop that processes deferred closes into its own function 2018-10-25 21:43:09 +02:00
Lennart Poettering 180e7f4e62 journal: fix some type confusion in journal_directory_vacuum()
Let's store array sizes and indexes in size_t. And let's count numbers
of files in uint64_t (simply because that is the type of the input
parameter for this of the function)
2018-10-25 21:43:09 +02:00
Lennart Poettering ab41da087d journald: use structured initialization 2018-10-25 21:42:05 +02:00
Lennart Poettering 6761e0a2fd journald: use usec_sub_unsigned() where we can 2018-10-25 21:42:05 +02:00
Lennart Poettering f267719c38 fd-util: optimize fd_get_path() a bit
journald calls fd_get_path() a lot (it probably shouldn't, there's some
room for improvement there, but I'll leave that for another time), hence
it's worth optimizing the call a bit, in particular as it's easy.

Previously we'd open the dir /proc/self/fd/ first, before reading the
symlink inside it. This means the whole function requires three system
calls: open(), readlinkat(), close(). The reason for doing it this way
is to distinguish the case when we see ENOENT because /proc is not
mounted and the case when the fd doesn't exist.

With this change we'll directly go for the readlink(), and only if that
fails do an access() to see if /proc is mounted at all.

This optimizes the common case (where the fd is valid and /proc
mounted), in favour of the uncommon case (where the fd doesn#t exist or
/proc is not mounted).
2018-10-25 21:37:14 +02:00
Lennart Poettering 8e060ec225 fs-util: increase start buffer size in readlinkat_malloc()
I noticed while profiling journald that we invoke readlinkat() a ton on
open /proc/self/fd/<fd>, and that the returned paths are more often than
not longer than the 99 chars used before, when we look at archived
journal files. This means for these cases we generally need to execute
two rather than one syscalls.

Let's increase the buffer size a tiny bit, so that we reduce the number
of syscalls executed. This is really a low-hanging fruit of
optimization.
2018-10-25 21:37:14 +02:00
Lukas Nykryn a7dd6d04b0 debug-generator: introduce rd.* version of all options 2018-10-25 17:05:50 +02:00
Zbigniew Jędrzejewski-Szmek 05f339267e
Merge pull request #10378 from poettering/json-fuzz-fix
json: a comprehensive fix for oss-fuzz#10908
2018-10-25 16:25:39 +02:00
Lukas Nykryn ed58820d76 proc-cmdline: introduce PROC_CMDLINE_RD_STRICT
Our current set of flags allows an option to be either
use just in initrd or both in initrd and normal system.
This new flag is intended to be used in the case where
you want apply some settings just in initrd or just
in normal system.
2018-10-25 16:21:26 +02:00
Lennart Poettering 5ec1fca41e
Merge pull request #10518 from poettering/dhcp6-size-fixes
dhcp6 packet size calculation fixes
2018-10-25 13:29:42 +02:00
Zbigniew Jędrzejewski-Szmek 5b8b8056eb
Merge pull request #10504 from poettering/hibernate-fallback
s2h: when hibernate fails after coming back from suspend, go back to suspend
2018-10-25 12:54:47 +02:00
Martin Wilck e1e74614aa core: don't create Requires for workdir if "missing ok"
Don't add an implicit RequiresMountsFor depenency for the
WorkingDirectory of a unit if the "-" character was used to
indicate that "a missing working directory is not considered fatal"
(see systemd.exec(5)). Otherwise systemd might fail the unit
because of missing dependencies.
2018-10-25 11:35:59 +02:00
Lennart Poettering 20b55f8538 dhcp6: prefer offsetof() over sizeof() for structs with undefined sizes
This doesn't change anything in the generated source, but I think makes
semantically more sense, as these structures have undefined size, and we
only want to know the size up to the data field in these cases.
2018-10-25 11:23:19 +02:00
Lennart Poettering 4dac5eaba4 dhcp6: make sure we have enough space for the DHCP6 option header
Fixes a vulnerability originally discovered by Felix Wilhelm from
Google.

CVE-2018-15688
LP: #1795921
https://bugzilla.redhat.com/show_bug.cgi?id=1639067
2018-10-25 11:23:19 +02:00
Lennart Poettering 990668aa4c dhcp6: reduce whitespace a bit 2018-10-25 11:23:19 +02:00
Lennart Poettering 3c290c0316 dhcp6: split assert_return() to be more debuggable when hit 2018-10-25 11:23:19 +02:00
Lennart Poettering e0a18b74a3 dhcp6: constify things where we can 2018-10-25 11:23:19 +02:00
Yu Watanabe 4e412d2684
string-util: fix prototype of explicit_bzero_safe() (#10513)
Follow-up for 87f5446311.
2018-10-25 11:41:55 +09:00
Lennart Poettering def34f63fe time-util: change parse_sec_fix_0() to accept "0s" for infinity too (#10501)
This function is about compatibility, nothing else, hence we should make
it properly compatible.

Fixes: #9556
2018-10-25 05:21:28 +09:00
Lennart Poettering d776fd08a3
Merge pull request #10510 from poettering/uacess-brackets
coverity fixes
2018-10-24 22:18:33 +02:00
Lennart Poettering 87f5446311 string-util: introduce explicit_zero_safe()
The only real difference is that this wrapper can deal with NULL
pointer arguments, but only if the length is also zero.

CID 1396277
2018-10-24 21:00:15 +02:00
Lennart Poettering 7388cea30d udev: use right error variable to make level decision 2018-10-24 20:47:52 +02:00
Lennart Poettering dc4fedd8cb udev: fix bad if {}
CID 1396318
CID 1396319
2018-10-24 20:46:41 +02:00
Lennart Poettering 5f00dc4df6 test: skip various tests if namespacing is not available
Apparently on Debian LXC/AppArmor doesn't allow namespacing to container
payloads. Deal with it.

Fixes: #9700
2018-10-24 19:40:24 +02:00
Lennart Poettering a4bc3c1d25 tests: add helper call have_namespaces() to test whether Linux namespaces are available
A slighly sloppy test call for conditionalizing several tests.
2018-10-24 19:40:24 +02:00
Lennart Poettering 795919efdf tests: as per CODING_STYLE undefine basename() right after including libgen.h 2018-10-24 17:08:12 +02:00
Lennart Poettering eca27ebbc8 tests: alloc-util.h and fs-util.h are our own headers
Hence include them with "" rather than <>. Also including them twices is
a pretty bad idea too.
2018-10-24 17:08:12 +02:00
Lennart Poettering 2194547e3b execute: if we fail to do namespacing, explain why we refuse to continue in a debug message 2018-10-24 17:08:12 +02:00
Lennart Poettering f05e1ae666 sleep: when we can't hibernate on suspend-then-hibernate, fall back to suspend again
Let's make this a bit safer, and try hard to return to sleep, if we can
at all.

Fixes: #10212
2018-10-24 14:44:14 +02:00
Lennart Poettering 14250f0942 sleep: rework what we do if a suspend fails.
First of all, let's fix logging: let's simply log the same message as we
do on success, so that there's always the same pair of these messages
around, regardless if the suspend was successful or not. To distuingish
a successful suspend from a failed one, check the ERRNO= field of the
structured message.

In most ways a failed suspend cycle is not distuingishable from a
successful one that took no time, hence let's treat it this way, and
always pair the success message with a failure message.

This also changes a more important concept: the post-suspend callouts
are now called also called on failure, following the same logic: let's
always run them in pairs: for every pre callout a post callout has to
follow.
2018-10-24 13:07:53 +02:00
Lennart Poettering c695101f47 sleep: no need to check for resume_offset twice
The W_OK check already checks for existance hence let's remove the F_OK
check.
2018-10-24 12:57:37 +02:00
Lennart Poettering eabcf200f7 sleep: let's turn off the RTC alarm time ASAP
Let's be a tiny bit more careful here.

Also, let's rearrange things to simplify them a bit, and to not use "r"
outside of its immediate scope of validity.
2018-10-24 12:52:11 +02:00
Lennart Poettering d029a3a8ca sleep: round up when calculating RTC sleep time
Paranoia: this way we know that when we wake up all timers are
definitely equal or ahead of what we expect them to be.
2018-10-24 12:48:56 +02:00
Lennart Poettering 033cea5c9d sleep: move log message generation for rtc_read_time() into the function itself
The log messages were petty borked anyway, and generated at two separate
locations. Let's fix that.
2018-10-24 12:47:46 +02:00
Lennart Poettering f780e438fa sleep: rework write_wakealarm() to take a numeric parameter
Also, let's rename it to rtc_write_wake_alarm(). Both changes together
make sure rtc_write_wake_alarm() and rtc_read_time() are more alike in
their naming and semantics.
2018-10-24 12:46:12 +02:00
Lennart Poettering c16669a309 sleep: rename read_wakealarm() → rtc_read_time()
It doesn't read wakealarm, but the current time of the RTC. Hence, let's
rename this to make it less misleading.
2018-10-24 12:44:20 +02:00
Lennart Poettering 6ce63245f6 sleep: log about the correct errors 2018-10-24 12:38:13 +02:00
Lennart Poettering 58220e6b91 sleep: don't make up errors, propagate the right ones 2018-10-24 12:38:04 +02:00
Lennart Poettering f00aff0a02 sleep: let's use write_string_file() instead of write_string_stream() if we can
Let's shorten things.
2018-10-24 12:35:49 +02:00
Lennart Poettering d1db1c438f
Merge pull request #10484 from yuwata/udev-spawn-simplify
udev-event: cleanups about udev_event_spawn()
2018-10-24 10:57:45 +02:00
Lennart Poettering e7b48c45ae
Merge pull request #10498 from yuwata/udev-builtin-log
udev-builtin: use log_device_*() macros
2018-10-24 10:53:35 +02:00
Lennart Poettering 77d28bd10f
Merge pull request #10483 from yuwata/udev-cleanup-10
tree-wide: use log_device_*()
2018-10-24 10:51:53 +02:00
Lennart Poettering 086712f99f
Merge pull request #10461 from yuwata/small-cleanups
Fixes recent defects reported by coverity
2018-10-24 10:36:20 +02:00
Jiuyang liu a2f577fca0 add ephemeral to nspawn-settings. 2018-10-24 10:22:20 +02:00