]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/core/manager.c
manager: execute generators in a mount namespace "sandbox"
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Dec 2022 13:32:35 +0000 (14:32 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Dec 2022 21:12:44 +0000 (22:12 +0100)
commitca6ce62d2a437432082b5c6e5d4275d56055510f
tree134e8f1a48de72a6c42f01dbf1a7cfc88b8c7973
parent61ef30515b44c478cf1aa1155d5b306f09c9dc5a
manager: execute generators in a mount namespace "sandbox"

When generators are executed during early boot, /tmp might not be available
yet. This causes problems with bash, because here-docs don't work. Even
non-shell code can often assume that /tmp is available. This limitation is
known to trip up people, and when the code is tested on a "normal" system,
everything works.

We can solve this nicely, and get another small benefit, by making most of the
file system read-only and "punching holes" for some dirs that should be
writable. The generator code runs with full privileges and can do anything it
wants by writing appropriate systemd units, so it doesn't make much sense to do
any significant sandboxing around generators. But making root read-only is nice
because it can catch stupid mistakes where the generator tries to write to a
wrong path or something like that. We effectively also get a "private /tmp" for
the generators, which protects them against existing files in /tmp.

The path does the following:
when executing generators, we fork, and the child unshares root and makes
it recursively read-only, with the exception of /sys and /run. Error handling
is permissive — if some of this setup fails, we're in the same state as
before the patch.

Fixes #24430.
src/core/manager.c