Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe f562abe296 unit: drop ProtectClock=yes from systemd-udevd.service
This partially reverts cabc1c6d7a.

The setting ProtectClock= implies DeviceAllow=, which is not suitable
for udevd. Although we are slowly removing cgropsv1 support, but
DeviceAllow= with cgroupsv1 is necessarily racy, and reloading PID1
during the early boot process may cause issues like #24668.

Let's disable ProtectClock= for udevd. And, if necessary, let's
explicitly drop CAP_SYS_TIME and CAP_WAKE_ALARM (and possibly others)
by using CapabilityBoundingSet= later.

Fixes #24668.
2022-09-16 03:41:29 +09:00
Yu Watanabe 88ffd21014 test-date: do not fail even on ~50 years later
Fixes #16181.
2022-09-15 13:48:55 +01:00
Yu Watanabe a900274915 test-seccomp: support systems that sched_setscheduler() is already limited
Fixes #17078.
2022-09-15 13:47:17 +01:00
Yu Watanabe f539452505 Merge pull request #24671 from mrc0mmand/even-more-codeql
ci: enable a couple more possibly useful CodeQL queries
2022-09-15 06:22:36 +09:00
Yu Watanabe af3d387365 tree-wide: fix typo 2022-09-15 06:03:57 +09:00
Yu Watanabe 10f3f4ed01 pid1: introduce dbus properties WatchdogDevice and friends
Closes #24665.
2022-09-14 13:13:59 +01:00
Yu Watanabe 908eb7be58 Merge pull request #24669 from dtardon/nested-asserts
Use nested ASSERT_PTR
2022-09-14 20:27:07 +09:00
Yu Watanabe c9bc7a449c Merge pull request #24663 from mrc0mmand/codeql-follow-up
A couple of CodeQL tweaks and follow ups
2022-09-14 05:31:10 +09:00
Yu Watanabe d0b387b617 Merge pull request #24662 from mrc0mmand/test-exec-deserialization-tweaks
test: drop the use of `tempfile.mktemp()`
2022-09-14 05:29:00 +09:00
Yu Watanabe 6f2d367e49 Merge pull request #24272 from dtardon/asserts
Use ASSERT_PTR more
2022-09-13 21:08:10 +09:00
Yu Watanabe 63d18b6cd0 boot: fix missing initialization
Fixes CID#1497847.
2022-09-13 21:06:05 +09:00
Yu Watanabe e51bea3433 Merge pull request #24651 from yuwata/openssl-util
openssl-util: trivial cleanups
2022-09-13 21:05:42 +09:00
Yu Watanabe 35aefda35f creds-util: fix NULL pointer dereference
Fixes CID#1497840.
2022-09-13 21:05:16 +09:00
Yu Watanabe 2e64df07b8 openssl-util: use assert() if no side effect 2022-09-13 17:03:34 +09:00
Yu Watanabe d39929d96d openssl-util: drop meaningless assertion
As the type of 'msz' is int.

Fixes CID#1497842.
2022-09-13 17:03:18 +09:00
Yu Watanabe 6d64cb0625 Merge pull request #23087 from yuwata/udev-watch
udev: resolve race in saving inotify watch handle
2022-09-12 23:41:00 +09:00
Yu Watanabe 75a5a143bb Merge pull request #23043 from yuwata/udev-node-use-flock
udev-node: use flock() for symlink stack directory
2022-09-12 23:40:34 +09:00
Yu Watanabe ee27501225 test: add testcase for udev-watch 2022-09-12 01:36:06 +09:00
Yu Watanabe 3fb94c7062 sd-device: move device_new_from_watch_handle_at() to udev-watch.c
And drop unused watch handle related functions.
2022-09-12 01:36:06 +09:00
Yu Watanabe 790da548b0 udev: warn on udev_watch_{begin,end}() failure 2022-09-12 01:36:06 +09:00
Yu Watanabe 4443b1857b udev: drop unnecessary call of udev_watch_end()
As it is already called by udev_event_execute_rules().
2022-09-12 01:36:06 +09:00
Yu Watanabe 2369152394 udev: use rm_rf() to remove old watch directory 2022-09-12 01:36:02 +09:00
Yu Watanabe 691a596da1 udev-watch: remove symlink for saving inotify watch handle only when it is owned by the processing device
Before removing symlinks that stores watch handles, this makes udev
worker check if the symlink is owned by the processing device.
Then, we can avoid TOCTOU and drop the try-and-wait loop.

This partially reverts 2d3af41f0e.
2022-09-12 01:32:32 +09:00
Yu Watanabe cd66f972d1 udev: ignore IN_IGNORED inotify event earlier 2022-09-12 01:23:08 +09:00
Yu Watanabe ea8213dc47 udev: not necessary to return 1 from on_inotify() 2022-09-12 01:23:08 +09:00
Yu Watanabe 03f48fc7c3 Merge pull request #24637 from mrc0mmand/TEST-75-tweaks
test: make the resolved notifications check a bit more robust
2022-09-12 01:17:36 +09:00
Yu Watanabe 706c9a30ac test-29-portable: set timeout for 'portablectl reattach'
Then, the test can fail earlier than the timeout of the whole test
specified by $QEMU_TIMEOUT=.

This is useful when we try to run the test multiple times.

Workaround for issue #24147.
2022-09-10 08:00:44 +00:00
Yu Watanabe 9a18458834 Merge pull request #24618 from yuwata/udev-split-synthesizing
udev: shorten synthesize_change() a bit
2022-09-10 02:52:54 +09:00
Yu Watanabe 86f9b69a6a blockdev-util: split out blockdev_reread_partition_table()
No functional changes, just refactoring.
2022-09-10 01:19:41 +09:00
Yu Watanabe 9409174ee7 udevd: use partition enumerator at one more place
No functional changes, just refactoring.
2022-09-10 00:48:34 +09:00
Yu Watanabe e97589cf38 Merge pull request #24609 from yuwata/sd-device-enumerator-check-sysname
sd-device-enumerator: check sysname earlier
2022-09-09 23:32:15 +09:00
Yu Watanabe 9cce72ee5d Merge pull request #24611 from yuwata/loop-util-refactoring
loop-util: several cleanups
2022-09-09 23:31:19 +09:00
Yu Watanabe e0993236d3 blockdevi-util: also check sysname when enumerating partitions 2022-09-09 22:30:19 +09:00
Yu Watanabe 88b5080ea9 sd-device-enumerator: use _cleanup_free_ attribute for safety
No functional changes, just improve readability.

Suggested by https://github.com/systemd/systemd/pull/24601#discussion_r966883459.
2022-09-09 21:16:37 +09:00
Yu Watanabe 89ad604839 sd-device-enumerator: always ignore ENOENT from opendir()
But logs all errors.
2022-09-09 21:16:37 +09:00
Yu Watanabe 0f519b9c2e sd-device-enumerator: check sysname earlier 2022-09-09 21:16:32 +09:00
Yu Watanabe 761787fc88 Merge pull request #24557 from yuwata/repart
repart: fix partition size calculation
2022-09-09 09:32:07 +09:00
Yu Watanabe 3b19e16056 test-58-repart: add test case for issue #24553 2022-09-09 05:53:01 +09:00
Yu Watanabe 9ccceb9d2b repart: make existing partition can be also 'dropped'
Previously, when an existing partition cannot grow, then entire process
fails. This makes such an existing partion handled as an foreign
partition, i.e. it is not managed by us.
2022-09-09 05:52:57 +09:00
Yu Watanabe cdbcc33952 repart: check if existing partitions can grow
Fixes #24553.
2022-09-09 05:49:00 +09:00
Yu Watanabe 58b06ac1ab repart: split out free_area_{current,min}_end() from free_area_available_for_new_partitions()
No actual code changes, just preparation for later commits.
2022-09-09 05:49:00 +09:00
Yu Watanabe f39cf264a6 repart: reset assignments by previous context_allocate_partitions()
The function context_allocate_partitions() may be called multiple times.
If this is called multiple times, then dropped partitions may still
assigned to free area.
2022-09-09 05:48:56 +09:00
Yu Watanabe d7c46b5e1e repart: do not assign new size larger than acquired or the specified maximum
The acquired size may be larger than the requested maximum. So, let's
cap the value.

Note, at the final phase, the acquired size should be larger than the
requested minimum. Hence, the assertion about that is added.
2022-09-09 05:35:41 +09:00
Yu Watanabe bf99aed6e8 repart: set new size for foreign partitions at first
Otherwise, the new size may be larger than the acquired one.
2022-09-09 05:35:41 +09:00
Yu Watanabe 2a503ad2a9 repart: anyway run loop at the end even if the loop will be restarted later
The order of the partitions processed in each phase does not change
result for the first two phase (PHASE_OVERCHARGE and PHASE_UNDERCHARGE).
2022-09-09 05:35:41 +09:00
Yu Watanabe 0245e15afe repart: make scale_by_weight() always succeed 2022-09-09 05:35:40 +09:00
Yu Watanabe 19903a4335 repart: split out context_grow_partition_one()
No actual code changes, just refactoring.
2022-09-09 05:35:40 +09:00
Yu Watanabe a801bb0157 repart: introduce partition_{min,max}_padding()
No actual code changes, just refactoring.
2022-09-09 05:35:40 +09:00
Yu Watanabe b0fbf90b5a repart: ensure partition_max_size() >= partition_min_size() 2022-09-09 05:35:40 +09:00
Yu Watanabe 822d9b9adc repart: make partition_max_size() return UINT64_MAX if not specified
Previously, it did not return UINT64_MAX, but a huge value, as
`UINT64_MAX / grain_size * grain_size != UINT64_MAX`.

This also drops unnecessary conditions.
2022-09-09 05:35:40 +09:00
Yu Watanabe a80701e68f repart: constify partition_min_size() 2022-09-09 05:35:40 +09:00
Yu Watanabe f126038f83 repart: rename variables in config_parse_weight()
This is for Weight= or PaddingWeight=, not for Priority=.

No actual code changes, just refactoring.
2022-09-09 05:35:40 +09:00
Yu Watanabe 833106b876 loop-util: do not try to enumerate partitions twice 2022-09-09 05:16:41 +09:00
Yu Watanabe 53274fdb59 loop-util: always check if backing file is not attached yet
An image file without partition table may be attached.
2022-09-09 05:16:01 +09:00
Yu Watanabe da4fd28871 loop-util: open loopback block device in loop_configure()
And make it return LoopDevice object on success.
No functional changes, just refactoring.
2022-09-09 04:31:10 +09:00
Yu Watanabe bb273a5145 loop-util: save the flag about if LOOP_CONFIGURE ioctl works or not in loop_configure()
When LOOP_CONFIGURE fail, then it is not necessary to call it on any
later call of loop_configure(). Let's save the flag in a static variable
in the function.
2022-09-09 04:31:10 +09:00
Yu Watanabe 54ba7daf23 loop-util: split out several functions fron loop_configure() and loop_device_make_internal()
The two functions were quite long, and hard to understand its logic.
No functional change, just refactoring.
2022-09-09 04:31:10 +09:00
Yu Watanabe 539b6597b2 Merge pull request #24601 from yuwata/sd-device-enumerator-drop-recursion
sd-device-enumerator: do not recursively find child devices
2022-09-09 04:30:42 +09:00
Yu Watanabe 2d9c58d786 test: add test for sd_device_enumerator_add_match_parent() 2022-09-08 18:10:50 +09:00
Yu Watanabe 6c876f0c20 sd-device-enumerator: rewrite child enumeration without recursion 2022-09-08 18:10:50 +09:00
Yu Watanabe bae477676a sd-device-enumerator: do not fail when a directory vanishes on enumerate 2022-09-08 18:10:50 +09:00
Yu Watanabe cdffb95cce sd-device-enumerator: use test_matches() more 2022-09-08 18:10:50 +09:00
Yu Watanabe e21253d3d7 Merge pull request #24587 from yuwata/sd-device-monitor-running-user-ns
sd-device-monitor: relax sender uid check when running in user namespace
2022-09-08 14:27:21 +09:00
Yu Watanabe c0aa23cf1e sd-device-monitor: relax sender uid check when running in user namespace
If sd-device-monitor is running in a user namespace, the sender uid is
not zero. Let's relax the verification in that case.
2022-09-08 11:08:43 +09:00
Yu Watanabe a30d3c0134 uid-range: move to src/basic/
To make the functions defined in the files usable by libsystemd library.
2022-09-08 11:08:43 +09:00
Yu Watanabe 30633dbd32 Merge pull request #24571 from yuwata/dissect-loop-image-use-backing-file
dissect: save image path to LoopDevice and use it when dissect loop device
2022-09-07 23:45:29 +09:00
Yu Watanabe 0fb5036f4d dissect-image: drop unnecessary duplication of partition device node 2022-09-07 20:45:24 +09:00
Yu Watanabe 0b214aa0d0 dissect-image: reuse LoopDevice.node in dissect_image()
Currently, dissect_image() is only called through dissect_loop_device(),
and the LoopDevice object has device name. Hence, it is not necessary to
get device name in dissect_image().
2022-09-07 20:45:24 +09:00
Yu Watanabe bec0c37c9e dissect-image: drop currently unused arguments 2022-09-07 20:45:24 +09:00
Yu Watanabe 7726bd4b03 dissect-image: drop currently unused code
Currently, dissect_image() is called only through dissect_loop_device(),
and image_path is always specified. Let's drop it.
2022-09-07 20:45:24 +09:00
Yu Watanabe 64dd3a245f dissect-image: use loop backing file or device node as name of the image
Note, currently, for each call of dissect_loop_device_and_warn(), the
specified name is equivalent to the path passed to loop_device_make_by_path().
Hence, this should not change the current behavios.
2022-09-07 20:45:24 +09:00
Yu Watanabe 55a065cd30 gpt-auto: use LoopDevice object to manage whole block disk 2022-09-07 20:45:24 +09:00
Yu Watanabe 369de26fdf dissect-image: use backing_file stored in LoopDevice object to generate image name
Follow-up for e374439f4b (#24322).

This also simplify the logic of generating image name from image path.
2022-09-07 20:45:24 +09:00
Yu Watanabe e77cab8248 loop-util: save backing file of loopback block device
It will be used in later commits.
2022-09-07 20:45:24 +09:00
Yu Watanabe aa0295f1d9 loop-util: move device_has_block_children() to blockdev-util.c
As the function is not only for loopback block device.

No actual code changes, just refactoring.
2022-09-07 20:45:24 +09:00
Yu Watanabe af15ee0368 blockdev-util: check if provided sd_device is for a whole block device
And split out partition_generator_new(), to make it usable in other
functions.
2022-09-07 20:45:24 +09:00
Yu Watanabe 46c3a28845 blockdev-util: make block_device_remove_all_partitions() take sd_device object
Then, it is not necessary to recreate sd_device object when we already
have.
2022-09-07 20:45:20 +09:00
Yu Watanabe 10719a6ff8 loop-util: fix leak of file descriptor on failure 2022-09-07 07:52:32 +09:00
Yu Watanabe cc5bae6cc2 loop-util: store sd_device object for the loop device
It will be used in later commits.
2022-09-06 11:26:00 +09:00
Yu Watanabe 802e7f7234 Merge pull request #24520 from yuwata/udevadm-wait-listen-kernel-uevents
udevadm-wait: also listen kernel uevents
2022-09-06 08:33:27 +09:00
Yu Watanabe e063db12c3 udevadm-wait: shorten code a bit 2022-09-06 06:09:55 +09:00
Yu Watanabe f6bb2e5189 udevadm-wait: wait for two periodic timer triggered before exit 2022-09-06 06:09:55 +09:00
Yu Watanabe 9d7c7de9bd udevadm-wait: also listen kernel uevent stream if --initialized=no
Suggested at https://github.com/systemd/systemd/pull/24471#discussion_r959703103.
2022-09-06 06:09:42 +09:00
Yu Watanabe 6f2cea06bf Merge pull request #24467 from qdeslandes/nspawn_rootidmap
nspawn: add rootidmap as --bind option
2022-09-06 03:45:53 +09:00
Yu Watanabe 559bf6b351 Merge pull request #24568 from poettering/atou16-atou-rework
parse-util: simplify safe_atou8() + safe_atou16()
2022-09-06 03:38:41 +09:00
Yu Watanabe 0cf2dcf154 udev/rules,hwdb: filter out mostly meaningless default strings
The filter is generated based on the following results:
---
git clone git@github.com:linuxhw/DMI.git
cd DMI
git grep -h -A2 '^System Information$' | grep 'Manufacturer' | sort | uniq -c | sort -nr | less
git grep -h -A2 '^System Information$' | grep 'Product Name' | sort | uniq -c | sort -nr | less
---

Closes #24446.
2022-09-06 03:38:09 +09:00
Yu Watanabe e42270b6a6 loop-util: lock_fd must be closed before calling LOOP_CLR_FD
Follow-up for 7f52206a2b.

C.f. 87862cc2b4.
2022-09-05 04:31:47 +09:00
Yu Watanabe 9bf8600774 loop-util: drop unnecessary initializations 2022-09-05 04:31:29 +09:00
Yu Watanabe 1996ad2854 loop-util: use loop_device_open_full() when whole block device is passed to loop_device_make()
This also fixes a leak of lock_fd, which introduced by
7f52206a2b, when fd is for a block device,
and size or offset is non-zero.

Fixes another issue in #24147.
2022-09-05 03:50:05 +09:00
Yu Watanabe a8d8a61980 loop-util: introduce loop_device_open_full() 2022-09-05 03:29:06 +09:00
Yu Watanabe 9b5626d67a loop-util: fix LoopDevice.devno assigned by loop_device_open() 2022-09-05 03:29:06 +09:00
Yu Watanabe ffcb33241e loop-util: also set LoopDevice.diskseq when created with loop_device_open() 2022-09-05 03:29:06 +09:00
Yu Watanabe b6ca2b281e mount-util: fix error code
If multiple service is starting simultaneously with a shared image,
then one of the service may fail to create a mount node:

systemd[695]: Bind-mounting /usr/lib/os-release on /run/systemd/unit-root/run/host/os-release (MS_BIND|MS_REC "")...
systemd[696]: Bind-mounting /usr/lib/os-release on /run/systemd/unit-root/run/host/os-release (MS_BIND|MS_REC "")...
systemd[695]: Failed to mount /usr/lib/os-release (type n/a) on /run/systemd/unit-root/run/host/os-release (MS_BIND|MS_REC ""): No such file or directory
systemd[696]: Failed to mount /usr/lib/os-release (type n/a) on /run/systemd/unit-root/run/host/os-release (MS_BIND|MS_REC ""): No such file or directory
systemd[695]: Bind-mounting /usr/lib/os-release on /run/systemd/unit-root/run/host/os-release (MS_BIND|MS_REC "")...
systemd[696]: Failed to create destination mount point node '/run/systemd/unit-root/run/host/os-release': Operation not permitted
systemd[695]: Successfully mounted /usr/lib/os-release to /run/systemd/unit-root/run/host/os-release

The function apply_one_mount() in src/core/namespace.c gracefully
handles -EEXIST from make_mount_point_inode_from_path(), but it erroneously
returned -EPERM previously. This fixes the issue.

Fixes one of the issues in #24147, especially reported at
https://github.com/systemd/systemd/issues/24147#issuecomment-1236194671.
2022-09-05 03:28:47 +09:00
Yu Watanabe 7903fcbb7c Merge pull request #24550 from yuwata/bootspec
bootspec: do not build too many json object at once
2022-09-04 03:00:22 +09:00
Yu Watanabe b488c59c9f test: check returned values are always initialized on success 2022-09-04 00:02:38 +09:00
Yu Watanabe 28340719f2 bootspec: shorten code a bit 2022-09-04 00:01:09 +09:00
Yu Watanabe 69a34a4fd4 fuzz: add a test case for fuzz-bootspec
This adds a testcase for the issue oss-fuzz#50949
(https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50949).
2022-09-03 23:32:54 +09:00
Yu Watanabe 4d49d19e9d bootspec: do not build two many json object at once
This is a workaround for an issue in the memory sanitizer.
If a function is called with too many arguments, then the sanitizer
triggers the following false-positive warning:

==349==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7f8b247134a7 in json_buildv /work/build/../../src/systemd/src/shared/json.c:3213:17
    #1 0x7f8b24714231 in json_build /work/build/../../src/systemd/src/shared/json.c:4117:13
    #2 0x7f8b24487fa5 in show_boot_entries /work/build/../../src/systemd/src/shared/bootspec.c:1424:29
    #3 0x4a6a1b in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-bootspec.c:119:16
    #4 0x4c6693 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #5 0x4c5e7a 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
    #6 0x4c7ce4 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:826:7
    #7 0x4c7f19 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:857:3
    #8 0x4b757f in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6
    #9 0x4e0bd2 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #10 0x7f8b23ead082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #11 0x41f69d in _start (build-out/fuzz-bootspec+0x41f69d)

Follow-up for #24541.
Fixes #24551.
2022-09-03 23:32:50 +09:00
Yu Watanabe 41dceb91dd json: introduce json_append() 2022-09-03 23:13:47 +09:00
Yu Watanabe d12c0f4cfe loop-util: fix memleak when fd is for a block device with non-zero offset or size 2022-09-03 09:47:53 +09:00