Commit Graph
61138 Commits
Author SHA1 Message Date
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
Christian Brauner 2e776ed6c8 shared: use move_pivot_root() for services
Currently, services use mount_move_root() in order to setup the root
directory of services using a mount namespace. This relies on MS_MOVE
and chroot(). However, this has serious drawbacks even for relatively
simple mount propagation scenarios.

What systemd currently does is roughly equivalent to the following shell
code:

  unshare --mount --propagation=shared
  cd /
  mount --make-rslave /
  mkdir /new-root
  mount --rbind / /new-root
  cd /new-root
  mount --move /new-root /
  chroot .

This looks simple enough but has the consequence that two separate mount
trees exist for the lifetime of the service. The first one was created
when the mount namespace was created, and the second one when a new
mount for the rootfs was created. The first mount tree sticks around as
a shadow mount tree. Both mount trees are dependent mounts with the host
rootfs as their dominating mount.

Now, when mount propagation is triggered by the host by e.g.,

   mount --bind /opt /mnt

it means that two propagation events are generated. I'm skipping over
the exact kernel details as they aren't that important. The gist is that
for every propagation event that is generated a second one is generated
for the shadow mount tree. In other words, the kernel creates two copies
for each mount that is propagated instead of one.

This isn't necessary. We can simply change the sequence above to:

  unshare --mount --propagation=shared
  cd /
  mount --make-rslave /
  mkdir /new-root
  # stash fd to old rootfs
  # stash fd to new rootfs
  mount --rbind / /new-root
  mkdir /new-root
  cd /new-root
  pivot_root . .
  # new root is tucked under old root
  # chdir into old rootfs via stashed fd
  umount -l /old-root

The pivot_root allows us to get rid of the old mount tree that was
created when the mount namespace was created. So after this sequence
only one mount tree is alive. Plus, it's safer and nicer. Moving mounts
isn't pleasnt.

This patch doesn't convert nspawn yet as the requirements are more
tricky given that it wants to preserve the rootfs as a shared mount
which goes against pivot_root() requirements.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
2022-11-24 10:58:26 +01:00
Yu Watanabe 00a60eaf5f Merge pull request #25483 from poettering/ppoll-usec-eintr
ppoll() + EINTR fixes
2022-11-24 09:42:48 +09:00
Michal Sekletar 88e4bfa62b core: add possibility to not track certain unit types 2022-11-24 09:28:22 +09:00
Luca Boccassi 80d95fcd6e portable: add a few more useful debug log messages
When attaching and /etc/systemd/system.attached can't be created or used
(eg: dead symlink) the logs are pretty much useless as even at debug
level there's no indication of what is going wrong.
Add some debug logs, and return a more specific error string over D-Bus.
2022-11-23 23:02:07 +01:00
Daan De Meyer 3f9b0e1343 Revert "find-esp: Relax filesystem root directory check"
This reverts commit d91a5f6481.

This is the wrong approach as we don't detect the UUID and devid
of valid ESP/XBOOTLDR partitions.
2022-11-23 21:22:07 +01:00
Bernd Steinhauser f5ae7f4c77 hwdb: remove fuzz and deadzone for Simucube wheel bases.
For these devices the axes are setup via a special
configuration tool. udev should not apply additional
fuzz or deadzone.

Reference for the product IDs:
https://granitedevices.com/wiki/Simucube_product_USB_interface_documentation
This also indicates that there are a total of 8 axes.
2022-11-23 21:18:55 +01:00
Lennart Poettering 2ed2c52ace Merge pull request #25486 from keszybz/kernel-install-header
Add "File created by …" header to BLS entries
2022-11-23 17:36:44 +01:00
Zbigniew Jędrzejewski-Szmek ca4249847b TODO: add item about mnt_fstype_is_netfs() 2022-11-23 12:43:28 +01:00
Zbigniew Jędrzejewski-Szmek 0be160136e kernel-install: add header to generate entry files
I was looking at a bug in bugzilla about some boot loader issue, and it was
hard to say if the boot entry files were generated by our plugin or something
else. Add a header to make this clear.

kernel-install invokes the plugins via absolute path always, so $0 gives as
the full path the location where the plugin is installed. This is what we want:

  title      Fedora Linux 37 (Workstation Edition)
  # Boot Loader Specification type#1 entry
  # File created by /usr/lib/kernel/install.d/90-loaderentry.install (systemd 252-409-g5028904^)
2022-11-23 10:14:25 +01:00
Daan De Meyer d91a5f6481 find-esp: Relax filesystem root directory check
When relaxed checks are requested, let's not require the efi/xbootldr
directory to be the root of the filesystem. When building images, image
builders might install all efi/xbootldr files to a regular directory
first before packing them up into a partition. To allow bootctl to be
used in such scenarios to install systemd-boot, we need to relax the
fsroot check.
2022-11-23 09:20:10 +01:00
Luca Boccassi 0dce448bbc repart: respect --discard=no also for block devices
It's only used to avoid BLKDISCARD on individual partitions at the moment.
It can take a lot of time to run on very slow devices, so avoid it for
them too.
2022-11-23 01:33:26 +01:00
Jason A. Donenfeld da403fd38a Update changelog with latest sd-boot, sd-stub, and bootctl changes 2022-11-23 01:33:05 +01:00
Jason A. Donenfeld 0a1d8ac77a stub: handle random seed like sd-boot does
sd-stub has an opportunity to handle the seed the same way sd-boot does,
which would have benefits for UKIs when sd-boot is not in use. This
commit wires that up.

It refactors the XBOOTLDR partition discovery to also find the ESP
partition, so that it access the random seed there.
2022-11-23 00:56:45 +01:00
Lennart Poettering 0c14c45e5c sd-event: reenable epoll_pwait2()
This reenables epoll_pwait2() use, i.e. undoes the effect of
39f756d3ae.

Instead of just reverting that, this PR will change things so that we
strictly rely on glibc's new epoll_pwait2() wrapper (which was added
earlier this year), and drop our own manual fallback syscall wrapper.
That should nicely side-step any issues with correct syscall wrapping
definitions (which on some arch seem not to be easy, given the sigset_t
size final argument), by making this a glibc problem, not ours.

Given that the only benefit this delivers are time-outs more granular
than msec, it shouldn't really matter that we'll miss out on support
for this on systems with older glibcs.
2022-11-23 00:54:23 +01:00
Daan De Meyer c9bb7438db Merge pull request #25485 from DaanDeMeyer/gpt-fix
gpt: Specify designator array sizes explicitly
2022-11-22 22:29:50 +01:00
Zbigniew Jędrzejewski-Szmek 04fea8407c kernel-install: make 90-loadentry.install templated
It's a bit annoying that this causes so much churn, but I don't see a different
way to do this.
2022-11-22 16:12:09 +01:00
Daan De Meyer df655bf34c gpt: Drop PARTITION_LINUX_GENERIC and PARTITION_USER_HOME
These don't have an inherent purpose, and aren't used throughout
the codebase, so let's simplify things and remove these.

See https://github.com/systemd/systemd/pull/24803#discussion_r1028190421
for more information.
2022-11-22 15:59:50 +01:00
Daan De Meyer 3cde36ffa3 gpt: Specify designator array sizes explicitly
Avoid users accidentally accessing uninitialized memory by always
making sure the array size covers all possible enum values.
2022-11-22 15:53:02 +01:00
Lennart Poettering ffbcc8d423 io-util: document EINTR situation a bit 2022-11-22 15:23:34 +01:00
Luca Boccassi d4b3ae65f3 Merge pull request #25477 from yuwata/network-wifi-reconfigure-on-connect
network: wifi: try to reconfigure when connected
2022-11-22 13:37:15 +01:00
Zbigniew Jędrzejewski-Szmek 70b9ea26b6 man/journalctl: mention systemd-cat, make the description more direct
We said "query the journal". This is true but also very generic. Let's say
"print log entries from the journal" instead, so that users who are looking for
"logging" are more likely to figure out that the journalctl is the tool for
them.

Also, mention systemd-journal-remote.service which can write the journal too.
And give some hints how to figure out how to write *to* the journal.
2022-11-22 13:31:04 +01:00
Lennart Poettering 22ecfa8312 utmp-wtmp: handle EINTR gracefully when waiting to write to tty 2022-11-22 13:11:04 +01:00
Lennart Poettering 80b780ba17 utmp-wtmp: fix error in case isatty() fails 2022-11-22 13:10:29 +01:00
Lennart Poettering f3d9278f38 homed: handle EINTR gracefully when waiting for device node 2022-11-22 13:09:53 +01:00
Lennart Poettering 6d66a22168 resolved: handle -EINTR returned from fd_wait_for_event() better
We might get signals for various reasons (for example, somebody asking
us to reload caches via a signal), hence let's handle this gracefully.
2022-11-22 13:09:17 +01:00
Lennart Poettering 6985878533 sd-netlink: handle EINTR from poll() gracefully, as success 2022-11-22 13:08:41 +01:00
Lennart Poettering 6976bf5cd6 varlink: also handle EINTR gracefully when waiting for EIO via ppoll() 2022-11-22 13:08:05 +01:00
Lennart Poettering 7c75f34131 stdio-bridge: don't be bothered with EINTR
We handle signals via signal handlers, hence no need to be concerned
about EINTR.
2022-11-22 13:07:27 +01:00
Lennart Poettering 3022916b4d sd-bus: handle -EINTR return from bus_poll()
In sd_bus_wait(), let's convert EINTR to a return code of 0, thus asking
the caller do loop again and enter sd_bus_process() again (which will
not find any queued events). This way we'll not return an error on
something that isn't really an error. This should typically make sure
things are properly handled by the caller, magically, without eating up
the event entirely, and still giving the caller time to run some code if
they want.
2022-11-22 13:06:50 +01:00
Lennart Poettering 108dfff2c7 tree-wide: modernizations with RET_NERRNO() 2022-11-22 13:05:29 +01:00
Anita Zhang 6ee27eb3ca man: update docs for MemoryZSwapMax= 2022-11-22 11:01:50 +01:00
Benjamin Fogle f4a49d1c58 resolved: Fix OpenSSL error messages 2022-11-22 16:04:45 +09:00
Yu Watanabe 8a4ad01a72 network: wifi: try to reconfigure when connected
Sometimes, RTM_NEWLINK message with carrier is received earlier than
NL80211_CMD_CONNECT. To make SSID= or other WiFi related settings in
[Match] section work, let's try to reconfigure the interface.

Fixes a bug introduced by 96f5f9ef9a.

Fixes #25384.
2022-11-22 14:44:26 +09:00
Yu Watanabe 4642371d07 network: drop unnecessary prototype
Follow-up for a39a9ac806.
2022-11-22 14:32:19 +09:00
Yu Watanabe 6ad17c31fb Merge pull request #25470 from keszybz/strv-extendf-format
Improve check for strv_extendf() format string
2022-11-22 12:27:37 +09:00
наб 848517ddd4 systemctl: edit: write override files as text files
Instead of stripping the newline off the final would-be line;
continue to reduce an empty-line-only file to an empty file, though

Closes #25303
2022-11-22 01:45:50 +01:00
Zbigniew Jędrzejewski-Szmek 5a65d2e535 bootctl: use grey-and-slash prefix for source in list too
Follow-up for 7851732262. The source
field also shows a path relative to $BOOT, so it should be displayed
in the same fashion.
2022-11-22 01:40:20 +01:00
Lennart Poettering e4cb147a2e udev: make sure auto-root logic also works in UKIs booted from XBOOTLDR
If no root= switch is specified on the kernel command line we'll use the
root disk on which the partition the LoaderDevicePartUUID efi var is
located – as long as that partition is an ESP. Let's slightly liberalize
that and also allow it if that partition is an XBOOTLDR partition. This
ensures that UKIs spawned directly from XBOOTLDR work the same as those
from the ESP.

(Note that this makes no difference if sd-boot is in the mix, as in that
case LoaderDevicePartUUID is always set to the ESP, as that's where
sd-boot is located, and sd-boot will set the var first, sd-stub will
only set it later if it#s not set yet.)
2022-11-22 01:32:51 +01:00
Lennart Poettering 7d1e61cab6 tree-wide: make constant ratelimit compound actually const
The compiler should recognize that these are constant expressions, but
let's better make this explicit, so that the linker can safely share the
initializations all over the place.
2022-11-22 01:30:55 +01:00
Jason A. Donenfeld 47b3e96647 boot: remove random-seed-mode
Now that the random seed is used on virtualized systems, there's no
point in having a random-seed-mode toggle switch. Let's just always
require it now, with the existing logic already being there to allow not
having it if EFI itself has an RNG. In other words, the logic for this
can now be automatic.
2022-11-22 01:30:03 +01:00
Luca Boccassi a0c544ee09 Merge pull request #25379 from keszybz/update-doc-links
Update doc links
2022-11-22 01:07:13 +01:00
Zbigniew Jędrzejewski-Szmek 400102ec91 basic/strv: check printf arguments to strv_extendf()
The second argument to _printf_() specifies where the arguments start. We need to
use 0 in two cases: when the args in a va_list and can't be checked, and with journald
logging functions which accept multiple format strings with multiple argument sets,
which the _printf_ checker does not understand. But strv_extendf() can be checked.
2022-11-21 20:08:50 +01:00
Zbigniew Jędrzejewski-Szmek 6457ce15be manager: fix format strings for trigger metadata
Fixup for c8bc7519c8.
2022-11-21 20:08:50 +01:00
Yu Watanabe 69b31b29a0 Merge pull request #25395 from poettering/tpm2-dlsym-assert
dlfcn-util: add static asserts ensuring our sym_xyz() func ptrs match …
2022-11-22 03:36:03 +09:00
Lennart Poettering 0d9e6d76be mkosi: pull in libbpf1 instead of legacy libbpf0 on debian 2022-11-21 16:13:29 +01:00
Lennart Poettering 7736a71fd2 dlfcn-util: add static asserts ensuring our sym_xyz() func ptrs match the types from the official headers
Make sure that the sym_xyz function pointers have the types that the
functions we'll assign them have.

And of course, this found a number of incompatibilities right-away, in
particular in the bpf hookup.

(Doing this will trigger deprecation warnings from libbpf. I simply
turned them off locally now, since we are well aware of what we are
doing in that regard.)

There's one return type fix (bool → int), that actually matters I think,
as it might have created an incompatibility on some archs.
2022-11-21 16:13:17 +01:00
Lennart Poettering 28795f2c13 update TODO 2022-11-21 15:14:22 +01:00
Jason A. Donenfeld a4eea6038c bootctl: install system token on virtualized systems
Removing the virtualization check might not be the worst thing in the
world, and would potentially get many, many more systems properly seeded
rather than not seeded. There are a few reasons to consider this:

- In most QEMU setups and most guides on how to setup QEMU, a separate
  pflash file is used for nvram variables, and this generally isn't
  copied around.

- We're now hashing in a timestamp, which should provide some level of
  differentiation, given that EFI_TIME has a nanoseconds field.

- The kernel itself will additionally hash in: a high resolution time
  stamp, a cycle counter, RDRAND output, the VMGENID uniquely
  identifying the virtual machine, any other seeds from the hypervisor
  (like from FDT or setup_data).

- During early boot, the RNG is reseeded quite frequently to account for
  the importance of early differentiation.

So maybe the mitigating factors make the actual feared problem
significantly less likely and therefore the pros of having file-based
seeding might outweigh the cons of weird misconfigured setups having a
hypothetical problem on first boot.
2022-11-21 15:13:26 +01:00