1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-11 20:58:27 +03:00

64949 Commits

Author SHA1 Message Date
Frantisek Sumsal
f32e44e467 sd-journal: use TAKE_PTR() a bit more 2023-05-24 13:55:39 +02:00
Frantisek Sumsal
ac874b8fb1 sd-journal: avoid double-free
If we fail to combine the new entry with a previous one, or update it in
the hashmap, we might later on attempt a double-free:

=================================================================
==10==ERROR: AddressSanitizer: attempting double-free on 0x611000039fc0 in thread T0:
SCARINESS: 42 (double-free)
    #0 0x4a0962 in __interceptor_free /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:52:3
    #1 0x7f55e431d9f2 in _hashmap_clear /work/build/../../src/systemd/src/basic/hashmap.c:927:33
    #2 0x7f55e431d4c8 in _hashmap_free /work/build/../../src/systemd/src/basic/hashmap.c:896:17
    #3 0x4de1de in ordered_hashmap_free_free_free /work/build/../../src/systemd/src/basic/hashmap.h:120:24
    #4 0x4de1de in ordered_hashmap_free_free_freep /work/build/../../src/systemd/src/basic/hashmap.h:434:1
    #5 0x4de1de in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-catalog.c:26:1
    #6 0x4de8b8 in NaloFuzzerTestOneInput (/build/fuzz-catalog+0x4de8b8)
    #7 0x4fd8c3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #8 0x4fd0aa in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #9 0x4fe779 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #10 0x4ff445 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #11 0x4ee7af in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #12 0x4ef078 in LLVMFuzzerRunDriver /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:925:10
    #13 0x4deb35 in main (/build/fuzz-catalog+0x4deb35)
    #14 0x7f55e3a32082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #15 0x41f7cd in _start (/build/fuzz-catalog+0x41f7cd)

DEDUP_TOKEN: __interceptor_free--_hashmap_clear--_hashmap_free
0x611000039fc0 is located 0 bytes inside of 224-byte region [0x611000039fc0,0x61100003a0a0)
freed by thread T0 here:
    #0 0x4a0962 in __interceptor_free /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:52:3
    #1 0x7f55e451493d in freep /work/build/../../src/systemd/src/basic/alloc-util.h:107:22
    #2 0x7f55e451493d in finish_item /work/build/../../src/systemd/src/libsystemd/sd-journal/catalog.c:187:1
    #3 0x7f55e4513e56 in catalog_import_file /work/build/../../src/systemd/src/libsystemd/sd-journal/catalog.c:313:45
    #4 0x4de1be in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-catalog.c:23:16
    #5 0x4de8b8 in NaloFuzzerTestOneInput (/build/fuzz-catalog+0x4de8b8)
    #6 0x4fd8c3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #7 0x4fd0aa in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #8 0x4fe779 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #9 0x4ff445 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #10 0x4ee7af in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #11 0x4ef078 in LLVMFuzzerRunDriver /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:925:10
    #12 0x4deb35 in main (/build/fuzz-catalog+0x4deb35)
    #13 0x7f55e3a32082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

DEDUP_TOKEN: __interceptor_free--freep--finish_item
previously allocated by thread T0 here:
    #0 0x4a0c06 in __interceptor_malloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
    #1 0x4de539 in malloc (/build/fuzz-catalog+0x4de539)
    #2 0x7f55e42bf96b in memdup /work/build/../../src/systemd/src/basic/alloc-util.c:16:15
    #3 0x7f55e451475d in finish_item /work/build/../../src/systemd/src/libsystemd/sd-journal/catalog.c:176:28
    #4 0x7f55e4513e56 in catalog_import_file /work/build/../../src/systemd/src/libsystemd/sd-journal/catalog.c:313:45
    #5 0x4de1be in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-catalog.c:23:16
    #6 0x4de8b8 in NaloFuzzerTestOneInput (/build/fuzz-catalog+0x4de8b8)
    #7 0x4fd8c3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #8 0x4fd0aa in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3
    #9 0x4fe779 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19
    #10 0x4ff445 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5
    #11 0x4ee7af in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #12 0x4ef078 in LLVMFuzzerRunDriver /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:925:10
    #13 0x4deb35 in main (/build/fuzz-catalog+0x4deb35)
    #14 0x7f55e3a32082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

DEDUP_TOKEN: __interceptor_malloc--malloc--memdup
SUMMARY: AddressSanitizer: double-free /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:52:3 in __interceptor_free

Found by Nallocfuzz.
2023-05-24 13:55:39 +02:00
Yu Watanabe
d689f70a2c test: add test case for systemd-update-utmp vs daemon-reexec 2023-05-24 20:06:10 +09:00
Yu Watanabe
08bc702b12 test: drop a workaround
Follow-up for 61961e693d3ba71386068947d85078c086e455e4.
2023-05-24 20:06:10 +09:00
Yu Watanabe
fcb2343175 update-utmp: reconnect after sleep when PID1 is reexecuting
Fixes #27167.
2023-05-24 20:06:10 +09:00
Yu Watanabe
87ae54533c update-utmp: update log message 2023-05-24 20:06:10 +09:00
Yu Watanabe
86da32ee0c update-utmp: downgrade log level of ignored failure 2023-05-24 20:06:10 +09:00
Yu Watanabe
4c40ab203c update-utmp: swap q <-> r
We usually use 'r' for general purpose.

No functional change, just refactoring.
2023-05-24 20:06:10 +09:00
Yu Watanabe
3950d8f693 update-utmp: modernize get_startup_monotonic_time()
This also downgrade error level, as the failure will be ignored.

No functional change, just refactoring.
2023-05-24 20:06:07 +09:00
Yu Watanabe
309491e4cf update-utmp: rebreak comments 2023-05-24 20:04:33 +09:00
Yu Watanabe
230f663e3e update-utmp: use verbs
No functional change, just refactoring.
2023-05-24 20:04:33 +09:00
Yu Watanabe
5f1f05b961
Merge pull request #27740 from dtardon/list-sessions-idle
Show idle status in `loginctl list-sessions`
2023-05-24 20:03:39 +09:00
Yu Watanabe
8ddc5f7699
Merge pull request #27757 from dtardon/bus-locator
Convert more DBus calls to BusLocator
2023-05-24 20:02:57 +09:00
Luca Boccassi
c67d5a027d ukify: add default .sbat section for addons
In order to ensure addons can always be revoked via SBAT, and it is not
left out by mistake, have a default metadata entry if none is specified
by the caller.
https://github.com/rhboot/shim/blob/main/SBAT.md
2023-05-24 11:09:03 +01:00
Luca Boccassi
f644ea3ed7 ukify: use empty stub for addons
Instead of picking up sd-stub, which is runnable, add an empty
addon stub that just returns an error if executed
2023-05-24 11:09:03 +01:00
Luca Boccassi
e78fc81d30 elf2efi: ensure minimum gap between .text and other sections
When linking an almost empty binary the linker can merged .text with
a later section, creating a RWE segment, that then it rejects.
2023-05-24 11:06:36 +01:00
Luca Boccassi
e18e3c4305 elf2efi: add parameter to increase reserved space for headers
When building a minimal empty addon it would not have enough
space to append sections. Add an option that will later be
used to reserve enough space.
2023-05-24 11:06:36 +01:00
Luca Boccassi
b6f2e68602 stub/measure: document and measure .uname UKI section 2023-05-24 11:06:36 +01:00
Daan De Meyer
e21f75afcd timer: Use dual_timestamp_is_set() in one more place 2023-05-24 11:41:37 +02:00
Luca Boccassi
e1f1b5fc62 efi: set EFIVAR to stop Shim from uninstalling its protocol
We'll use it from the stub to validate files. Requires Shim 5.18.
By default, Shim uninstalls its protocol when calling StartImage(),
so when loading systemd-boot via shim and then loading an UKI, the
UKI's sd-stub will no longer be able to use the shim verification
protocol by default.
2023-05-24 10:26:41 +01:00
Luca Boccassi
fe830b84d4
Merge pull request #27761 from yuwata/network-vlan-qos-mapping
network: fix vlan qos mapping
2023-05-24 09:59:41 +01:00
Lennart Poettering
00078fb309 execute: add missing NULL handling 2023-05-24 10:57:16 +02:00
Lennart Poettering
1483892a42 mount: check right before invoking /bin/umount if it makes sense
Notifications from /proc/self/mountinfo are async, so if we stop a
service (and while doing so get rid of the credentials mount point of
it), then it will take a while until the notification reaches us and we
actually scan the table again. In particular as we nowadays ratelimit
notifications on the table, since it's so inefficient. And as I learnt
the ratelimiting is actually quite regularly hit during shutdown, where
a flurry of umount events are genreated. Hence, let's check if a mount
point is actually a mountpoint before trying to unmount it. And if it
isn't let's wait for the notification to come in.

(This race might be triggred not just by us on ourselves btw: there are
other daemons that unmount stuff when stopping where the race also
exists, but might simply be harder to trigger: if during service
shutdown these services remove some mount then they might collide with
us doing the same. After all, we have the rule to unmount everything
mounted automatically for you during shutdown.)

In the long run we should also start making us of this when it becomes
available: https://github.com/util-linux/util-linux/issues/2132 With
that we can make issues like this go away entirely from our side of
things at least.

Fixes: #25527
2023-05-24 10:57:16 +02:00
Lennart Poettering
2fdc274c66 sd-event: add an explicit API for leaving the ratelimit state
Sometimes, it might make sense to end the ratelimit window early.
2023-05-24 10:52:08 +02:00
Lennart Poettering
75b0952982 core: split out default network dep generation into own function
Just some simple refactoring: let's split out network dep generation
into its own function mount_add_default_network_dependencies().

This way mount_add_default_dependencies() only does preparatory stuff,
and then calls both mount_add_default_network_dependencies() and
mount_add_default_ordering_dependencies() with that, making things
nicely symmetric.
2023-05-24 10:20:36 +02:00
Lennart Poettering
92e64e9ae9 core: suppress various defaults deps for credentials mounts
The per-unit credentials mounts might show up for any kind of service,
including very very early ones. Hence let's not order them after
local-fs-pre.target, because otherwise we might trigger cyclic deps of
services that want to plug before that but still use credentials.
2023-05-24 10:18:14 +02:00
Lennart Poettering
ce18c39623 unit: add ordering dep relative to credentials dir
See: #25527
2023-05-24 10:17:31 +02:00
Daan De Meyer
6546045fa0 core/timer: Always use inactive_exit_timestamp if it is set
If we're doing a daemon-reload, we'll be going from TIMER_DEAD => TIMER_WAITING,
so we won't use inactive_exit_timestamp because TIMER_DEAD != UNIT_ACTIVE, even
though inactive_exit_timestamp is serialized/deserialized and will be valid after
the daemon-reload.

This issue can lead to timers never firing as we'll always calculate the next
elapse based on the current realtime on daemon-reload, so if daemon-reload happens
often enough, the elapse interval will be moved into the future every time, which
means the timer will never trigger.

To fix the issue, let's always use inactive_exit_timestamp if it is set, and only
fall back to the current realtime if it is not set.
2023-05-24 10:05:08 +02:00
David Tardon
556723e738 loginctl: show session idle status in list-sessions 2023-05-24 10:04:45 +02:00
Yu Watanabe
5c4e96c28c test: rotate journal before storing coredumps
Hopefully fixes the failure like
https://jenkins-systemd.apps.ocp.cloud.ci.centos.org/job/upstream-vagrant-archlinux-sanitizers/2558/
---
[   66.708894] testsuite-74.sh[728]: + coredumpctl --json=off
[   66.709344] testsuite-74.sh[826]: TIME                        PID UID GID SIG     COREFILE EXE             SIZE
[   66.709773] testsuite-74.sh[826]: Tue 2023-05-23 22:10:17 UTC 739   0   0 SIGTRAP journal  /tmp/test-dump     -
[   66.711134] testsuite-74.sh[826]: Tue 2023-05-23 22:10:18 UTC 747   0   0 SIGABRT journal  /tmp/test-dump     -
[   66.711789] testsuite-74.sh[826]: Tue 2023-05-23 22:10:19 UTC 763   0   0 SIGTRAP present  /tmp/test-dump 53.5K
[   66.712460] testsuite-74.sh[826]: Tue 2023-05-23 22:10:20 UTC 776   0   0 SIGABRT present  /tmp/test-dump 53.3K
[   66.713505] testsuite-74.sh[728]: + coredumpctl --root=/
[   66.714144] testsuite-74.sh[828]: TIME                        PID UID GID SIG     COREFILE EXE             SIZE
[   66.714535] testsuite-74.sh[828]: Tue 2023-05-23 22:10:17 UTC 739   0   0 SIGTRAP journal  /tmp/test-dump     -
[   66.715208] testsuite-74.sh[828]: Tue 2023-05-23 22:10:18 UTC 747   0   0 SIGABRT journal  /tmp/test-dump     -
[   66.715907] testsuite-74.sh[828]: Tue 2023-05-23 22:10:19 UTC 763   0   0 SIGTRAP present  /tmp/test-dump 53.5K
[   66.716565] testsuite-74.sh[828]: Tue 2023-05-23 22:10:20 UTC 776   0   0 SIGABRT present  /tmp/test-dump 53.3K
[   66.717494] testsuite-74.sh[728]: + coredumpctl --directory=/var/log/journal
[   66.718188] testsuite-74.sh[830]: TIME                        PID UID GID SIG     COREFILE EXE             SIZE
[   66.882072] testsuite-74.sh[830]: Tue 2023-05-23 22:10:17 UTC 739   0   0 SIGTRAP journal  /tmp/test-dump     -
[   66.882642] testsuite-74.sh[830]: Tue 2023-05-23 22:10:18 UTC 747   0   0 SIGABRT journal  /tmp/test-dump     -
[   66.883450] testsuite-74.sh[830]: Tue 2023-05-23 22:10:19 UTC 763   0   0 SIGTRAP present  /tmp/test-dump 53.5K
[   66.883944] testsuite-74.sh[830]: Tue 2023-05-23 22:10:20 UTC 776   0   0 SIGABRT present  /tmp/test-dump 53.3K
[   66.885448] testsuite-74.sh[728]: + coredumpctl --file=/var/log/journal/2e1ed84be19a4e22adfc99ad849be1f6/system.journal
[   66.885989] testsuite-74.sh[728]: + at_exit
[   66.894162] coredumpctl[833]: No coredumps found.
---
2023-05-24 09:22:13 +02:00
David Tardon
3ac26d0718 oomctl: convert a oom1.Manager call to BusLocator 2023-05-24 08:50:02 +02:00
David Tardon
86257d9fd8 bus-locator: sort the list 2023-05-24 08:50:02 +02:00
David Tardon
1925011748 bus-locator: declare bus locator for oom1 and timesync1 2023-05-24 08:50:02 +02:00
David Tardon
d14bd34f25 hostnamectl: convert more hostname1 calls to BusLocator 2023-05-24 08:33:22 +02:00
David Tardon
7f8a85e6d8 tree-wide: convert more resolve1.Manager calls to BusLocator 2023-05-24 08:33:22 +02:00
David Tardon
daecc5b95b journalctl: convert a machine1.Manager call to BusLocator 2023-05-24 08:33:22 +02:00
David Tardon
a29f13f296 sleep: convert a home1.Manager call to BusLocator 2023-05-24 08:33:22 +02:00
David Tardon
6ce68c7c51 login: use NULL to denote arg-less method call
"" and NULL are equivalent, but the latter is normally used.
2023-05-24 08:32:13 +02:00
David Tardon
d962e73796 tree-wide: convert more login1.Manager calls to BusLocator 2023-05-24 08:24:00 +02:00
David Tardon
b71471684a tree-wide: convert more system1.Manager calls to BusLocator 2023-05-24 08:23:59 +02:00
Yu Watanabe
73d24e45f8 test-network: add tests for vlan QoS mapping 2023-05-24 11:15:44 +09:00
Yu Watanabe
4194478af8 network/vlan: paranoia about type safety
No functional change, as the struct is defined as the following:
```
struct ifla_vlan_qos_mapping {
      __u32 from;
      __u32 to;
};
```
2023-05-24 11:06:43 +09:00
Yu Watanabe
4d13d175f8 network/vlan: drop unnecessary restriction for QoS mapping
Fixes #27460.
2023-05-24 11:02:39 +09:00
Yu Watanabe
5dc0c21b31 core/slice: shorten code a bit 2023-05-24 10:26:21 +09:00
Yu Watanabe
93ec924c41 test: add test cases for defining mount and swap units from kernel cmdline 2023-05-24 08:23:22 +09:00
Yu Watanabe
55365b0a23 fstab-generator: support defining mount units through kernel command line
Now, the following kernel command line options are supported:
  systemd.mount-extra=what:where:fstype:options
  systemd.swap-extra=what:options

Closes #27260.
2023-05-24 08:23:22 +09:00
Yu Watanabe
2646f18445 fstab-generator: fix error code propagation in run_generator()
Previously, some errors might be ignored.
2023-05-24 08:23:22 +09:00
Yu Watanabe
6742eca134 fstab-generator: refuse invalid mount point path in fstab earlier 2023-05-24 08:23:22 +09:00
Yu Watanabe
9445623363 fstab-generator: refuse to add swap earlier if disabled
No functional change, preparation for later commits.
2023-05-24 08:23:22 +09:00
Yu Watanabe
256604ccdd fstab-generator: call add_swap() earlier
As 'where' field will be ignored for swap entry.
2023-05-24 08:23:22 +09:00