]> git.ipfire.org Git - thirdparty/systemd.git/log
thirdparty/systemd.git
2 years agosd-journal: split out generic_array_bisect_one() from generic_array_bisect() 27553/head
Yu Watanabe [Sat, 6 May 2023 15:19:24 +0000 (00:19 +0900)] 
sd-journal: split out generic_array_bisect_one() from generic_array_bisect()

This also makes journal corruption always handled gracefully, and drop
potentially unsatisfied assertion on corrupted journal.

Fixes #27533.

2 years agosd-journal: re-read entry array object
Yu Watanabe [Sat, 6 May 2023 15:16:30 +0000 (00:16 +0900)] 
sd-journal: re-read entry array object

`test_object()` may call `journal_file_move_to_object()` and thus
the `array` object may be invalidated.

2 years agosd-journal: drop unnecessary initialization
Yu Watanabe [Sat, 6 May 2023 15:15:49 +0000 (00:15 +0900)] 
sd-journal: drop unnecessary initialization

2 years agosd-journal: rebreak comments
Yu Watanabe [Sat, 6 May 2023 15:23:44 +0000 (00:23 +0900)] 
sd-journal: rebreak comments

2 years agosd-journal: fix comment
Yu Watanabe [Sat, 6 May 2023 15:15:28 +0000 (00:15 +0900)] 
sd-journal: fix comment

2 years agoMerge pull request #27262 from keszybz/ukify-install
Zbigniew Jędrzejewski-Szmek [Sat, 6 May 2023 11:34:08 +0000 (13:34 +0200)] 
Merge pull request #27262 from keszybz/ukify-install

Add kernel-install plugin that calls ukify

2 years agohwdb: do not include '#' in modalias
Yu Watanabe [Sat, 6 May 2023 05:36:19 +0000 (14:36 +0900)] 
hwdb: do not include '#' in modalias

Follow-up for 7bd3d6e35a6de8b1bf93e2fae28a64f0c7ffd2ac.
Fixes #27516.

2 years agoMerge pull request #27527 from mrc0mmand/fuzz-manager-serialize
Luca Boccassi [Sat, 6 May 2023 00:53:26 +0000 (01:53 +0100)] 
Merge pull request #27527 from mrc0mmand/fuzz-manager-serialize

core: a couple of follow-ups for issues found by fuzz-manager-serialize

2 years agozsh: remove usage of PREFIX in _systemctl
Ronan Pigott [Fri, 5 May 2023 19:33:29 +0000 (12:33 -0700)] 
zsh: remove usage of PREFIX in _systemctl

The usage of PREFIX in this completion is mostly counter to the intended
usage of compsys in zsh. It is generally expected that completion code
provide the available completions and tags in that word position so that
compsys, with user configuration, can filter them to the appropriate set.

One egregious error caused by the usage of PREFIX here is the caching of
SYS_ALL_UNITS, which stored only the unit names prematurely filtered by
the completion prefix, affecting all future completions. For example,

  $ systemctl cat nonsense<TAB>

might find no matching units if nonsense* has no matches, but now

  $ systemctl cat <TAB>

will fail in all future completions even though every unit file
is a valid match, because the cached set has been erroneously filtered
by the last prefix.

2 years agotest: add a test case for #27521 27527/head
Frantisek Sumsal [Fri, 5 May 2023 20:07:12 +0000 (22:07 +0200)] 
test: add a test case for #27521

Which got resolved by e652663a04.

2 years agocore: check the unit type more thoroughly when deserializing
Frantisek Sumsal [Thu, 4 May 2023 14:56:28 +0000 (16:56 +0200)] 
core: check the unit type more thoroughly when deserializing

Resolves: #27523

2 years agoshared: refuse fd == INT_MAX
Frantisek Sumsal [Thu, 4 May 2023 14:45:36 +0000 (16:45 +0200)] 
shared: refuse fd == INT_MAX

Since we do `FD_TO_PTR(fd)` that expands to `INT_TO_PTR(fd) + 1` which
triggers an integer overflow.

Resolves: #27522

2 years agocore: use extract_first_word() instead of sscanf()
Frantisek Sumsal [Thu, 4 May 2023 14:25:25 +0000 (16:25 +0200)] 
core: use extract_first_word() instead of sscanf()

2 years agobasic/audit-util: make a test request before enabling use of audit
Nick Rosbrook [Tue, 2 May 2023 16:30:31 +0000 (12:30 -0400)] 
basic/audit-util: make a test request before enabling use of audit

If a container manager does not follow the guidance in
https://systemd.io/CONTAINER_INTERFACE/ regarding audit capabilities,
then the current check may not be sufficient to determine that audit
will function properly. In particular, when calling bind() on the audit
fd, we will get EPERM if running in a user-namespaced container.

Expand the check to make an AUDIT_GET_FEATURE request on the audit fd to
test if it is working. If this fails with ECONNREFUSED, we know it is
because the kernel does not support the use of audit outside of the
initial user namespace.

Note that the approach of this patch was suggested here:
https://github.com/systemd/systemd/pull/19443#issuecomment-829566659

Fixes: #6519
2 years agoMerge pull request #27536 from dtardon/checked-fd-parsing
Luca Boccassi [Fri, 5 May 2023 19:55:48 +0000 (20:55 +0100)] 
Merge pull request #27536 from dtardon/checked-fd-parsing

Always check parsed fds for validity

2 years agotest_ukify: add test for combining config and cmdline 27262/head
Zbigniew Jędrzejewski-Szmek [Thu, 4 May 2023 13:17:27 +0000 (15:17 +0200)] 
test_ukify: add test for combining config and cmdline

2 years agoman: describe all the changes to ukify
Zbigniew Jędrzejewski-Szmek [Mon, 24 Apr 2023 10:40:08 +0000 (12:40 +0200)] 
man: describe all the changes to ukify

As in mkosi(1), let's describe the config file and commandline options
together. This is nice for us, because we don't need to duplicate descriptions
and we're less likely to forget to update one place or the other. This is also
nice for users, because they can easily figure out what can be configured
where.

The options are now ordered by config file section.

--summary was not described before.

More examples are added.

2 years agoci: install pytest-flakes
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 11:17:32 +0000 (13:17 +0200)] 
ci: install pytest-flakes

Some web searches say that it's packaged for those distros and not the others…

v2:
- drop arch. https://aur.archlinux.org/packages/python-pytest-flakes exists,
  but installation fails in CI.

2 years agotest_ukify: rework how --flakes argument is appended
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 11:10:28 +0000 (13:10 +0200)] 
test_ukify: rework how --flakes argument is appended

The usual approach is to put 'addopts = --flakes' in setup.cfg. Unfortunately
this fails badly when pytest-flakes is not installed:
  ERROR: usage: test_ukify.py [options] [file_or_dir] [file_or_dir] [...]
  test_ukify.py: error: unrecognized arguments: --flakes

pytest-flakes is not packaged everywhere, and this test is not very important,
so let's just do it only if pytest-flakes is available. We now detect if
pytest-flakes is available and only add '--flakes' conditionally. This
unfortunately means that when invoked via 'pytest' or directly as
'src/ukify/test/test_ukify.py', '--flakes' will not be appended automatically.
But I don't see a nice way to achieve previous automatic behaviour.

(I first considered making 'setup.cfg' templated. But then it is created
in the build directory, but we would need it in the source directory for
pytest to load it automatically. So to load the file, we'd need to give an
argument to pytest anyway, so we don't gain anything with this more complex
approach.)

2 years agotest_ukify: propagate failure
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 09:20:11 +0000 (11:20 +0200)] 
test_ukify: propagate failure

Oops. This explains why the tests were "passing" in CI even
though a direct pytest invocation would fail.

2 years agoukify: appease mypy
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 16:43:50 +0000 (18:43 +0200)] 
ukify: appease mypy

Note to self: PEP 585 introduced using collection types as types,
and is available since 3.9. PEP 604 allows writing unions with "|",
but is only available since 3.10, so not yet here because we maintain
compat with 3.9.

2 years agoTODO: remove two entries
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:53:49 +0000 (18:53 +0200)] 
TODO: remove two entries

0ccfd3564b2532a4da6526a9e030362c4a142b77 implemented one of the items, and this
pull requests handles the other one.

2 years agotest/60-ukify: override stub location in tests
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:45:24 +0000 (18:45 +0200)] 
test/60-ukify: override stub location in tests

Without this, build would fail if the stub is not available in /usr/lib/.

2 years agotest-kernel-install: test 60-ukify.install and 90-uki-copy.install
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 16:11:39 +0000 (18:11 +0200)] 
test-kernel-install: test 60-ukify.install and 90-uki-copy.install

We install a kernel with layout=uki and uki_generator=ukify, and test
that a UKI gets installed in the expected place. The two plugins cooperate,
so it's easiest to test them together.

2 years ago60-ukify: kernel-install plugin that calls ukify to create a UKI
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 16:07:22 +0000 (18:07 +0200)] 
60-ukify: kernel-install plugin that calls ukify to create a UKI

60-ukify.install calls ukify with a config file, so singing and policies and
splash will be done through the ukify config file, without 60-ukify.install
knowing anything directly.

In meson.py, the variable for loaderentry.install.in is used just once, let's
drop it. (I guess this approach was copied from kernel_install_in, which is
used in another file.)

The general idea is based on cvlc12's #27119, but now in Python instead of
bash.

2 years agotest_ukify: add tests for the new functionality
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 14:06:53 +0000 (16:06 +0200)] 
test_ukify: add tests for the new functionality

2 years agoukify: PeError → PEError
Zbigniew Jędrzejewski-Szmek [Thu, 20 Apr 2023 18:23:18 +0000 (20:23 +0200)] 
ukify: PeError → PEError

We don't lowercase acronyms in systemd usually.
Remove unnused f'' prefix to avoid a pylint warning.

2 years agoukify: rework option parsing to support a config file
Zbigniew Jędrzejewski-Szmek [Thu, 20 Apr 2023 18:22:25 +0000 (20:22 +0200)] 
ukify: rework option parsing to support a config file

In some ways this is similar to mkosi: we have a argparse.ArgumentParser()
with a bunch of options, and a configparser.ConfigParser() with an
overlapping set of options. Many options are settable in both places, but
not all. In mkosi, we define this in three places (a dataclass, and a
function for argparse, and a function for configparser). Here, we have one
huge list of ConfigItem instances. Each instance specifies the full metadata
for both parsers. Argparse generates a --help string for all the options,
and we also append a config file sample to --help based on the ConfigItem
data:

$ python src/ukify/ukify.py --help|tail -n 25
config file:
  [UKI]
  Linux = LINUX
  Initrd = INITRD…
  Cmdline = TEXT|@PATH
  OSRelease = TEXT|@PATH
  DeviceTree = PATH
  Splash = BMP
  PCRPKey = KEY
  Uname = VERSION
  EFIArch = ia32|x64|arm|aa64|riscv64
  Stub = STUB
  PCRBanks = BANK…
  SigningEngine = ENGINE
  SecureBootPrivateKey = SB_KEY
  SecureBootCertificate = SB_CERT
  SignKernel = SIGN_KERNEL

  [PCRSignature:NAME]
  PCRPrivateKey = PATH
  PCRPublicKey = PATH
  Phases = PHASE-PATH…

While writing this I needed to check the argument parsing, so I added
a --summary switch. It just pretty-prints the resulting option dictionary:

$ python src/ukify/ukify.py /efi//3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/linux /efi//3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/initrd --pcr-private-key=PRIV.key --pcr-public-key=PUB.key --config=man/ukify-example.conf --summary
Host arch 'x86_64', EFI arch 'x64'
{'_groups': [0, 'initrd', 'system'],
 'cmdline': 'A1 B2 C3',
 'config': 'man/ukify-example.conf',
 'devicetree': None,
 'efi_arch': 'x64',
 'initrd': [PosixPath('initrd1'),
            PosixPath('initrd2'),
            PosixPath('initrd3'),
            PosixPath('/efi/3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/initrd')],
 'linux': PosixPath('/efi/3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/linux'),
 'measure': None,
 'os_release': PosixPath('/etc/os-release'),
 'output': 'linux.efi',
 'pcr_banks': ['sha1', 'sha384'],
 'pcr_private_keys': [PosixPath('PRIV.key'),
                      PosixPath('pcr-private-initrd-key.pem'),
                      PosixPath('pcr-private-system-key.pem')],
 'pcr_public_keys': [PosixPath('PUB.key'),
                     PosixPath('pcr-public-initrd-key.pem'),
                     PosixPath('pcr-public-system-key.pem')],
 'pcrpkey': None,
 'phase_path_groups': [None,
                       ['enter-initrd'],
                       ['enter-initrd:leave-initrd',
                        'enter-initrd:leave-initrd:sysinit',
                        'enter-initrd:leave-initrd:sysinit:ready']],
 'sb_cert': PosixPath('mkosi.secure-boot.crt'),
 'sb_key': PosixPath('mkosi.secure-boot.key'),
 'sections': [],
 'sign_kernel': None,
 'signing_engine': None,
 'splash': None,
 'stub': PosixPath('/usr/lib/systemd/boot/efi/linuxx64.efi.stub'),
 'summary': True,
 'tools': None,
 'uname': None}

With --summary, existence of input paths is not checked. I think we'll
want to show them, instead of throwing an error, but in red, similarly to
'bootctl list'.

This also fixes tests which were failing with e.g.
E       FileNotFoundError: [Errno 2] No such file or directory: '/ARG1'
=========================== short test summary info ============================
FAILED ../src/ukify/test/test_ukify.py::test_parse_args_minimal - FileNotFoun...
FAILED ../src/ukify/test/test_ukify.py::test_parse_args_many - FileNotFoundEr...
FAILED ../src/ukify/test/test_ukify.py::test_parse_sections - FileNotFoundErr...
=================== 3 failed, 10 passed, 3 skipped in 1.51s ====================

2 years agomain: improve log message 27536/head
David Tardon [Fri, 5 May 2023 12:17:21 +0000 (14:17 +0200)] 
main: improve log message

2 years agotpm2 PCRs: fix unchecked attempt to set PCR[24]
OMOJOLA [Thu, 4 May 2023 22:21:04 +0000 (22:21 +0000)] 
tpm2 PCRs: fix unchecked attempt to set PCR[24]

2 years agotree-wide: use parse_fd()
David Tardon [Fri, 5 May 2023 07:10:49 +0000 (09:10 +0200)] 
tree-wide: use parse_fd()

2 years agotest: add a test for parse_fd()
David Tardon [Fri, 5 May 2023 07:10:26 +0000 (09:10 +0200)] 
test: add a test for parse_fd()

2 years agofd-util: introduce parse_fd()
David Tardon [Fri, 5 May 2023 06:09:14 +0000 (08:09 +0200)] 
fd-util: introduce parse_fd()

It's a simple wrapper for safe_atoi() that returns error if the parsed
fd is < 0 .

2 years agomain: add missing return
David Tardon [Fri, 5 May 2023 06:46:51 +0000 (08:46 +0200)] 
main: add missing return

Follow-up-for: 2b5107e1625e0847179da0d35eb544192766886f

2 years agoman: small fixes to systemd.time Calendar Events
Christopher Gurnee [Thu, 4 May 2023 19:37:57 +0000 (15:37 -0400)] 
man: small fixes to systemd.time Calendar Events

2 years agoMerge pull request #27529 from DaanDeMeyer/kernel-top
Luca Boccassi [Thu, 4 May 2023 18:17:37 +0000 (19:17 +0100)] 
Merge pull request #27529 from DaanDeMeyer/kernel-top

mkosi: A few kernel build QOL improvements

2 years agomkosi: Disable a bunch of useless configs when building a kernel 27529/head
Daan De Meyer [Thu, 4 May 2023 17:05:12 +0000 (19:05 +0200)] 
mkosi: Disable a bunch of useless configs when building a kernel

Let's speed up the kernel build a bit by disabling some stuff we
don't use.

2 years agoMerge pull request #27525 from poettering/creds-empty-gone
Lennart Poettering [Thu, 4 May 2023 14:22:54 +0000 (16:22 +0200)] 
Merge pull request #27525 from poettering/creds-empty-gone

suppress per-service credentials dir when empty

2 years agomkosi: Look for mkosi.kernel/ in the top level directory
Daan De Meyer [Thu, 4 May 2023 13:45:42 +0000 (15:45 +0200)] 
mkosi: Look for mkosi.kernel/ in the top level directory

Let's make this slightly easier to use by looking for mkosi.kernel/
in the top level directory instead of in mkosi.presets/20-final/.

2 years agoexecute: remove credentials dir again when empty 27525/head
Lennart Poettering [Thu, 4 May 2023 10:06:10 +0000 (12:06 +0200)] 
execute: remove credentials dir again when empty

This is closely related to the previous commit: if the credentials dir
is empty and nothing mounted on it, let's remove it again.

This will in particular happen if we decided to not actually install the
mount we prepared for the credentials because it is empty. In that case
the mount point inode is already there, and with this we'll remove it.
Primary effect, users will see ENOENT rather than EACCESS when trying to
access it, which should be preferable, given we already handle that
nicely in our credential consumption code.

This should also be useful on systems where we lack any privs to create
mounts, and thus operate on a regular dir anyway.

2 years agoexecute: suppress credentials mount if empty
Lennart Poettering [Wed, 3 May 2023 20:45:05 +0000 (22:45 +0200)] 
execute: suppress credentials mount if empty

Let's avoid creating another mount in the system if it's empty anyway.

This is mostl a cosmetic thing in one (pretty common) special case: if
creds settings are used in a unit but no creds actually available to be
passed.

(While we are at it this also does one more minor optimization: it
adjusts the MS_RDONLY/MS_NOSUID/… flags of the source mount we are about
to MS_MOVE into the right place only if we actually really move it, and
if we instead unmount it again we won't bother with the flags either)

2 years agorun: change sd_bus_call_method to bus_call_method (#27518)
Arthur Shau [Thu, 4 May 2023 01:41:10 +0000 (18:41 -0700)] 
run: change sd_bus_call_method to bus_call_method (#27518)

Migrates the sd_bus_call_method code in run.c to use bus-locator.h api

2 years agoMerge pull request #27513 from mrc0mmand/journal-tests
Mike Yuan [Thu, 4 May 2023 01:19:48 +0000 (09:19 +0800)] 
Merge pull request #27513 from mrc0mmand/journal-tests

test: a couple more TEST-04-JOURNAL follow-ups

2 years agocore: fix use of uninitialized value
Yu Watanabe [Wed, 3 May 2023 20:13:07 +0000 (05:13 +0900)] 
core: fix use of uninitialized value

Fixes https://github.com/systemd/systemd/pull/27504#issuecomment-1533354787.

2 years agocryptsetup: downgrade a bunch of log messages that to LOG_WARNING
Lennart Poettering [Tue, 2 May 2023 09:14:20 +0000 (11:14 +0200)] 
cryptsetup: downgrade a bunch of log messages that to LOG_WARNING

In all these cases we ignore the failure, hence per our rule the log
level should be below LOG_ERR. Fix that.

2 years agomount-util: simplify mount_switch_root() a bit
Lennart Poettering [Wed, 3 May 2023 15:17:35 +0000 (17:17 +0200)] 
mount-util: simplify mount_switch_root() a bit

There's no need to fchdir() out of the rootfs and back into it around
the umount2(), hence don't.

This brings the logic closer to what the pivot_root() man page suggests.

While we are at it, always operate based on fds, once we opened the
original dir, and pass the path string along only for generating
messages (i.e. as "decoration").

Add tests for both code paths: the pivot_root() one and the MS_MOUNT.

2 years agomkosi: Use kernel-kvmsmall package on opensuse
Daan De Meyer [Wed, 3 May 2023 13:27:10 +0000 (15:27 +0200)] 
mkosi: Use kernel-kvmsmall package on opensuse

Let's save on image size by using the kernel build for KVM from
opensuse.

2 years agoMerge pull request #27450 from poettering/switch-root-modernize
Lennart Poettering [Wed, 3 May 2023 18:12:20 +0000 (20:12 +0200)] 
Merge pull request #27450 from poettering/switch-root-modernize

pid1: modernize switch root logic a bit

2 years agotest: clean up the test script even further 27513/head
Frantisek Sumsal [Wed, 3 May 2023 16:24:17 +0000 (18:24 +0200)] 
test: clean up the test script even further

Most notably:
  - use `systemd-id128 new` instead of `journalctl --new-id128`
  - move all temporary files to /tmp
  - wrap repetitive checks in a function

2 years agocore: minor coding style modernization in mount.c
Lennart Poettering [Thu, 23 Mar 2023 22:16:21 +0000 (23:16 +0100)] 
core: minor coding style modernization in mount.c

2 years agosd-daemon: add sd_pid_notify_barrier() call and use it in systemd-notify
Lennart Poettering [Wed, 3 May 2023 12:13:58 +0000 (14:13 +0200)] 
sd-daemon: add sd_pid_notify_barrier() call and use it in systemd-notify

Previously we'd honour --pid= from the main notification we send, but
not from the barrier. This is confusing at best. Let's fix that.

2 years agoMerge pull request #27510 from poettering/notify-barrier-pid-1-tweaks
Lennart Poettering [Wed, 3 May 2023 16:21:14 +0000 (18:21 +0200)] 
Merge pull request #27510 from poettering/notify-barrier-pid-1-tweaks

pid 1 notify barrier handling tweaks

2 years agonotify: don't send EXIT_STATUS= notify message from systemd-notify
Lennart Poettering [Wed, 3 May 2023 12:14:06 +0000 (14:14 +0200)] 
notify: don't send EXIT_STATUS= notify message from systemd-notify

In 623a00020f116d8e9c70608a9e4f7cc978342441 code was added that our
various programs send a notification message with their exit status on
exit. This is great, but it becomes utterly confusing in systemd-notify,
whose primary purpose is to send such messages after all, and sending an
implicit one in addition to the primary one is particularly confusing,
when debugging things.

Let's hence just drop the implicit message. systemd-notify's exit status
is after all indicative primarily because sd_notify() failed, and hence
it's pretty pointless to then send that fact as another sd_notify()
message.

(Primary reason for this patch is simply that it confused the hell out
of me, when debugging sd_notify() issues)

Follow-up for: 623a00020f116d8e9c70608a9e4f7cc978342441

2 years agoupdate TODO 27450/head
Lennart Poettering [Fri, 28 Apr 2023 19:05:15 +0000 (21:05 +0200)] 
update TODO

2 years agobase-filesystem: unify common parts of base_filesystem_create_fd() branches
Lennart Poettering [Fri, 28 Apr 2023 18:47:10 +0000 (20:47 +0200)] 
base-filesystem: unify common parts of base_filesystem_create_fd() branches

The error handling and fchmodat() invocation is pretty much the same in
the directory and symlink branches, hence make them the same.

No real change in behaviour. Just refactoring.

2 years agobase-filesystem: add new helper base_filesystem_create_fd() that operates on an fd...
Lennart Poettering [Fri, 28 Apr 2023 16:33:17 +0000 (18:33 +0200)] 
base-filesystem: add new helper base_filesystem_create_fd() that operates on an fd, instead of a path

This also changes the open flags from
O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW to
O_DIRECTORY|O_CLOEXEC. O_RDONLY is redundant, since O_RDONLY is zero
anyway, and O_DIRECTORY pins the acces mode enough: it doesn't allow
read()/write() anyway when specified. O_NONBLOCK is also pointless given
that O_DIRECTORY is specified, it has no meaning on directories. (It is
useful if we don't know much about the inode we are opening, and could
be a device node or fifo, but the O_DIRECTORY excludes that case.)

O_NOFOLLOW is dropped since there's really no point in blocking out the
initial entrypoint being a symlink. Once we pinned the the root of the
tree it might make sense to restrict symlink use below it, but for the
entrypoint itself it doesn't matter.

2 years agoswitch-root: don't require /mnt/ when switching root into host OS
Lennart Poettering [Fri, 28 Apr 2023 16:35:31 +0000 (18:35 +0200)] 
switch-root: don't require /mnt/ when switching root into host OS

So far, we invoked pivot_root() specifying /mnt/ as second argument,
which then unmounted right-after. We'd create /mnt/ if needed. This
sucks, because it means /mnt/ must strictly be pre-created on immutable
images.

Remove this limitation, by using pivot_root() with "." as source and
target, which will result in two stacked mounts afterwards: the new one
underneath, the old one ontop. We can then simply unmount the top one,
and have what we want without needing any extra /mnt/ dir.

Since we don't need /mnt/ anymore we can get rid of the extra
unmount_old_root parameter and simply specify it as NULL if we don't
want the old mount to stick around.

2 years agotest: vacuum the journal after the "stress test"
Frantisek Sumsal [Wed, 3 May 2023 15:37:09 +0000 (17:37 +0200)] 
test: vacuum the journal after the "stress test"

To make the rest of the test significantly faster.

2 years agotest: slightly extend checks on corrupted journals
Frantisek Sumsal [Wed, 3 May 2023 15:32:36 +0000 (17:32 +0200)] 
test: slightly extend checks on corrupted journals

2 years agotest: further extend our collection of corrupted journals
Frantisek Sumsal [Wed, 3 May 2023 09:06:01 +0000 (11:06 +0200)] 
test: further extend our collection of corrupted journals

And make adding them slightly easier.

Provides coverage for b5335da7a5.

2 years agomanager: add debug logging about BARRIER=1 messages 27510/head
Lennart Poettering [Wed, 3 May 2023 12:12:43 +0000 (14:12 +0200)] 
manager: add debug logging about BARRIER=1 messages

2 years agomanager: simplify manager_process_barrier_fd() a bit
Lennart Poettering [Wed, 3 May 2023 12:12:26 +0000 (14:12 +0200)] 
manager: simplify manager_process_barrier_fd() a bit

2 years agoMerge pull request #27504 from mrc0mmand/fuzz-manager-serialize
Yu Watanabe [Wed, 3 May 2023 12:45:26 +0000 (21:45 +0900)] 
Merge pull request #27504 from mrc0mmand/fuzz-manager-serialize

test: add a simple fuzzer for manager serialization

2 years agotest_ukify: fix two failing tests
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 06:32:09 +0000 (08:32 +0200)] 
test_ukify: fix two failing tests

Fixup for 22ad038ac6e4fe5e4a68555f0e70bd0a16fb5616 and
3fc5eed47091363247012454df458e1a3303bf12. It seems that the tests are
not executed properly in CI. Nevertheless, test-ukify appears in logs:

rpm-build:fedora-rawhide-x86_64:
 409/1191 systemd / test-ukify    OK   0.16s

This is strange.

2 years agotest_ukify: fix loop iteration
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 06:27:21 +0000 (08:27 +0200)] 
test_ukify: fix loop iteration

We'd try to access 'linux' or 'initrd' after failing to set it.

2 years agomeson: allow building .standalone on demand
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:19:48 +0000 (18:19 +0200)] 
meson: allow building .standalone on demand

We can always build the standalone version whenever we build the normal version
(the dependencies are the same). In most builds standalone binaries would be
disabled. But it is occasionally useful to have them for testing, so move the
conditional to install:, so the binaries can be build by giving the explicit
target name.

The default of 'build_by_default' for executable() is sadly true (since meson
0.38.0), so need to specify build_by_default: too.

Also add systemd-shutdown.standalone to public_programs for additional testing.

2 years agomeson: avoid building executables that won't be installed
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:10:58 +0000 (18:10 +0200)] 
meson: avoid building executables that won't be installed

When executable() or custom_target() has install: that is conditional as is
false (i.e. not install:true), it won't be built by default. (build_by_default:
defaults to install:). But if that program is added to public_programs, it will
be build by default because it is pulled in by the test, effectively defeating
the disablement.

While at it, make 'ukify' follow the same pattern as 'kernel-install'.
They will be used later together.

2 years agoukify: add missing header
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 15:58:52 +0000 (17:58 +0200)] 
ukify: add missing header

This file is installed, so it should have the long header.

2 years agoukify: use UPPERCASE for parameter names
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 15:53:18 +0000 (17:53 +0200)] 
ukify: use UPPERCASE for parameter names

We generally nowadays use UPPERCASE for parameters in variuos help text.
Let's be consistent here too, and also drop duplicated 'usage:':
$ ukify -h
usage: ukify [options…] LINUX INITRD…
       ukify -h | --help

Build and sign Unified Kernel Images

positional arguments:
  LINUX                 vmlinuz file [.linux section]
  INITRD…               initrd files [.initrd section]
...

2 years ago90-loaderentry: make sure that variables are set
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 15:50:07 +0000 (17:50 +0200)] 
90-loaderentry: make sure that variables are set

We unconditionally use the variables later on, so let's make sure
that they were passed as expected.

2 years agoshared: reject empty attachment path 27504/head
Frantisek Sumsal [Tue, 2 May 2023 20:37:17 +0000 (22:37 +0200)] 
shared: reject empty attachment path

2 years agoshared: ignore invalid valink socket fd when deserializing
Frantisek Sumsal [Tue, 2 May 2023 20:36:59 +0000 (22:36 +0200)] 
shared: ignore invalid valink socket fd when deserializing

2 years agocore: fix NULL pointer dereference during deserialization
Frantisek Sumsal [Tue, 2 May 2023 20:36:36 +0000 (22:36 +0200)] 
core: fix NULL pointer dereference during deserialization

2 years agotest: add a simple fuzzer for manager serialization
Frantisek Sumsal [Mon, 1 May 2023 20:41:52 +0000 (22:41 +0200)] 
test: add a simple fuzzer for manager serialization

2 years agoMerge pull request #27499 from yuwata/sd-journal-fix-loop
Yu Watanabe [Wed, 3 May 2023 04:30:47 +0000 (13:30 +0900)] 
Merge pull request #27499 from yuwata/sd-journal-fix-loop

sd-journal: check .next_entry_array_offset earlier

2 years agoRevert "sd-journal: introduce simple loop detection for entry array objects" 27499/head
Yu Watanabe [Tue, 2 May 2023 16:30:23 +0000 (01:30 +0900)] 
Revert "sd-journal: introduce simple loop detection for entry array objects"

This reverts commit a8fbcc0e3c033a43e511550052cace6b0dcf3df7.

The commit is not necessary, as the invalid entry array object is
filtered earlier by the previous commit.

2 years agosd-journal: check .next_entry_array_offset earlier
Yu Watanabe [Tue, 2 May 2023 16:29:08 +0000 (01:29 +0900)] 
sd-journal: check .next_entry_array_offset earlier

Then, if it is invalid, refuse to use the entry array object.

Follow-up for a8fbcc0e3c033a43e511550052cace6b0dcf3df7.
Fixes #27489.

2 years agoboot: Use correct memory type for allocations
Jan Janssen [Tue, 2 May 2023 17:41:58 +0000 (19:41 +0200)] 
boot: Use correct memory type for allocations

We were using the wrong memory type when allocating pool memory. This
does not seem to cause a problem on x86, but the kernel will fail to
boot at least on ARM in QEMU.

This is caused by mixing different allocation types which ended up
breaking the kernel or EDK2 during boot services exit. Commit
2f3c3b0bee5534f2338439f04b0aa517479f8b76 appears to fix this boot
failure because it was replacing the gnu-efi xpool_print with xasprintf
thereby unifying the allocation type.
But this same issue can also happen without this fix somehow when the
random-seed logic is in use.

Fixes: #27371
2 years agocore: check for SERVICE_RELOAD_NOTIFY in manager_dbus_is_running
msizanoen1 [Tue, 2 May 2023 09:59:07 +0000 (16:59 +0700)] 
core: check for SERVICE_RELOAD_NOTIFY in manager_dbus_is_running

This ensures that systemd won't erronously disconnect from the system
bus in case a bus recheck is triggered immediately after the bus service
emits `RELOADING=1`.

This fixes an issue where systemd-logind sometimes randomly stops
receiving `UnitRemoved` after a system update.

This also handles SERVICE_RELOAD_SIGNAL just in case somebody ever
creates a D-Bus broker implementation that uses `Type=notify-reload`.

2 years agojournal: handle EADDRNOTAVAIL in two more cases gracefully
Lennart Poettering [Tue, 2 May 2023 10:23:07 +0000 (12:23 +0200)] 
journal: handle EADDRNOTAVAIL in two more cases gracefully

Follow-up for #27488.

2 years agoMerge pull request #27493 from poettering/generate-sym-test-tweaks
Yu Watanabe [Tue, 2 May 2023 15:12:48 +0000 (00:12 +0900)] 
Merge pull request #27493 from poettering/generate-sym-test-tweaks

fixes/additions for generate-sym-test

2 years agoMerge pull request #27492 from poettering/base-filesystem-000
Mike Yuan [Tue, 2 May 2023 12:53:35 +0000 (20:53 +0800)] 
Merge pull request #27492 from poettering/base-filesystem-000

base-filesystem: create /proc, /sys, /dev mount points as 555

2 years agogenerators: skip private tmpfs if /tmp does not exist
Luca Boccassi [Sun, 30 Apr 2023 18:21:23 +0000 (19:21 +0100)] 
generators: skip private tmpfs if /tmp does not exist

When spawning generators within a sandbox we want a private /tmp, but it
might not exist, and on some systems we might be unable to create it
because users want a BTRFS subvolume instead.

Fixes https://github.com/systemd/systemd/issues/27436

2 years agotree-wide: Handle EADDRNOTAVAIL as journal corruption
Daan De Meyer [Tue, 2 May 2023 07:16:16 +0000 (09:16 +0200)] 
tree-wide: Handle EADDRNOTAVAIL as journal corruption

Journal corruption is not only indicated by EBADMSG but also by
EADDRNOTAVAIL so treat that as corruption in a few more cases.

2 years agomount-setup: use size_t when iterating through array indexes 27492/head
Lennart Poettering [Tue, 2 May 2023 10:03:32 +0000 (12:03 +0200)] 
mount-setup: use size_t when iterating through array indexes

2 years agobase-filesystem: create /proc, /sys, /dev mount points as 0555
Lennart Poettering [Tue, 2 May 2023 08:44:14 +0000 (10:44 +0200)] 
base-filesystem: create /proc, /sys, /dev mount points as 0555

These inodes are going to be overmounted anyway, hence let's create them
with access mode 555, so that they are as close to being immutable as
regular UNIX access modes allow them to be. In other words: this takes
the "w" mode away for root. This of course usually has little effect --
unless CAP_DAC_OVERRIDE is dropped. But at the very least it makes the
point clear that inodes should be considered immutable.

(I intended to make this 0000 originally, but that doesn't work, as many
tools – including our own – have fallback paths that when they see
ENOENT in /proc/ they can handle this gracefully. But changing the mode
to 000 would turn this to EACCES - something they usually have no
fallback path for)

2 years agogenerate-sym-test: only look in .c and .h files 27493/head
Lennart Poettering [Tue, 2 May 2023 09:22:22 +0000 (11:22 +0200)] 
generate-sym-test: only look in .c and .h files

Otherwise it might find backup files and such, which triggered all kinds
of false positives (at least on my devel machine).

2 years agogenerate-sym-test: search for missing symbols
Lennart Poettering [Tue, 2 May 2023 09:21:23 +0000 (11:21 +0200)] 
generate-sym-test: search for missing symbols

This slightly extends the symbol file test and checks which symbols are
listed in one list but missing in the other. This is tremendously useful
to quickly determine which symbols wheren't exposed properly but should
have been.

(This is is implemented in pure C, no systemd helpers, to ensure we see
libsystemd.so API as any other tool would.)

2 years agodocs: add correct `pacman` command (#27486)
Klaus [Tue, 2 May 2023 09:18:10 +0000 (11:18 +0200)] 
docs: add correct `pacman` command (#27486)

The `pacman` command in order to install packages on Arch in the documentation is invalid.
This PR fixes the command.

2 years agotest: replace sleep with timeout
Yu Watanabe [Tue, 2 May 2023 06:15:30 +0000 (15:15 +0900)] 
test: replace sleep with timeout

If the test environment is too slow, then sleeping 2 seconds may not be
sufficient.

2 years agoMerge pull request #27455 from yuwata/test-lib-sym
Yu Watanabe [Mon, 1 May 2023 19:45:30 +0000 (04:45 +0900)] 
Merge pull request #27455 from yuwata/test-lib-sym

test: check all public functions are listed in .sym file

2 years agoMerge pull request #27442 from DaanDeMeyer/presets
Luca Boccassi [Mon, 1 May 2023 19:10:58 +0000 (20:10 +0100)] 
Merge pull request #27442 from DaanDeMeyer/presets

mkosi: Switch to use mkosi presets with prebuilt initrds

2 years agotest-network: add workaround for bug in iproute2 v6.2.0
Yu Watanabe [Mon, 1 May 2023 15:11:49 +0000 (00:11 +0900)] 
test-network: add workaround for bug in iproute2 v6.2.0

Closes #27473.

2 years agostub: Relocate kernels below 4G for EFI handover
Jan Janssen [Mon, 1 May 2023 09:32:30 +0000 (11:32 +0200)] 
stub: Relocate kernels below 4G for EFI handover

Old kernels can fail to boot when they are located above the 4G
boundary even if they claim to support it.

Fixes: #27472
2 years agoboot: Fix EFI_SIZE_TO_PAGES macro
Jan Janssen [Mon, 1 May 2023 09:31:52 +0000 (11:31 +0200)] 
boot: Fix EFI_SIZE_TO_PAGES macro

2 years agomkosi: Switch to use mkosi presets with prebuilt initrds 27442/head
Daan De Meyer [Tue, 25 Apr 2023 14:04:49 +0000 (16:04 +0200)] 
mkosi: Switch to use mkosi presets with prebuilt initrds

Instead of building the initrds for the mkosi images with dracut,
let's switch to using mkosi presets to build the initrd with mkosi
as well.

This commit splits up our single image build into three separate
mkosi presets:

1. The "base" preset. This image contains systemd and all its runtime
dependencies. The sole purpose of this image is to serve as a base image
for the initrd and the final image. It's also responsible for building
systemd from source with the build script. The results are installed into
the base image. Note that we install the systemd and udev packages into this
image as well to prevent package managers from overriding the systemd we built
from source with the distro packaged systemd if it's pulled in as a dependency
by another package from the initrd or final profiles.
2. The "initrd" preset. This image provides the initrd. It's trivial and does
nothing more than packaging the base image up as a zstd compressed initramfs and
adds /init and /etc/initrd-release symlinks to the image.
3. The "final" preset. This image builds on top of the base image and adds
a kernel and extra packages that are useful for testing and debugging.

We also split out the optional kernel build into a separate set of config files
that are only included if a kernel to build is actually provided.

Note that this commit doesn't really change anything about how mkosi is used.
The commands remain the same, except that mkosi will now build all the presets
in order. "mkosi summary" will show the summary of all the presets. "mkosi qemu,
boot, shell" will always boot the final preset. With "-f", all presets will be
built and the final one is booted. "-i" makes a cache of each preset.

The only thing to keep in mind is that specifying config via the mkosi CLI will
apply to each of the presets. e.g. any extra packages added with "-p" will be
installed in both the initrd and the final image. To apply local configuration
to a single preset, create a file 00-local.conf in
mkosi.presets/<profile>/mkosi.conf.d and put all the preset specific configuration
in there.

2 years agomeson: Search for find program
Daan De Meyer [Mon, 1 May 2023 08:25:18 +0000 (10:25 +0200)] 
meson: Search for find program

find is required by a few of the unit tests so let's make sure its
available when configuring the build.

2 years agomeson: Search for diff program
Daan De Meyer [Thu, 27 Apr 2023 14:37:39 +0000 (16:37 +0200)] 
meson: Search for diff program

diff is required by a few of the unit tests so let's make sure its
available when configuring the build.

2 years agoMerge pull request #27458 from mrc0mmand/test-corrupted-journals
Yu Watanabe [Mon, 1 May 2023 10:14:22 +0000 (19:14 +0900)] 
Merge pull request #27458 from mrc0mmand/test-corrupted-journals

test: test journalctl with corrupted journals

2 years agotest: test journalctl with corrupted journals 27458/head
Frantisek Sumsal [Sat, 29 Apr 2023 10:01:37 +0000 (12:01 +0200)] 
test: test journalctl with corrupted journals

Last month I monkey-patched journald to produce a small (64K) but valid
journal and used that as an input to four AFL fuzzers. After a month it
generated quite a nice corpora (4738 test cases) and after filtering
and minimizing it I was left with 619 unique journals with various
levels of corruption that probe the journal code.

It seems to detect past issues like systemd#26567, etc.