1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00
Commit Graph

41081 Commits

Author SHA1 Message Date
Yu Watanabe
b40c8ebdc8 sd-id128: fold do_sync flag into Id128FormatFlag 2022-12-12 22:07:48 +09:00
Yu Watanabe
e2720340e9 sd-id128: make sd_id128_get_boot() and friend return -ENOSYS when /proc/ is not mounted 2022-12-12 22:04:53 +09:00
Yu Watanabe
9be90c401e sd-id128: make sd_id128_get_boot() and friend return -ENOMEDIUM 2022-12-12 22:04:53 +09:00
Yu Watanabe
66c7949e08 test: add tests for "uninitialized" string handling by id128_read_fd() 2022-12-12 21:57:31 +09:00
Yu Watanabe
057bf780e9 sd-id128: make id128_read() or friends return -ENOPKG when the file contents is "uninitialized"
Then, this drops ID128_PLAIN_OR_UNINIT. Also, this renames
Id128Format -> Id128FormatFlag, and make it bitfield.

Fixes #25634.
2022-12-12 21:57:31 +09:00
Yu Watanabe
28bf2de201 sd-id128: several cleanups
- use SD_ID128_STRING_MAX or friend,
- use sizeof(sd_id128_t),
- use newly introduced ascii_ishex().
2022-12-12 21:48:47 +09:00
Yu Watanabe
0ce8870f19 string-util: introduce ascii_ishex() 2022-12-12 21:47:22 +09:00
Zbigniew Jędrzejewski-Szmek
ae3506ab92 udev-builtin-keyboard: update description 2022-12-12 13:44:33 +01:00
Yu Watanabe
733529d812 test: name_assign_type sysattr never exists for enumerated devices
As we filtered out network devices in the test.
2022-12-12 15:04:39 +09:00
Yu Watanabe
eb18e7b782 sd-device: fix double-free
If an attribute is read but the value is not used (i.e. ret_value is NULL),
then sd_device_get_sysattr_value() mistakenly frees the read data even though
it is cached internally.

Fixes a bug introduced by acfc2a1d15.

Fixes #25702.
2022-12-12 14:20:47 +09:00
Peter Cai
2a469016e3 libfido2-util: Refactor pre-flight failure handling
`fido2_is_cred_in_specific_token()` should simply not return error codes
for non-fatal errors. For example, `-ENODEV` can be safely translated to
a `false` return value. When the pre-flight request is not supported, we
should simply return true to instruct the caller to attempt to use the
device anyway.

All error codes returned by the funtion should now be fatal and logged
at error level. Non-fatal errors should only appear in debug logs.
2022-12-10 15:28:49 -05:00
Peter Cai
5d2c1ce4e4 libfido2-util: Perform pre-flight checks as well when a specific device path is given
This prevents unnecessary user interactions when `fido2-device` is set to
something other than `auto` -- a case overlooked in the original PR #23577
(and later #25268).

We do not move pre-flight checks to `fido2_use_hmac_hash_specific_token`
because the behaviors are different between different cases: when the
device path is NULL, we try to automatically choose the correct device,
in which case pre-flight errors should be "soft" errors, without
spamming the tty with error outputs; but when a specific device path is
given, a pre-flight request that determined the non-existence of the
credential should be treated the same as a failed assertion request.
2022-12-10 15:28:49 -05:00
Peter Cai
53c1ef9ce0 libfido2-util: Disable pre-flight checks for credentials with UV
According to the FIDO2 spec, tokens may not support pre-flight checks
for credentials requiring UV, at least not without at least
`pinUvAuthParam` or `uv = true`. Originally, in #25268, this was
handled by passing a PIN to satisfy `pinUvAuthParams`, but this is not
ideal, since `pinUvAuthParam` can be obtained from either a PIN
or a UV verification. Forcing the user to enter the PIN here (which is
often just the fallback option on UV devices) is no better than just
trying out each device with the actual assertion request.

As a result, this commit disables pre-flight checks when the credential
requires UV, and instead reverts to the old behavior (trying out each
device and each key slot, requiring multiple user interactions) for this
type of credentials.
2022-12-10 15:28:49 -05:00
Lennart Poettering
09e917ea4d repart: support erofs
So, i think "erofs" is probably the better, more modern alternative to
"squashfs". Many of the benefits don't matter too much to us I guess,
but there's one thing that stands out: erofs has a UUID in the
superblock, squashfs has not. Having an UUID in the superblock matters
if the file systems are used in an overlayfs stack, as overlayfs uses
the UUIDs to robustly and persistently reference inodes on layers in
case of metadata copy-up.

Since we probably want to allow such uses in overlayfs as emplyoed by
sysext (and the future syscfg) we probably should ramp up our erofs game
early on. Hence let's natively support erofs, test it, and in fact
mention it in the docs before squashfs even.
2022-12-10 11:26:36 +01:00
jcg
5e5fce3e91 mount-setup: don't need to mount /sys/fs/pstore if there is no ENABLE_PSTORE 2022-12-10 12:02:25 +09:00
Yu Watanabe
068ef623bd resolve: add missing assertion 2022-12-10 10:32:29 +09:00
Yu Watanabe
14822ede9f resolve: shorten code a bit 2022-12-10 10:32:29 +09:00
Yu Watanabe
494ef16743 resolve: drop recursion in TXT field handling
Fixes #25683.
2022-12-10 10:32:09 +09:00
Zbigniew Jędrzejewski-Szmek
7aebbdcfa9
Merge pull request #25636 from thom311/th/wcast-align-fixes
all: avoid various "-Wcast-align=strict" warnings
2022-12-09 15:03:45 +01:00
Thomas Haller
6759b62720
all: avoid various "-Wcast-align=strict" warnings 2022-12-09 08:58:07 +01:00
Yu Watanabe
b9152f2d63 resolve: optimize conversion of TXT fields to json
Fixes oss-fuzz#54080 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54080).

Fixes #25654.
2022-12-09 04:59:49 +09:00
Yu Watanabe
7d34567444 hexdecoct: fix NULL pointer dereferences in hexmem()
Fixes oss-fuzz#54090 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54090).

Fixes #25655.
2022-12-09 04:55:47 +09:00
Yu Watanabe
45655e776f hexdecoct: add missing NULL check
Fixes oss-fuzz#54065 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54065).

Fixes #25650.
2022-12-09 04:54:43 +09:00
Yu Watanabe
6b0df52e58 test: add tests for base64_append() 2022-12-09 04:53:50 +09:00
Yu Watanabe
c21b316964 hexdecoct: several cleanups for base64_append()
- add missing assertions,
- use size_t for buffser size or memory index,
- handle empty input more gracefully,
- return the length or the result string,
- fix off-by-one issue when the prefix is already long enough.
2022-12-09 04:53:50 +09:00
Franck Bui
c8966e812e localed: reload PID1 configuration after modifying /etc/locale.conf
Since commit 1ad6e8b302, unsetting an environment
variable means restoring it to its default value.

However this doesn't work well when localed updates locale.conf. Indeed when a
variable is removed from that file, localed calls "UnsetAndSetEnvironment"
method which restores the default values of the unset variables obtained by
PID1 when it first read locale.conf. But since locale.conf has been updated,
these default values might be outdated and localed needs to instruct PID1 to
read locale.conf again.

Reloading PID1 configuration is quite an heavy operation for this purpose but
there's no other way unless we change again the meaning of "UnsetEnvironment"
or we introduce a new method that really unset an env variable.

That said given the fact that localed modifies locale.conf, it should have an
effect on PID1 default environment rather than on the environment explicitly
set by the user (m->client_manager).
2022-12-08 18:35:51 +01:00
Lennart Poettering
b6256af75e socket-util: add CMSG_TYPED_DATA() as type-safe wrapper around CMSG_DATA() 2022-12-08 17:48:34 +01:00
Thomas Haller
86bdf11714 fundamental: add CAST_ALIGN_PTR() macro 2022-12-08 17:34:20 +01:00
Lennart Poettering
d20ea2c515
Merge pull request #25662 from msizanoen1/s2h-nosuspend-user-proc
sleep: always thaw user.slice even if freezing failed
2022-12-08 17:24:52 +01:00
Lennart Poettering
93c1baa0c8
Merge pull request #25667 from poettering/sha256-align-fix
sha256 alignment fixes/rework
2022-12-08 17:24:17 +01:00
Lennart Poettering
39a72c13b8
Merge pull request #25665 from poettering/dissect-memory
dissect: add a mode for operating on an in-memory copy of a DDI, inst…
2022-12-08 17:23:15 +01:00
Yu Watanabe
340bc268c8 fs-util: make chmod_and_chown_at() work with empty path and AT_FDCWD
Follow-up for 7d000133c2.

Fixes CID#1500608.
2022-12-08 15:57:33 +01:00
Lennart Poettering
a0ccc18e89 sha256: port to new generic IS_ALIGNED32() macro
This drops the special casing for s390 and other archs, which was
cargo-culted from glibc. Given it's not obvious why it exists, and is at
best an optimization let's simply avoid it, in particular as the archs
are relatively non-mainstream.

Inspired by: #25636
2022-12-08 15:30:41 +01:00
Lennart Poettering
4f07388360 macro: add generic IS_ALIGNED32() anf friends
Let's generalize (and invert) the UNALIGNED32_P() macro from the sha256
code, and let's add a test for it.
2022-12-08 15:30:31 +01:00
Lennart Poettering
22e339761b sha256: move to unaligned_write_ne32() 2022-12-08 15:18:47 +01:00
Lennart Poettering
d8007e7aac fundamental: split out unaligned_{read|write}_ne{16,32,64}() helpers into unaligned-fundamental.h
Let's allow using this in code shared between userspace and EFI mode.

Also, don't implement these functions via endianness conversions given
we don't actually want to convert endianess here.
2022-12-08 15:18:47 +01:00
Lennart Poettering
17b296a118 sha256: external headers should be included with <> 2022-12-08 15:18:46 +01:00
Lennart Poettering
a579990277
Merge pull request #25180 from keszybz/ukify
ukify: add helper to create UKIs
2022-12-08 15:11:18 +01:00
msizanoen1
af1e336589 core: pending_freezer_{message => invocation}
Rename the field to reflect the new semantics.
2022-12-08 12:58:00 +01:00
msizanoen1
432a321175 core/sleep: set timeout for freeze/thaw operation to 1.5 seconds
A FreezeUnit operation can hang due to the presence of kernel threads
(see last 2 commits). Keeping the default configuration will mean the
system will hang for 25 seconds in suspend waiting for the response. 1.5
seconds should be sufficient for most cases.
2022-12-08 12:58:00 +01:00
msizanoen1
7fcd269784 core/cgroup: ignore kernel cgroup.events when thawing
The `frozen` state can be `0` while the processes are indeed frozen (see
last commit). Therefore do not respect cgroup.events when checking
whether thawing is necessary.
2022-12-08 12:58:00 +01:00
Lennart Poettering
6c07d57075 dissect: add a mode for operating on an in-memory copy of a DDI, instead of directly on it
This is useful for operating in ephemeral, writable mode on any image,
including read-only ones. It also has the benefit of not keeping the
image file's filesystem busy.

Inspired by the discussions in #25648
2022-12-08 12:48:06 +01:00
Lennart Poettering
fcd8a19da8 loop-util: add new loop_device_make_by_path_memory() helper
This uses the new memfd_clone_fd() call to make an in-memory copy of
some file before setting up a loopback block device on it.
2022-12-08 12:47:28 +01:00
Lennart Poettering
6bea3d8e0f data-fd-util: add new memfd_clone_fd() helper
This adds a new helper for cloning any file's contents (or block device contents) into a new memfd.
2022-12-08 12:47:01 +01:00
Antonio Alvarez Feijoo
0254e4d66a cryptsetup: retry TPM2 unseal operation if it fails with TPM2_RC_PCR_CHANGED
Quoting "Trusted Platform Module Library - Part 3: Commands (Rev. 01.59)":

"pcrUpdateCounter – this parameter is updated by TPM2_PolicyPCR(). This value
may only be set once during a policy. Each time TPM2_PolicyPCR() executes, it
checks to see if policySession->pcrUpdateCounter has its default state,
indicating that this is the first TPM2_PolicyPCR(). If it has its default value,
then policySession->pcrUpdateCounter is set to the current value of
pcrUpdateCounter. If policySession->pcrUpdateCounter does not have its default
value and its value is not the same as pcrUpdateCounter, the TPM shall return
TPM_RC_PCR_CHANGED.

If this parameter and pcrUpdateCounter are not the same, it indicates that PCR
have changed since checked by the previous TPM2_PolicyPCR(). Since they have
changed, the previous PCR validation is no longer valid."

The TPM will return TPM_RC_PCR_CHANGED if any PCR value changes (no matter
which) between validating the PCRs binded to the enrollment and unsealing the
HMAC key, so this patch adds a retry mechanism in this case.

Fixes #24906
2022-12-08 10:37:28 +01:00
Yu Watanabe
2e83783030
Merge pull request #25672 from jelly/FirwmwareName
Extend hostnamed DMI firmware properties
2022-12-08 16:04:36 +09:00
Yu Watanabe
daff9d5460
Merge pull request #25564 from poettering/dissect-discover
systemd-dissect: add simple "--discover" command
2022-12-08 12:29:07 +09:00
Yu Watanabe
cc488e9ba8
Merge pull request #25666 from poettering/selinux-getconf-fixup
selinux getXYZcon() NULL return fixes
2022-12-08 12:23:29 +09:00
Jade Lovelace
3b703840d9 oomd: print dry run output at INFO level
Otherwise, the dry run isn't much use since it would be logged at debug
and not seen.
2022-12-08 09:26:57 +09:00
Space Meyer
ff868eaade journald: prevent segfault on empty attr/current
getpidcon() might set con to NULL, even when it returned a 0 return
code[0]. The subsequent strlen(con) will then cause a segfault.

Alternatively the behaviour could also be changed in getpidcon. I
don't know whether the libselinux folks are comitted to the current
behaviour, but the getpidcon man page doesn't really make it obvious
this case could happen.

[0] fb7f35495f/libselinux/src/procattr.c (L155-L158)
2022-12-08 01:00:25 +01:00
msizanoen1
3d19e122cf core/unit: allow overriding an ongoing freeze operation
Sometimes a freeze operation can hang due to the presence of kernel
threads inside the unit cgroup (e.g. QEMU-KVM). This ensures that the
ThawUnit operation invoked by systemd-sleep at wakeup always thaws the
unit.
2022-12-08 00:54:53 +01:00
msizanoen1
a14137d90e core/cgroup: thaw slice of unit when thawing unit
This ensures starting a new unit under a frozen slice work as expected.
2022-12-08 00:54:53 +01:00
msizanoen1
fcb0878f75 core/slice: skip member units without realized cgroup during freeze or thaw
This ensures that services with `RemainAfterExit` but without any
process running won't cause failure during freeze.
2022-12-08 00:54:53 +01:00
msizanoen1
efa736d383 sleep: always thaw user.slice even if freezing failed
`FreezeUnit` can fail even when some units did got frozen, causing some
user units to be frozen. A possible symptom is `user@.service` being
frozen while still being able to log in over SSH.
2022-12-08 00:54:53 +01:00
Luca Boccassi
a101d7849d
Merge pull request #25465 from DaanDeMeyer/repart-workspace
repart: Cleanup created files on failure
2022-12-07 20:45:23 +01:00
Jelle van der Waa
ff4d26dff4 hostnamed: expose FirmwareDate dbus property
Expose /sys/class/dmi/id/bios_date as dbus property in hostnamed.
2022-12-07 20:35:56 +01:00
Jelle van der Waa
f233bbd607 hostnamed: expose FirmwareVendor as dbus property
Expose /sys/class/dmi/id/bios_vendor as dbus property in hostnamed.
2022-12-07 20:34:30 +01:00
Lennart Poettering
0305cf6e9d dissect: add simple --discover command 2022-12-07 17:57:22 +01:00
Lennart Poettering
3775e1410c discover-image: store image class in Image object too, if known 2022-12-07 17:44:35 +01:00
Lennart Poettering
e0cd19007e discover-image: add stringification helpers for ImageClass 2022-12-07 17:44:35 +01:00
Zbigniew Jędrzejewski-Szmek
54c84c8a7a ukify: allow multiple initrds
If given, multiple initrds are concatenated into a temporary file which then
becomes the .initrd section.

It is also possible to give no initrd. After all, some machines boot without an
initrd, and it should be possible to use the stub without requiring an initrd.
(The stub might not like this, but this is something to fix there.)
2022-12-07 17:22:05 +01:00
Zbigniew Jędrzejewski-Szmek
1f6da5d902 ci: install pefile 2022-12-07 15:53:47 +01:00
Zbigniew Jędrzejewski-Szmek
483c9c1b8a ukify: try to find the uname string in the linux image if not specified
The approach is based on mkinicpio's autodetection.

This is hacky as hell. Some cases are actually fairly nice: ppc64el images have
a note that contains 'uname -r'. (The note is not uniquely labeled at all, and
only contains the release part instead of the full version-hostname-release
string, and we don't actually care about ppc, and it's very hard to read the
note from Python, but in general that'd be the approach I'd like.)

I opted to simply read and decompress the full linux binary in some cases.
Python doesn't make it easy to do streaming decompression with regexp matching,
and it doesn't seem to matter much: the image decompresses in a fraction of a
second.
2022-12-07 15:53:45 +01:00
Zbigniew Jędrzejewski-Szmek
a1d6dbb1c9 tests: add pytest tests for ukify
Some gymnastics were needed to import ukify as a module. Before the file
was templated, this was trivial: insert the directory in sys.path, call import.
But it's a real pain to import the unsuffixed file after processing. Instead,
the untemplated file is imported, which works well enough for tests and is
very simple.

The tests can be called via pytest:
  PATH=build/:$PATH pytest -v src/ukify/test/test_ukify.py
or directly:
  PATH=build/:$PATH src/ukify/test/test_ukify.py
or via the meson test machinery output:
  meson test -C build test-ukify -v
or without verbose output:
  meson test -C build test-ukify

Zekret files are obfuscated using base64.
2022-12-07 15:52:37 +01:00
Zbigniew Jędrzejewski-Szmek
30ec2eaef5 meson,ukify: hook up ukify, add --version option
The option is added because we have a similar one for kernel-install. This
program requires python, and some people might want to skip it because of this.

The tool is installed in /usr/lib/systemd for now, since the interface might
change.

A template file is used, but there is no .in suffix.
The problem is that we'll later want to import the file as a module
for tests, but recent Python versions make it annoyingly hard to import
a module from a file without a .py suffix. imp.load_sources() works, but it
is deprecated and throws warnings.
importlib.machinery.SourceFileLoader().load_module() works, but is also
deprecated. And the documented replacements are a maze of twisted little
callbacks that result in an empty module.
So let's take the easy way out, and skip the suffix which makes it easy
to import the template as a module after adding the directory to sys.path.
2022-12-07 15:32:13 +01:00
Zbigniew Jędrzejewski-Szmek
f4780cbe30 ukify: add helper to create UKIs
Features:
- adds sections .linux, .initrd, .uname, .osrel, .pcrpkey, .pcrsig, .cmdline, .splash
- multiple initrds can be concatenated
- section flags are set properly (READONLY, DATA or CODE)
- uses systemd-measure to precalculate pcr measurements and create a signed json policy
- the inner linux image will be signed automatically with sbsign if unsigned
- uses sbsign to sign the output image
- offsets are calculated so that sections are placed adjacent, with .linux last
- custom sections are possible
- multiple pcr signing keys can be specified and different boot phase paths can be
  signed with different keys
- most things can be overriden (path to tools, stub file, signing keys, pcr banks,
  boot phase paths, whether to sign things)
- superficial verification of slash bmp is done
- kernel uname "scraping" from the kernel if not specified (in a later patch)

TODO:
- change systemd-measure to not require a functional TPM2. W/o this, we'd need
  to support all banks in the build machine, which is hard to guarantee.
- load signing keys from /etc/kernel/
- supress exceptions, so if something external fails, the user will not see a traceback
- conversion to BMP from other formats

$ sudo /usr/lib/systemd/ukify \
  --tools=build/ \
  --measure \
  /lib/modules/6.0.5-300.fc37.x86_64/vmlinuz \
  /boot/08a5690a2eed47cf92ac0a5d2e3cf6b0/6.0.5-300.fc37.x86_64/initrd \
  --secureboot-private-key=server.key --secureboot-certificate=server.crt \
  --pcr-private-key=tpm2-pcr-private.pem --pcr-public-key=tpm2-pcr-public.pem \
  --cmdline='rw quiet' \
  --section test:TESTTESTTEST \
  --section test2:TESTTESTTEST2 \
  --pcr-banks=sha1 \
  --uname="$(uname -rv)"

Host arch 'x86_64', efi arch 'x64'
+ sbverify --list /lib/modules/6.0.5-300.fc37.x86_64/vmlinuz
+ build/systemd-measure calculate --linux=/lib/modules/6.0.5-300.fc37.x86_64/vmlinuz --osrel=/etc/os-release --cmdline=/tmp/tmpcmdline_5aufjir --pcrpkey=tpm2-pcr-public.pem --initrd=/boot/08a5690a2eed47cf92ac0a5d2e3cf6b0/6.0.5-300.fc37.x86_64/initrd --bank=sha1
11:sha1=03df5e5243bc002b959d52359fe04e266d0b5ebf
11:sha1=54949b82bae32e80343ff0f01eeeeb75f4c07d3f
11:sha1=0fc62be88aa9c5ad7282aa8adb504f451bcec9df
11:sha1=b71155e7fcd467f7c1696f675e37887032e2eafa
+ build/systemd-measure sign --linux=/lib/modules/6.0.5-300.fc37.x86_64/vmlinuz --osrel=/etc/os-release --cmdline=/tmp/tmpcmdline_5aufjir --pcrpkey=tpm2-pcr-public.pem --initrd=/boot/08a5690a2eed47cf92ac0a5d2e3cf6b0/6.0.5-300.fc37.x86_64/initrd --bank=sha1 --private-key=tpm2-pcr-private.pem --public-key=tpm2-pcr-public.pem
+ objcopy /usr/lib/systemd/boot/efi/linuxx64.efi.stub --add-section .osrel=/etc/os-release --change-section-vma .osrel=0x22000 --add-section .cmdline=/tmp/tmpcmdline_5aufjir --change-section-vma .cmdline=0x23000 --add-section .pcrpkey=tpm2-pcr-public.pem --change-section-vma .pcrpkey=0x24000 --add-section .initrd=/boot/08a5690a2eed47cf92ac0a5d2e3cf6b0/6.0.5-300.fc37.x86_64/initrd --change-section-vma .initrd=0x25000 --add-section .uname=/tmp/tmpuname0v3uzh5r --change-section-vma .uname=0x4009000 --add-section .test=/tmp/tmptestuxve59c8 --change-section-vma .test=0x400a000 --add-section .test2=/tmp/tmptest2_i143p9i --change-section-vma .test2=0x400b000 --add-section .pcrsig=/tmp/tmppcrsigdtcqxz_w --change-section-vma .pcrsig=0x400c000 --add-section .linux=/lib/modules/6.0.5-300.fc37.x86_64/vmlinuz --change-section-vma .linux=0x400d000 /tmp/uki4vsbf7y8
+ sbsign --key server.key --cert server.crt /tmp/uki4vsbf7y8 --output vmlinuz.efi
warning: data remaining[79849520 vs 79866644]: gaps between PE/COFF sections?
warning: data remaining[79849520 vs 79866648]: gaps between PE/COFF sections?
Signing Unsigned original image
Wrote signed vmlinuz.efi
2022-12-07 15:32:13 +01:00
Lennart Poettering
4a69c2c748 selinux-setup: minor modernizations 2022-12-07 15:26:18 +01:00
Lennart Poettering
af614e45c3 selinux: accept the fact that getxyzcon() can return success and NULL
Inspired by #25664: let's check explicitly for NULL everywhere we do one
of those getXYZcon() calls.

We usually turn this into EOPNOTSUPP, as when selinux is off (which is
supposed to be the only case this can happen according to selinux docs)
we otherwise return EOPNOTSUPP in that case.

Note that in most cases we have an explicit mac_selinux_use() call
beforehand, hence this should mostly not be triggerable codepaths.
2022-12-07 15:25:37 +01:00
Yu Watanabe
42f8b6a808 network: manage addresses in the way the kernel does
This effectively reverts 5d0030310c.

With the commit 5d0030310c, networkd manages
addresses with the detailed hash and compare functions. But that causes
networkd cannot detect address update by the kernel or an external tool.
See issue
https://github.com/systemd/systemd/issues/481#issuecomment-1328132401.

With this commit, networkd (again) manages addresses in the way that the
kernel does. Hence, we can correctly detect address update.
2022-12-07 15:10:45 +01:00
Luca Boccassi
87edf80b1b
Merge pull request #25502 from keszybz/pam-namespace-add
Add pam_namespace to user@.service pam stack
2022-12-07 13:01:50 +01:00
Yu Watanabe
47c57b4813 core: use correct scope of looking up units
Fixes a bug introduced by 3b3557c410.

Fixes #25625.
2022-12-07 12:45:33 +01:00
Yu Watanabe
9644fbd584 fuzz-systemctl: adjust size limit
Follow-up for 719b7d4dc2.

The size of the current reproducer is 250KB. Hence, 16KB should be
enough, but still we can test most arguments within the size.

Hopefully fixes oss-fuzz#53552.
2022-12-07 09:56:50 +01:00
Yu Watanabe
bf9afd7b31
Merge pull request #25628 from zhangjian3032/dev/fix-set-bond-mac-failed
network: Fix set bond device MAC address failed
2022-12-07 13:34:39 +09:00
Daan De Meyer
94799c305a test-fs-util: Add relative path chase_symlinks() tests 2022-12-07 10:39:20 +09:00
Zbigniew Jędrzejewski-Szmek
cc420ae52a
Merge pull request #25616 from poettering/chase-symlinks-opendir
chase-symlinks/systemctl: let's handle cases without /proc/ better
2022-12-06 17:10:54 +01:00
Lennart Poettering
86adf4a5e8 gpt: add helpers for deriving data partition from verity or verity sig designator
let's add the inverse of the existing partition_verity_of() and
partition_verity_sig_of()
2022-12-06 16:41:06 +01:00
Frantisek Sumsal
0e336ea265
Merge pull request #25644 from yuwata/escape-fix-octescape
escape: fix octescape()
2022-12-06 15:22:08 +00:00
Yu Watanabe
f4ee7b98c4 network: drop REMOVING flag when a netlink message is sent to kernel
When an interface goes to down, the kernel drops several routes
automatically, and at the same time networkd requests to remove
them, but the kernel sometimes does not respond the requests. Hence,
the routes cannot drop the REMOVING flag, and networkd will never try
to configure other routes which depend on the previously removed
routes even if they are already reconfigured.

With this patch, when networkd sends a request to configure a route
(or any other network settings), REMOVING flag for the route is dropped
without waiting for the reply about the previous remove request, as we
can expect it will appear even if it is already removed or under removing.

Fixes #24999.
2022-12-06 16:01:01 +01:00
Luca Boccassi
0927ae6a5c
Merge pull request #25645 from yuwata/boot-fix-false-maybe-uninitialized
boot: fix false maybe-uninitialized warning
2022-12-06 16:00:10 +01:00
Aidan Dang
b04ff66b42 Implement --luks-pbkdf-force-iterations for homed 2022-12-06 15:56:11 +01:00
Yu Watanabe
64e7a14146
Merge pull request #25559 from intelfx/work/systemd-importd-quotas
import: wire up SYSTEMD_IMPORT_BTRFS_{SUBVOL,QUOTA} to importd
2022-12-06 14:05:35 +09:00
Yu Watanabe
febe556191 boot: fix false maybe-uninitialized warning
Fixes #25641.
2022-12-06 13:10:54 +09:00
Yu Watanabe
9e406b1141 boot: cleanups for efivar_get() and friends
- rename function arguments for storing results, and support the case
  that they are NULL,
- return earlier on error,
- always validate read size in efivar_get_uint32_le() and efivar_get_uint64_le().
2022-12-06 13:10:28 +09:00
Lennart Poettering
5acb31a683 dissect: show color in log output 2022-12-06 12:25:00 +09:00
Yu Watanabe
4f438c638b test: add basic tests for octescape() 2022-12-06 12:18:14 +09:00
Yu Watanabe
76519cecc7 escape: fix wrong octescape of bad character
Fixes a bug introduced by 95052df376.

This also makes octescape() support NULL or zero length string.

Fixes [oss-fuzz#54059](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54059).

Fixes #25643.
2022-12-06 12:18:10 +09:00
Luca Boccassi
83320324df journald: fix build error
Follow-up for: 379864f890

Two PRs clashed with each other and were merged before we noticed
2022-12-06 11:41:03 +09:00
Luca Boccassi
f252ea9ae4
Merge pull request #25638 from bluca/rate_limit_config
pid1: add env var to override default mount rate limit burst
2022-12-06 02:07:47 +01:00
Luca Boccassi
9cd4881d47
Merge pull request #25513 from brauner/pivot_root.nspawn
nspawn: support pivot_root()
2022-12-06 01:51:51 +01:00
Richard Phibel
379864f890 log: Switch logging to runtime when FS becomes read-only
The journal has a mechanism to log to the runtime journal if it fails to
log to the system journal. This mechanism is not triggered when the file
system becomes read-only. We enable it here.

When appending an entry fails if shall_try_append_again returns true,
the journal is rotated. If the FS is read-only, rotation will fail and
s->system_journal will be set to NULL. After that, when find_journal
will try to open the journal since s->system_journal will be NULL, it
will open the runtime journal.
2022-12-06 00:53:47 +01:00
Luca Boccassi
a5d63f1e29
Merge pull request #25633 from DaanDeMeyer/journald-another-ratelimit
journald: Ratelimit a few more log messages
2022-12-05 22:08:25 +01:00
Luca Boccassi
24a4542cfa pid1: add env var to override default mount rate limit burst
I am hitting the rate limit on a busy system with low resources, and
it stalls the boot process which is Very Bad (TM).
2022-12-05 21:05:57 +00:00
Christian Brauner
e79581ddfe
nspawn: split mount tunnel setup
Before we supported pivot_root() nspawn used to make the rootfs shared
before setting up the mount tunnel. So it was safe for it to just turn
it into a dependent mount during setup.

However, we cannot do this anymore because of the requirements
pivot_root() has. After the pivot_root() we will make the rootfs shared
recursively. If we turned the mount tunnel into dependent mount before
mount_switch_root() this will have the consequence that it becomes a
shared mount within the same peer group as the rootfs. So no mounts will
propagate into the container from the host anymore.

To fix this we split setting up the mount tunnel and making it active
into two steps. Setting up the mount tunnel is performed before
mount_switch_root() and activating it afterwards. Note that this works
because turning a shared mount into a shared mount is a nop. IOW, no new
peer group will be allocated.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-05 18:35:02 +01:00
Christian Brauner
b71a0192c0
nspawn: mount temporary visible procfs and sysfs instance
In order to mount procfs and sysfs in an unprivileged container the
kernel requires that a fully visible instance is already present in the
target mount namespace. Mount one here so the inner child can mount its
own  instances. Later we umount the temporary  instances created here
before we actually exec the payload. Since the rootfs is shared the
umount will propagate into the container. Note, the inner child wouldn't
be able to unmount the  instances on its own since it doesn't own the
originating mount namespace. IOW, the outer child needs to do this.

So far nspawn didn't run into this issue because it used MS_MOVE which
meant that the shadow mount tree pinned a procfs and sysfs instance
which the kernel would find. The shadow mount tree is gone with proper
pivot_root() semantics.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-05 18:34:25 +01:00
Christian Brauner
57c10a5650
nspawn: support pivot_root()
In order to support pivot_root() we need to move mount propagation
changes after the pivot_root(). While MS_MOVE requires the source mount
to not be a shared mount pivot_root() also requires the target mount to
not be a shared mount. This guarantees that pivot_root() doesn't leak
any mounts.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-12-05 18:34:25 +01:00
Daan De Meyer
04cb8ee880 journal: Ratelimit more log messages
Followup for 8522691d4d.
2022-12-05 14:41:53 +01:00
Daan De Meyer
d9799ea2e2 journal: Use shared log ratelimit constant
Instead of maintaining two different constants, move the constant
to journal-internal.h and share it between files.
2022-12-05 14:41:51 +01:00
Zbigniew Jędrzejewski-Szmek
cda7c31065
Merge pull request #25537 from evverx/fuzz-resource-records
tests: fuzz dns resource records
2022-12-05 13:41:38 +01:00
Jian Zhang
f1a69d5acc network: Fix set bond device MAC address failed
Issue:
When device is in bond mode and booting up, there is a probability of
set bond MAC address failed due to `Device or resource busy` error.

In systemd-networkd, set MAC address steps are:
1. Try to set MAC address to device.
2. If failed with `Device or resource busy`, then `Down` the device.
3. Try to set MAC address to device again.

Currently, Even down the bond device, the bond device is still return
`Device or resource busy` error. So the MAC address set failed.

The root cause is that this not enough to down the bond device. We need
to down all the slaves of the bond device.
About this descprition, we could use those commands to check:
```shell
We have two network devices: eth0, bond1, eth0 is slave of bond1.
They are all up.

1. Down bond1, and set MAC address to bond1.
~# ip link set bond1 down
~# ip link set bond1 address 00:11:22:33:44:55
ip: SIOCSIFHWADDR: Device or resource busy

2. Down eth0, and set MAC address to bond1.
~# ip link set eth0 down
~# ip link set bond1 address 00:11:22:33:44:55
Set okay.
```

Fix:
When setting the mac for the second time, if the device kind is bond,
then we need to down the slave devices of bond device.

Tested: Verified in a long time test( reboot cycles ).

Fixes: #25627

Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
2022-12-05 19:48:45 +08:00
Yu Watanabe
cfef0734a1 acl-util: several cleanups
- add missing assertions,
- rename function arguments for storing result,
- rename variables which conflict our macros,
- always initialize function arguments for results on success.
2022-12-05 10:37:58 +01:00
Zbigniew Jędrzejewski-Szmek
8608fef36c
Merge pull request #25437 from YHNdnzj/systemctl-disable-warn-statically-enabled-services
systemctl: warn if trying to disable a unit with no install info
2022-12-05 10:27:24 +01:00
Daan De Meyer
2877b14720 chase-symlinks: Fix regression from 5bc244aaa9
Previously, chase_symlinks() always returned an absolute path, which
changed after 5bc244aaa9. This commit
fixes chase_symlinks() so it returns absolute paths all the time again.
2022-12-05 09:27:58 +01:00
Eric DeVolder
5fbaa75707 pstore: fixes for dmesg.txt reconstruction
This patch fixes problems with the re-assembly of the dmesg
from the records stored in pstore.

The current code simply ignores the last 6 characters of the
file name to form a base record id, which then groups any
pstore files with this base id into the reconstructed dmesg.txt.
This approach fails when the following oops generated the
following in pstore:

 -rw-------.  1 root root  1808 Oct 27 22:07 dmesg-efi-166692286101001
 -rw-------.  1 root root  1341 Oct 27 22:07 dmesg-efi-166692286101002
 -rw-------.  1 root root  1812 Oct 27 22:07 dmesg-efi-166692286102001
 -rw-------.  1 root root  1820 Oct 27 22:07 dmesg-efi-166692286102002
 -rw-------.  1 root root  1807 Oct 27 22:07 dmesg-efi-166692286103001
 -rw-------.  1 root root  1791 Oct 27 22:07 dmesg-efi-166692286103002
 -rw-------.  1 root root  1773 Oct 27 22:07 dmesg-efi-166692286104001
 -rw-------.  1 root root  1801 Oct 27 22:07 dmesg-efi-166692286104002
 -rw-------.  1 root root  1821 Oct 27 22:07 dmesg-efi-166692286105001
 -rw-------.  1 root root  1809 Oct 27 22:07 dmesg-efi-166692286105002
 -rw-------.  1 root root  1804 Oct 27 22:07 dmesg-efi-166692286106001
 -rw-------.  1 root root  1817 Oct 27 22:07 dmesg-efi-166692286106002
 -rw-------.  1 root root  1792 Oct 27 22:07 dmesg-efi-166692286107001
 -rw-------.  1 root root  1810 Oct 27 22:07 dmesg-efi-166692286107002
 -rw-------.  1 root root  1717 Oct 27 22:07 dmesg-efi-166692286108001
 -rw-------.  1 root root  1808 Oct 27 22:07 dmesg-efi-166692286108002
 -rw-------.  1 root root  1764 Oct 27 22:07 dmesg-efi-166692286109001
 -rw-------.  1 root root  1765 Oct 27 22:07 dmesg-efi-166692286109002
 -rw-------.  1 root root  1796 Oct 27 22:07 dmesg-efi-166692286110001
 -rw-------.  1 root root  1816 Oct 27 22:07 dmesg-efi-166692286110002
 -rw-------.  1 root root  1793 Oct 27 22:07 dmesg-efi-166692286111001
 -rw-------.  1 root root  1751 Oct 27 22:07 dmesg-efi-166692286111002
 -rw-------.  1 root root  1813 Oct 27 22:07 dmesg-efi-166692286112001
 -rw-------.  1 root root  1786 Oct 27 22:07 dmesg-efi-166692286112002
 -rw-------.  1 root root  1754 Oct 27 22:07 dmesg-efi-166692286113001
 -rw-------.  1 root root  1752 Oct 27 22:07 dmesg-efi-166692286113002
 -rw-------.  1 root root  1803 Oct 27 22:07 dmesg-efi-166692286114001
 -rw-------.  1 root root  1759 Oct 27 22:07 dmesg-efi-166692286114002
 -rw-------.  1 root root  1805 Oct 27 22:07 dmesg-efi-166692286115001
 -rw-------.  1 root root  1787 Oct 27 22:07 dmesg-efi-166692286115002
 -rw-------.  1 root root  1815 Oct 27 22:07 dmesg-efi-166692286116001
 -rw-------.  1 root root  1771 Oct 27 22:07 dmesg-efi-166692286116002
 -rw-------.  1 root root  1816 Oct 27 22:07 dmesg-efi-166692286117002
 -rw-------.  1 root root  1388 Oct 27 22:07 dmesg-efi-166692286701003
 -rw-------.  1 root root  1824 Oct 27 22:07 dmesg-efi-166692286702003
 -rw-------.  1 root root  1795 Oct 27 22:07 dmesg-efi-166692286703003
 -rw-------.  1 root root  1805 Oct 27 22:07 dmesg-efi-166692286704003
 -rw-------.  1 root root  1813 Oct 27 22:07 dmesg-efi-166692286705003
 -rw-------.  1 root root  1821 Oct 27 22:07 dmesg-efi-166692286706003
 -rw-------.  1 root root  1814 Oct 27 22:07 dmesg-efi-166692286707003
 -rw-------.  1 root root  1812 Oct 27 22:07 dmesg-efi-166692286708003
 -rw-------.  1 root root  1769 Oct 27 22:07 dmesg-efi-166692286709003
 -rw-------.  1 root root  1820 Oct 27 22:07 dmesg-efi-166692286710003
 -rw-------.  1 root root  1755 Oct 27 22:07 dmesg-efi-166692286711003
 -rw-------.  1 root root  1790 Oct 27 22:07 dmesg-efi-166692286712003
 -rw-------.  1 root root  1756 Oct 27 22:07 dmesg-efi-166692286713003
 -rw-------.  1 root root  1763 Oct 27 22:07 dmesg-efi-166692286714003
 -rw-------.  1 root root  1791 Oct 27 22:07 dmesg-efi-166692286715003
 -rw-------.  1 root root  1775 Oct 27 22:07 dmesg-efi-166692286716003
 -rw-------.  1 root root  1820 Oct 27 22:07 dmesg-efi-166692286717003

The "reconstructed" dmesg.txt that resulted from the above contained
the following (ignoring actual contents, just providing the Part info):

 Emergency#3 Part17
 Emergency#3 Part16
 Emergency#3 Part15
 Emergency#3 Part14
 Emergency#3 Part13
 Emergency#3 Part12
 Emergency#3 Part11
 Emergency#3 Part10
 Emergency#3 Part9
 Emergency#3 Part8
 Emergency#3 Part7
 Emergency#3 Part6
 Emergency#3 Part5
 Emergency#3 Part4
 Emergency#3 Part3
 Emergency#3 Part2
 Emergency#3 Part1
 Panic#2 Part17
 Panic#2 Part16
 Oops#1 Part16
 Panic#2 Part15
 Oops#1 Part15
 Panic#2 Part14
 Oops#1 Part14
 Panic#2 Part13
 Oops#1 Part13
 Panic#2 Part12
 Oops#1 Part12
 Panic#2 Part11
 Oops#1 Part11
 Panic#2 Part10
 Oops#1 Part10
 Panic#2 Part9
 Oops#1 Part9
 Panic#2 Part8
 Oops#1 Part8
 Panic#2 Part7
 Oops#1 Part7
 Panic#2 Part6
 Oops#1 Part6
 Panic#2 Part5
 Oops#1 Part5
 Panic#2 Part4
 Oops#1 Part4
 Panic#2 Part3
 Oops#1 Part3
 Panic#2 Part2
 Oops#1 Part2
 Panic#2 Part1
 Oops#1 Part1

The above is a interleaved mess of three dmesg dumps.

This patch fixes the above problems, and simplifies the dmesg
reconstruction process. The code now distinguishes between
records on EFI vs ERST, which have differently formatted
record identifiers. Using knowledge of the format of the
record ids allows vastly improved reconstruction process.

With this change in place, the above pstore records now
result in the following:

 # ls -alR /var/lib/systemd/pstore
 1666922861:
 total 8
 drwxr-xr-x. 4 root root   28 Nov 18 14:58 .
 drwxr-xr-x. 7 root root  144 Nov 18 14:58 ..
 drwxr-xr-x. 2 root root 4096 Nov 18 14:58 001
 drwxr-xr-x. 2 root root 4096 Nov 18 14:58 002

 1666922861/001:
 total 100
 drwxr-xr-x. 2 root root  4096 Nov 18 14:58 .
 drwxr-xr-x. 4 root root    28 Nov 18 14:58 ..
 -rw-------. 1 root root  1808 Oct 27 22:07 dmesg-efi-166692286101001
 -rw-------. 1 root root  1812 Oct 27 22:07 dmesg-efi-166692286102001
 -rw-------. 1 root root  1807 Oct 27 22:07 dmesg-efi-166692286103001
 -rw-------. 1 root root  1773 Oct 27 22:07 dmesg-efi-166692286104001
 -rw-------. 1 root root  1821 Oct 27 22:07 dmesg-efi-166692286105001
 -rw-------. 1 root root  1804 Oct 27 22:07 dmesg-efi-166692286106001
 -rw-------. 1 root root  1792 Oct 27 22:07 dmesg-efi-166692286107001
 -rw-------. 1 root root  1717 Oct 27 22:07 dmesg-efi-166692286108001
 -rw-------. 1 root root  1764 Oct 27 22:07 dmesg-efi-166692286109001
 -rw-------. 1 root root  1796 Oct 27 22:07 dmesg-efi-166692286110001
 -rw-------. 1 root root  1793 Oct 27 22:07 dmesg-efi-166692286111001
 -rw-------. 1 root root  1813 Oct 27 22:07 dmesg-efi-166692286112001
 -rw-------. 1 root root  1754 Oct 27 22:07 dmesg-efi-166692286113001
 -rw-------. 1 root root  1803 Oct 27 22:07 dmesg-efi-166692286114001
 -rw-------. 1 root root  1805 Oct 27 22:07 dmesg-efi-166692286115001
 -rw-------. 1 root root  1815 Oct 27 22:07 dmesg-efi-166692286116001
 -rw-r-----. 1 root root 28677 Nov 18 14:58 dmesg.txt

 1666922861/002:
 total 104
 drwxr-xr-x. 2 root root  4096 Nov 18 14:58 .
 drwxr-xr-x. 4 root root    28 Nov 18 14:58 ..
 -rw-------. 1 root root  1341 Oct 27 22:07 dmesg-efi-166692286101002
 -rw-------. 1 root root  1820 Oct 27 22:07 dmesg-efi-166692286102002
 -rw-------. 1 root root  1791 Oct 27 22:07 dmesg-efi-166692286103002
 -rw-------. 1 root root  1801 Oct 27 22:07 dmesg-efi-166692286104002
 -rw-------. 1 root root  1809 Oct 27 22:07 dmesg-efi-166692286105002
 -rw-------. 1 root root  1817 Oct 27 22:07 dmesg-efi-166692286106002
 -rw-------. 1 root root  1810 Oct 27 22:07 dmesg-efi-166692286107002
 -rw-------. 1 root root  1808 Oct 27 22:07 dmesg-efi-166692286108002
 -rw-------. 1 root root  1765 Oct 27 22:07 dmesg-efi-166692286109002
 -rw-------. 1 root root  1816 Oct 27 22:07 dmesg-efi-166692286110002
 -rw-------. 1 root root  1751 Oct 27 22:07 dmesg-efi-166692286111002
 -rw-------. 1 root root  1786 Oct 27 22:07 dmesg-efi-166692286112002
 -rw-------. 1 root root  1752 Oct 27 22:07 dmesg-efi-166692286113002
 -rw-------. 1 root root  1759 Oct 27 22:07 dmesg-efi-166692286114002
 -rw-------. 1 root root  1787 Oct 27 22:07 dmesg-efi-166692286115002
 -rw-------. 1 root root  1771 Oct 27 22:07 dmesg-efi-166692286116002
 -rw-------. 1 root root  1816 Oct 27 22:07 dmesg-efi-166692286117002
 -rw-r-----. 1 root root 30000 Nov 18 14:58 dmesg.txt

 1666922867:
 total 4
 drwxr-xr-x. 3 root root   17 Nov 18 14:58 .
 drwxr-xr-x. 7 root root  144 Nov 18 14:58 ..
 drwxr-xr-x. 2 root root 4096 Nov 18 14:58 003

 1666922867/003:
 total 104
 drwxr-xr-x. 2 root root  4096 Nov 18 14:58 .
 drwxr-xr-x. 3 root root    17 Nov 18 14:58 ..
 -rw-------. 1 root root  1388 Oct 27 22:07 dmesg-efi-166692286701003
 -rw-------. 1 root root  1824 Oct 27 22:07 dmesg-efi-166692286702003
 -rw-------. 1 root root  1795 Oct 27 22:07 dmesg-efi-166692286703003
 -rw-------. 1 root root  1805 Oct 27 22:07 dmesg-efi-166692286704003
 -rw-------. 1 root root  1813 Oct 27 22:07 dmesg-efi-166692286705003
 -rw-------. 1 root root  1821 Oct 27 22:07 dmesg-efi-166692286706003
 -rw-------. 1 root root  1814 Oct 27 22:07 dmesg-efi-166692286707003
 -rw-------. 1 root root  1812 Oct 27 22:07 dmesg-efi-166692286708003
 -rw-------. 1 root root  1769 Oct 27 22:07 dmesg-efi-166692286709003
 -rw-------. 1 root root  1820 Oct 27 22:07 dmesg-efi-166692286710003
 -rw-------. 1 root root  1755 Oct 27 22:07 dmesg-efi-166692286711003
 -rw-------. 1 root root  1790 Oct 27 22:07 dmesg-efi-166692286712003
 -rw-------. 1 root root  1756 Oct 27 22:07 dmesg-efi-166692286713003
 -rw-------. 1 root root  1763 Oct 27 22:07 dmesg-efi-166692286714003
 -rw-------. 1 root root  1791 Oct 27 22:07 dmesg-efi-166692286715003
 -rw-------. 1 root root  1775 Oct 27 22:07 dmesg-efi-166692286716003
 -rw-------. 1 root root  1820 Oct 27 22:07 dmesg-efi-166692286717003
 -rw-r-----. 1 root root 30111 Nov 18 14:58 dmesg.txt

Furthemore, pstore records on ERST are now able to accurately
identify the change in timestamp sequence in order to start a
new dmesg.txt, as needed.
2022-12-05 09:25:12 +01:00
Lennart Poettering
f8a8f613c6 Revert "update credentials when reloading a service"
This reverts commit 16a42b84cf.
2022-12-05 09:00:45 +01:00
Zbigniew Jędrzejewski-Szmek
d22771fc00 gpt-auto-generator: do not write "noauto" in unit options
"auto"/"noauto" only make sense in the fstab. Putting them in Options= in the
generated unit has no effect and is confusing.
2022-12-05 08:42:04 +01:00
Zbigniew Jędrzejewski-Szmek
c99070a8cb
Merge pull request #25618 from keszybz/sysctl-simplify-writing
Write sysctl values without newlines and as fixed strings
2022-12-05 08:41:00 +01:00
Ivan Shapovalov
c7779a61ac import: wire up SYSTEMD_IMPORT_BTRFS_{SUBVOL,QUOTA} to importd
Btrfs quotas are actually being enabled in systemd-importd via
setup_machine_directory(), not in systemd-{import,pull} where those
environment variables are checked. Therefore, also check them in
systemd-importd and avoid enabling quotas if requested by the user.

Fixes: #18421
Fixes: #15903
Fixes: #24387
2022-12-03 20:31:48 +04:00
Ivan Shapovalov
e9231901a2 machine-pool: simplify return values from setup_machine_directory()
Non-negative return values of setup_machine_directory() were never used
and never had clear meaning, so do not distinguish between various
non-error conditions and just return 0 in all cases.
2022-12-03 20:31:48 +04:00
Mike Yuan
0acb1459a1
rpm/systemd-update-helper: use --no-warn when disabling units
Suppress the "empty [Install] section" warning (see #25437).
2022-12-03 20:27:47 +08:00
Mike Yuan
108d35ac7d
systemctl: allow suppress the warning of no install info using --no-warn
In cases like packaging scripts, it might be desired to use
enable/disable on units without install info. So, adding an
option '--no-warn' to suppress the warning.
2022-12-03 20:26:19 +08:00
Mike Yuan
bf1bea43f1
systemctl: warn if trying to disable a unit with no install info
Trying to disable a unit with no install info is mostly useless, so
adding a warning like we do for enable (with the new dbus method
'DisableUnitFilesWithFlagsAndInstallInfo()'). Note that it would
still find and remove symlinks to the unit in /etc, regardless of
whether it has install info or not, just like before. And if there are
actually files to remove, we suppress the warning.

Fixes #17689
2022-12-03 20:26:14 +08:00
Zbigniew Jędrzejewski-Szmek
27c8ca439f manager: write net/unix/max_dgram_qlen sysctl as fixed string 2022-12-03 11:59:03 +01:00
Zbigniew Jędrzejewski-Szmek
a5fac1df27 manager: define a string constant for LONG_MAX and use that for sysctl
This moves the formatting of the constant to compilation time and let's us
avoid asprintf() in the very hot path of initial boot.
2022-12-03 11:59:03 +01:00
Zbigniew Jędrzejewski-Szmek
b47e0fac03 manager: do not append '\n' when writing sysctl settings
When booting with debug logs, we print:

   Setting '/proc/sys/fs/file-max' to '9223372036854775807
   '
   Setting '/proc/sys/fs/nr_open' to '2147483640
   '
   Couldn't write fs.nr_open as 2147483640, halving it.
   Setting '/proc/sys/fs/nr_open' to '1073741816
   '
   Successfully bumped fs.nr_open to 1073741816

The strange formatting is because we explicitly appended a newline in those two
places. It seems that the kernel doesn't care. In fact, we have a few dozen other
writes to sysctl where we don't append a newline. So let's just drop those here
too, to make the code a bit simpler and avoid strange output in the logs.
2022-12-03 11:59:03 +01:00
Lennart Poettering
c2534821dc dissect: add new helper verity_settings_data_covers()
This function checks if the external verity data referenced in
VeritySettings covers the specified partition (indicated via
designator).

Right now, we'll use that at one place, but in a later commit in more.
2022-12-03 00:22:23 +01:00
Lennart Poettering
0f958c8d4f systemctl: print a clear warning if people invoke systemctl without /proc/ 2022-12-02 23:56:20 +01:00
Lennart Poettering
2075b6dd39 chase-symlink: when converting directory O_PATH fd to real fd, don't bother with /proc/
Replaces: #25581
2022-12-02 23:55:44 +01:00
Lennart Poettering
03c16b9784 glyph-util: add warning sign special glyph 2022-12-02 23:54:50 +01:00
Lennart Poettering
d90b03f80d dissect: pick up gpt partition flags
Let's store the GPT partition flags in the dissected partition info.

Right now we won't actually use them for anything yet, but later we'll
add that, when enforcing policy on dissection.
2022-12-02 22:52:48 +01:00
Lennart Poettering
f6484e8503
Merge pull request #25570 from yuwata/dissect-rootless-image
dissect: support to unmount image without root partition
2022-12-02 18:25:53 +01:00
Lennart Poettering
1fe6e5c112 Revert "basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted"
This reverts commit 3e22dfc235.
2022-12-02 17:57:10 +01:00
Michal Sekletar
3e22dfc235 basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted
https://bugzilla.redhat.com/show_bug.cgi?id=2136916
2022-12-02 17:45:33 +01:00
Zbigniew Jędrzejewski-Szmek
6accdcc547
Merge pull request #25541 from medhefgo/boot-reconnect
boot: Fix huge boot delay
2022-12-02 14:37:17 +01:00
Yu Watanabe
a52efa813d dissect-image: log expected UUID for /var
Closes #25443.
2022-12-02 14:25:48 +01:00
Yu Watanabe
46dc071985 bootspec: fix null-dereference-read
Fixes [oss-fuzz#53578](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53578).
Fixes #25450.
2022-12-02 14:23:45 +01:00
Yu Watanabe
719b7d4dc2 fuzz-systemctl: limit the size of input
Fixes [oss-fuzz#53552](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53552).
Fixes #25445.
2022-12-02 14:22:25 +01:00
Yu Watanabe
6c2d70ce9f tree-wide: fix typo 2022-12-02 13:27:08 +09:00
Neil Moore
d833ed781f virt: Support detection of LMHS SRE guests 2022-12-02 10:29:14 +09:00
Yu Watanabe
ef6636fd18
Merge pull request #25591 from poettering/dissect-probe-offset
dissect-image: probe file system via main block device fd/image file fd
2022-12-02 09:15:20 +09:00
Phaedrus Leeds
c85c2f7930 nspawn: Use "Ctrl-" rather than "^" in info msg
Maybe most people know that "^]" means "Ctrl + ]" but for those that
don't, this should be more clear.
2022-12-02 08:28:04 +09:00
Yu Watanabe
d9a95033bf network: unset Link.ndisc_configured only when a new address or route is requested
This fixes an issue introduced by af2aea8bb6.

When an outdated address or route is passed to link_request_address()/route(),
then they return 0 and the address or route will not be assigned. Such
situation can happen when we receive RA with zero lifetime. In that
case, we should not unset Link.ndisc_configured flag, otherwise even
no new address nor route will assigned, the interface will enter to the
configuring state, and unnecessary DBus property change is emit and the state
file will be updated. That makes resolved or timesyncd triggered to
reconfigure the interface.

Fixes #25456.
2022-12-01 23:15:09 +01:00
Luca Boccassi
f7031144da
Merge pull request #25568 from yuwata/network-tiny-cleanups
network: tiny cleanups
2022-12-01 23:12:26 +01:00
Lennart Poettering
c80c9079c8 dissect-image: probe file system via main block device fd/image file fd
let's make sure we can probe file systems also when unprivileged:
instead of probing the partition block devices for file system
signatures, let's go via the original "whole" fd.

libblkid makes this easy actually, as it allows us to specify the
offset/size of the area to probe. And we have the partition
offsets/sizes anyway, so it's trivial for us to make use of.

This thus enables fs probing also when lacking privs and operating on
naked regular files without loopback devices or anything like this.
2022-12-01 22:09:30 +01:00
Lennart Poettering
59a4c0d7e3 test-loop-block: let's explicitly flush buffer cache on whole block device
Let's explicitly flush the kernel's buffer cache on the whole block
device once we ran "mkfs". This is necessary, because partition and
whole block devices maintain separate buffer caches, and thus writing
to one will not be visible on the other if cached there already, until
the latter's cache is explicitly flushed.

This is preparation for later adding support for probing file sytems
also if we have no open partition block devices, and hence want to use
the whole block device instead.
2022-12-01 22:07:36 +01:00
Lennart Poettering
9f2d9a4aab test-loop-block: also test dissection without ADD/PIN of partition block devices
Let's extend the test further, and try the codepaths where we do not
pin/add the partition block devices (i.e. which is the codepaths we use
when running without privs)
2022-12-01 22:07:36 +01:00
Lennart Poettering
02c15120a1 test-loop-block: tighten tests a bit - check fstype, too
Let's verify that we properly created the file systems once we did so.
And tets this way that our dissector works correctly.
2022-12-01 22:07:36 +01:00
Yu Watanabe
41a95b18bd dissect: support to unmount image without root partition
Fixes #25480.
2022-12-02 02:58:44 +09:00
Yu Watanabe
040d343903 dissect: use sd-device to find and open loopback block device 2022-12-02 02:52:06 +09:00
Zbigniew Jędrzejewski-Szmek
c3f0bff945 bootctl: use output mode where "[]" is written instead for empty output
It's easier for the caller if output is always a list, even if there are no
entries.
2022-12-01 18:14:52 +01:00
Zbigniew Jędrzejewski-Szmek
8525bb369a shared/json: optimize appending objects to arrays
When repeatedly appending an object to a growing array, we would create a new
array larger by one slot, insert all the old entries and the new element with
ref count bumps into the new array, and then unref the old array.

This would cause problems when building an array with more than a few thousand
elements. If userdbctl is modified to construct an array,
'userdbctl --json=pretty group >/dev/null' with 31k groups:
0.74s   (existing code)
102.17s (returning an array)
0.79s   (with this patch)

We append arrays in various places, so it seems nice to make this generally
fast.
2022-12-01 18:13:21 +01:00
Zbigniew Jędrzejewski-Szmek
b0eeb94588 shared/json: make it possible to specify source name for strings too, add tests
The source would be set implicitly when parsing from a named file. But
it's useful to specify the source also for cases where we're parsing a
ready string. I noticed the lack of this API when trying to write tests,
but it seems generally useful to be specify a source name when parsing
things.
2022-12-01 18:02:06 +01:00
Zbigniew Jędrzejewski-Szmek
b570204a97 bootctl: make --json output normal json
We would output a sequence of concatenated JSON strings. 'jq' accepts such
output without fuss, and can even automatically build an array with --slurp/-s.
Nevertheless, parsing this format is more effort for the reader, since it's not
"standard JSON". E.g. Python's json module cannot do this out-of-the-box, but
needs some loop with json.JSONDecoder.raw_decode() and then collecting the
objects into an array. Such streaming output make sense in case of logs, where
we stream the output and it has no predefined length. But here we expect at
most a few dozen entries, so it's nicer to write normal JSON that is trivial to
parse.

I'm treating this is a bugfix and not attempting to provide compatibility
backwards. I don't think the previous format was seeing much use, and it's
trivial to adapt to the new one.
2022-12-01 18:00:49 +01:00
Lennart Poettering
2e3944b872 blkid-util: define enum for blkid_do_safeprobe() return values
libblkid really should define an enum for this on its own, but it
currently doesn't and returns literal numeric values. Lets make this
more readable by adding our own symbolic names via an enum.
2022-12-01 15:43:26 +01:00
Lennart Poettering
ef1f0a14fa tree-wide: use errno_or_else() more, instead of homegrown checks 2022-12-01 15:42:46 +01:00
Daan De Meyer
003cb0e046
Merge pull request #25579 from DaanDeMeyer/copy-graceful-symlinks
repart: Ignore copy failures for unsupported file types
2022-12-01 13:47:14 +01:00
Daan De Meyer
336ae0e71d repart: Ignore copy failures for unsupported file types
e.g. vfat doesn't support symlinks, sockets, fifos, etc so let's ignore
any copy failures related to unsupported file types when populating
filesystems.
2022-12-01 12:14:35 +01:00
Lennart Poettering
f0c24a0ed8
Merge pull request #25554 from enr0n/follow-on-25509
oomd: only check prefix_uid when uid != 0
2022-12-01 12:04:23 +01:00
Lennart Poettering
73d88b806b dissect: rework DISSECT_IMAGE_ADD_PARTITION_DEVICES + DISSECT_IMAGE_OPEN_PARTITION_DEVICES
Curently, these two flags were implied by dissect_loop_device(), but
that's not right, because this means systemd-gpt-auto-generator will
dissect the root block device with these flags set and that's not
desirable: the generator should not cause the partition devices to be
created (we don't intend to use them right-away after all, but expect
udev to find/probe them first, and then mount them though .mount units).
And there's no point in opening the partition devices, since we do not
intend to mount them via fds either.

Hence, rework this: instead of implying the flags, specify them
explicitly.

While we are at it, let's also rename the flags to make them more
descriptive:

DISSECT_IMAGE_MANAGE_PARTITION_DEVICES becomes
DISSECT_IMAGE_ADD_PARTITION_DEVICES, since that's really all this does:
add the partition devices via BLKPG.

DISSECT_IMAGE_OPEN_PARTITION_DEVICES becomes
DISSECT_IMAGE_PIN_PARTITION_DEVICES, since we not only open the devices,
but keep the devices open continously (i.e. we "pin" them).

Also, drop the DISSECT_IMAGE_BLOCK_DEVICE combination flag, since it is
misleading, i.e. it suggests it was appropriate to specify on all
dissected blocking devices, but that's precisely not the case, see the
systemd-gpt-auto-generator case. My guess is that the confusion around
this was actually the cause for this bug we are addressing here.

Fixes: #25528
2022-12-01 11:32:30 +01:00
Ray Strode
9fe26523a1 terminal-util: Set OPOST when setting ONLCR
reset_terminal_fd sets certain minimum required terminal attributes
that systemd relies on.

One of those attributes is `ONLCR` which ensures that when a new line
is sent to the terminal, that the cursor not only moves to the next
line, but also moves to the very beginning of that line.

In order for `ONLCR` to work, the terminal needs to perform output
post-processing. That requires an additional attribute, `OPOST`,
which reset_terminal_fd currently fails to ensure is set.

In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
it's not an issue, but it could be a problem if, e.g., the terminal was
put in raw mode by a program and the program unexpectedly died before
restoring settings.

This commit ensures when `ONLCR` is set `OPOST` is set too, which is
the only thing that really makes sense to do.
2022-12-01 11:29:21 +01:00
Daan De Meyer
494f7fc096 copy: Add COPY_GRACEFUL_WARN
When copying between filesystems, sometimes the target filesystem
might not support symlinks/fifos/sockets/... and we want to log and
ignore  any failures to copy such files when copying. Let's introduce
a new flag to enable this behavior.
2022-12-01 10:03:31 +01:00