diff options
author | Luke T. Shumaker <lukeshu@parabola.nu> | 2024-08-22 01:29:10 +0200 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@parabola.nu> | 2024-09-07 18:18:35 +0200 |
commit | dc3223919f663b7c8b8d8d1d6072b4487df7709b (patch) | |
tree | b4192fbe82e73926a6e8bbde1d3e0e1ce272dfad /src/nspawn/nspawn-register.c | |
parent | nspawn: register_machine() and allocate_scope() bools to flags (diff) | |
download | systemd-dc3223919f663b7c8b8d8d1d6072b4487df7709b.tar.xz systemd-dc3223919f663b7c8b8d8d1d6072b4487df7709b.zip |
nspawn: enable FUSE in containers
Linux kernel v4.18 (2018-08-12) added user-namespace support to FUSE, and
bumped the FUSE version to 7.27 (see: da315f6e0398 (Merge tag
'fuse-update-4.18' of
git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse, Linus Torvalds,
2018-06-07). This means that on such kernels it is safe to enable FUSE in
nspawn containers.
In outer_child(), before calling copy_devnodes(), check the FUSE version to
decide whether enable (>=7.27) or disable (<7.27) FUSE in the container. We
look at the FUSE version instead of the kernel version in order to enable FUSE
support on older-versioned kernels that may have the mentioned patchset
backported ([as requested by @poettering][1]). However, I am not sure that
this is safe; user-namespace support is not a documented part of the FUSE
protocol, which is what FUSE_KERNEL_VERSION/FUSE_KERNEL_MINOR_VERSION are meant
to capture. While the same patchset
- added FUSE_ABORT_ERROR (which is all that the 7.27 version bump
is documented as including),
- bumped FUSE_KERNEL_MINOR_VERSION from 26 to 27, and
- added user-namespace support
these 3 things are not inseparable; it is conceivable to me that a backport
could include the first 2 of those things and exclude the 3rd; perhaps it would
be safer to check the kernel version.
Do note that our get_fuse_version() function uses the fsopen() family of
syscalls, which were not added until Linux kernel v5.2 (2019-07-07); so if
nothing has been backported, then the minimum kernel version for FUSE-in-nspawn
is actually v5.2, not v4.18.
Pass whether or not to enable FUSE to copy_devnodes(); have copy_devnodes()
copy in /dev/fuse if enabled.
Pass whether or not to enable FUSE back over fd_outer_socket to run_container()
so that it can pass that to append_machine_properties() (via either
register_machine() or allocate_scope()); have append_machine_properties()
append "DeviceAllow=/dev/fuse rw" if enabled.
For testing, simply check that /dev/fuse can be opened for reading and writing,
but that actually reading from it fails with EPERM. The test assumes that if
FUSE is supported (/dev/fuse exists), then the testsuite is running on a kernel
with FUSE >= 7.27; I am unsure how to go about writing a test that validates
that the version check disables FUSE on old kernels.
[1]: https://github.com/systemd/systemd/issues/17607#issuecomment-745418835
Closes #17607
Diffstat (limited to 'src/nspawn/nspawn-register.c')
-rw-r--r-- | src/nspawn/nspawn-register.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c index 855172c09c..52f7384468 100644 --- a/src/nspawn/nspawn-register.c +++ b/src/nspawn/nspawn-register.c @@ -15,6 +15,7 @@ static int append_machine_properties( sd_bus_message *m, + bool enable_fuse, CustomMount *mounts, unsigned n_mounts, int kill_signal, @@ -40,6 +41,12 @@ static int append_machine_properties( "char-pts", "rw"); if (r < 0) return bus_log_create_error(r); + if (enable_fuse) { + r = sd_bus_message_append(m, "(sv)", "DeviceAllow", "a(ss)", 1, + "/dev/fuse", "rw"); + if (r < 0) + return bus_log_create_error(r); + } for (j = 0; j < n_mounts; j++) { CustomMount *cm = mounts + j; @@ -200,6 +207,7 @@ int register_machine( r = append_machine_properties( m, + FLAGS_SET(flags, REGISTER_MACHINE_ENABLE_FUSE), mounts, n_mounts, kill_signal, @@ -320,6 +328,7 @@ int allocate_scope( r = append_machine_properties( m, + FLAGS_SET(flags, ALLOCATE_SCOPE_ENABLE_FUSE), mounts, n_mounts, kill_signal, |