Skip to contentSkip to conversation

fuse/libfuse/e2fsprogs/etc: containerize ext4 for safer operation

PATCH Superseded Darrick J. Wong 4 participants 51 messages Apr 22 – Apr 29 Page 2 of 2

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#47 lore raw

RFC PATCH 3/4 fuseiso: enable systemd service mode

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Enable use of fuseiso as a contained fuse service. This is a patch against the Debian package, which was ported to fuse3.

---
 src/isofs.h             |    2 -
 configure.in            |  148 +++++++++++++++++++++++++++++++++++++++++++++++
 src/Makefile.am         |   16 +++++
 src/fuseiso.c           |  134 +++++++++++++++++++++++++++++++++++++------
 src/fuseiso.socket.in   |   16 +++++
 src/[email protected] |  102 ++++++++++++++++++++++++++++++++
 6 files changed, 398 insertions(+), 20 deletions(-)
 create mode 100644 src/fuseiso.socket.in
 create mode 100644 src/[email protected]
src/isofs.h +1 -1
index 3755e886c9ccc2..b765baf209d77e 100644
@@ -25,7 +25,7 @@
 #include <linux/iso_fs.h>
 #include <linux/rock.h>
 
-#define FUSE_USE_VERSION 314
+#define FUSE_USE_VERSION 319
 #include <fuse.h>
 
 typedef struct _isofs_context {
configure.in +147 -1

154 lines not on this page · raw message

src/Makefile.am +16 -0
index cb05da8cd1653c..97cded13a71c96 100644
@@ -8,4 +8,20 @@ INCLUDES= $(all_includes)
 fuseiso_LDFLAGS = $(all_libraries) $(FUSE_LIBS) $(GLIB_LIBS) -lz
 noinst_HEADERS = isofs.h
 
+if HAVE_FUSEISO_FUSE_SERVICE
+bin_SCRIPTS = fuseiso.socket [email protected]
+endif
+
+fuseiso.socket: fuseiso.socket.in
+	sed \
+		-e "s|@FUSE3_SERVICE_SOCKET_DIR@|$(fuse_service_socket_dir)|g" \
+		-e "s|@FUSE3_SERVICE_SOCKET_PERMS@|$(fuse_service_socket_perms)|g" \
+		< $< > $@
+
[email protected]: [email protected]
+	sed -e "s|@BINDIR@|$(bindir)|g" \
+		   < $< > $@
+
+EXTRA_PROGRAMS=$(SERVICE_FILES)
+
 AM_CFLAGS = -D_FILE_OFFSET_BITS=64 $(FUSE_CFLAGS) $(GLIB_CFLAGS) -Wall
src/fuseiso.c +116 -18

189 lines not on this page · raw message

src/fuseiso.socket.in new file +16 -0
new file mode 100644
index 00000000000000..a2ea11e408fa81
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2026 Oracle.  All Rights Reserved.
+# Author: Darrick J. Wong <[email protected]>
+[Unit]
+Description=Socket for fuseiso Service
+
+[Socket]
+ListenSequentialPacket=@FUSE3_SERVICE_SOCKET_DIR@/isofs
+ListenSequentialPacket=@FUSE3_SERVICE_SOCKET_DIR@/iso9660
+Accept=yes
+SocketMode=@FUSE3_SERVICE_SOCKET_PERMS@
+RemoveOnStop=yes
+
+[Install]
+WantedBy=sockets.target
src/[email protected] new file +102 -0

102 lines not on this page · raw message

#48 lore raw

RFC PATCH 4/4 httpdirfs: enable fuse systemd service mode

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Enable use of httpdirfs as a contained systemd service.

---
 src/fuse_local.h          |    2 +
 meson.build               |   26 ++++++++++++
 src/fuse_local.c          |   62 ++++++++++++++++++++++++++++
 src/httpdirfs.socket.in   |   16 +++++++
 src/[email protected] |   99 +++++++++++++++++++++++++++++++++++++++++++++
 src/main.c                |    7 +++
 6 files changed, 210 insertions(+), 2 deletions(-)
 create mode 100644 src/httpdirfs.socket.in
 create mode 100644 src/[email protected]
src/fuse_local.h +2 -0
index 9f459c1e1a8151..69157cd3fa7883 100644
@@ -9,4 +9,6 @@
 /* Initialise fuse */
 int fuse_local_init(int argc, char **argv);
 
+int fuse_local_main(int argc, char *argv[], int (*main)(int argc, char **argv));
+
 #endif
meson.build +26 -0
index 431a1547b20bfc..5d7c4721bb756c 100644
@@ -41,6 +41,32 @@ expat_dep = dependency('expat')
 openssl_dep = dependency('openssl')
 execinfo_dep = cc.find_library('execinfo', required: false)
 
+# Check for systemd support
+systemd_dep = dependency('systemd', required: false)
+if systemd_dep.found()
+   systemd_system_unit_dir = systemd_dep.get_variable(pkgconfig: 'systemd_system_unit_dir', default_value: '')
+   libfuse_service_socket_dir = fuse_dep.get_variable(pkgconfig: 'service_socket_dir', default_value: '')
+   libfuse_service_socket_perms = fuse_dep.get_variable(pkgconfig: 'service_socket_perms', default_value: '')
+endif
+
+private_cfg = configuration_data()
+if systemd_system_unit_dir == '' or libfuse_service_socket_dir == ''
+  warning('systemd service support will not be built')
+else
+   private_cfg.set('SYSTEMD_SYSTEM_UNIT_DIR', systemd_system_unit_dir)
+   private_cfg.set('LIBFUSE_SERVICE_SOCKET_DIR', libfuse_service_socket_dir)
+   private_cfg.set('LIBFUSE_SERVICE_SOCKET_PERMS', libfuse_service_socket_perms)
+   private_cfg.set('BINDIR', get_option('bindir'))
+   c_args += [ '-DHAVE_HTTPDIR_FUSE_SERVICE' ]
+
+   configure_file(input: 'src/[email protected]',
+                  output: '[email protected]',
+                  configuration: private_cfg)
+   configure_file(input: 'src/httpdirfs.socket.in',
+                  output: 'httpdirfs.socket',
+                  configuration: private_cfg)
+endif
+
 httpdirfs = executable('httpdirfs',
     srcs,
     dependencies : [gumbo_dep, libcurl_dep, fuse_dep, uuid_dep, expat_dep, openssl_dep, execinfo_dep],
src/fuse_local.c +61 -1

79 lines not on this page · raw message

src/httpdirfs.socket.in new file +16 -0
new file mode 100644
index 00000000000000..ae587646ad707e
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2026 Oracle.  All Rights Reserved.
+# Author: Darrick J. Wong <[email protected]>
+[Unit]
+Description=Socket for httpdirfs Service
+
+[Socket]
+ListenSequentialPacket=@LIBFUSE_SERVICE_SOCKET_DIR@/http
+ListenSequentialPacket=@LIBFUSE_SERVICE_SOCKET_DIR@/https
+Accept=yes
+SocketMode=@LIBFUSE_SERVICE_SOCKET_PERMS@
+RemoveOnStop=yes
+
+[Install]
+WantedBy=sockets.target
src/[email protected] new file +99 -0

99 lines not on this page · raw message

src/main.c +6 -1
index c93162a9bf4129..4c23d4e5d4419f 100644
@@ -16,7 +16,7 @@ void parse_config_file(char ***argv, int *argc);
 
 static char *config_path = NULL;
 
-int main(int argc, char **argv)
+static int __main(int argc, char **argv)
 {
     /*
      * Automatically print help if not enough arguments are supplied
@@ -114,6 +114,11 @@ activate Sonic mode.\n");
     return 0;
 }
 
+int main(int argc, char *argv[])
+{
+	return fuse_local_main(argc, argv, __main);
+}
+
 static char *get_XDG_CONFIG_HOME(void)
 {
     const char *default_config_subdir = "/.config";
#49 lore raw
In reply to Darrick J. Wong
Quoted 63 lines · Darrick J. Wong

Hi everyone,

This *would have been* the eight public draft of the gigantic patchset to connect the Linux fuse driver to fs-iomap for regular file IO operations to and from files whose contents persist to locally attached storage devices.

However, the previous submission was too large, and I didn't even send half the patches! I have therefore split the work into two sections. This first section covers setting up fuse servers to run as contained systemd services; I previously sent only the libfuse changes, without any of the surrounding pieces. Now I'm ready to send them all.

To summarize this patchbomb: fuse servers can now run as non-root users, with no privilege, no access to the network or hardware, etc. The only connection to the outside is an ephemeral AF_UNIX socket. The process on the other end is a helper program that acquires resources and calls fsmount().

Why would you want to do that? Most filesystem drivers are seriously vulnerable to metadata parsing attacks, as syzbot has shown repeatedly over almost a decade of its existence. Faulty code can lead to total kernel compromise, and I think there's a very strong incentive to move all that parsing out to userspace where we can containerize the fuse server process. Runtime filesystem metadata parsing is no longer a privileged (== risky) operation.

The consequences of a crashed driver is a dead mount, instead of a crashed or corrupt OS kernel.

Note that contained fuse filesystem servers are no faster than regular fuse. The redesign of the fuse IO path via iomap will be the subject of the second patchbomb. The containerization code only requires changes to libfuse and is ready to go today.

Since the seventh submission, I have made the following changes:

1) Added a couple of simple fuse service drivers to the example code

2) Adapted fuservicemount to be runnable as a setuid program so that unprivileged users can start up a containerized filesystem driver

3) Fixed some endianness handling errors in the socket protocol between the new mount helper and the fuse server

4) Added a high level fuse_main function so that fuse servers that use the high level api can containerize without a total rewrite

5) Adapted mount.fuse to call the new mount helper code so that mount -t fuse.XXX can try to start up a contained server

6) Cleaned up a lot of cppcheck complaints and refactored a bunch of repetitious code

7) Started using codex to try to find bugs and security problems with the new mount helper

There are a few unanswered questions:

a. How to integrate with the SYNC_INIT patches that Bernd is working on merging into libfuse

Quoted 6 lines

b. If /any/ of the new fsopen/fsconfig/fsmount/move_mount calls fail, do we fall back to the old mount syscall? Even after printing errors?

c. Are there any Linux systems where some inetd implementation can actually handle AF_UNIX sockets? Does it make sense to try to do the service isolation without the convenience of systemd directives?

A large part of the world is running container workloads on kubernetes and my understanding is that k8s does not mix well with systemd.

We have successfully used the fusetmount3-proxy [1] approach by Naoki MATSUMOTO as a way for unprivileged containers to delegate fuse mount by a (non-systemd) service, running in another container.

[1] https://github.com/pfnet-research/meta-fuse-csi-plugin#fusermount3-proxy-modified-fusermount3-approach

The README says that sshfs, s3fs and other high profile fuse fs have been tested with this approach and they do not require any rebuild.

So it bears the question...

Quoted 9 lines

d. meson/autoconf/cmake are a pain to deal with, hopefully the changes I made are correct

I have also converted a handful more fuse servers (fat, exfat, iso, http) to the new service architecture so that I can run a (virtual) Debian system with EFI completely off of containerized fuse servers. These will be sent at the end.

... what is the added value of rebuilding those packages with systemd service support?

I am not implying that there is no added value, I just am not well versed in the world of container and system services.

Thanks,
Amir.

#50 lore raw
Quoted 95 lines · Amir Goldstein
Quoted 63 lines · Darrick J. Wong

Hi everyone,

This *would have been* the eight public draft of the gigantic patchset to connect the Linux fuse driver to fs-iomap for regular file IO operations to and from files whose contents persist to locally attached storage devices.

However, the previous submission was too large, and I didn't even send half the patches! I have therefore split the work into two sections. This first section covers setting up fuse servers to run as contained systemd services; I previously sent only the libfuse changes, without any of the surrounding pieces. Now I'm ready to send them all.

To summarize this patchbomb: fuse servers can now run as non-root users, with no privilege, no access to the network or hardware, etc. The only connection to the outside is an ephemeral AF_UNIX socket. The process on the other end is a helper program that acquires resources and calls fsmount().

Why would you want to do that? Most filesystem drivers are seriously vulnerable to metadata parsing attacks, as syzbot has shown repeatedly over almost a decade of its existence. Faulty code can lead to total kernel compromise, and I think there's a very strong incentive to move all that parsing out to userspace where we can containerize the fuse server process. Runtime filesystem metadata parsing is no longer a privileged (== risky) operation.

The consequences of a crashed driver is a dead mount, instead of a crashed or corrupt OS kernel.

Note that contained fuse filesystem servers are no faster than regular fuse. The redesign of the fuse IO path via iomap will be the subject of the second patchbomb. The containerization code only requires changes to libfuse and is ready to go today.

Since the seventh submission, I have made the following changes:

1) Added a couple of simple fuse service drivers to the example code

2) Adapted fuservicemount to be runnable as a setuid program so that unprivileged users can start up a containerized filesystem driver

3) Fixed some endianness handling errors in the socket protocol between the new mount helper and the fuse server

4) Added a high level fuse_main function so that fuse servers that use the high level api can containerize without a total rewrite

5) Adapted mount.fuse to call the new mount helper code so that mount -t fuse.XXX can try to start up a contained server

6) Cleaned up a lot of cppcheck complaints and refactored a bunch of repetitious code

7) Started using codex to try to find bugs and security problems with the new mount helper

There are a few unanswered questions:

a. How to integrate with the SYNC_INIT patches that Bernd is working on merging into libfuse

Quoted 6 lines

b. If /any/ of the new fsopen/fsconfig/fsmount/move_mount calls fail, do we fall back to the old mount syscall? Even after printing errors?

c. Are there any Linux systems where some inetd implementation can actually handle AF_UNIX sockets? Does it make sense to try to do the service isolation without the convenience of systemd directives?

A large part of the world is running container workloads on kubernetes and my understanding is that k8s does not mix well with systemd.

We have successfully used the fusetmount3-proxy [1] approach by Naoki MATSUMOTO as a way for unprivileged containers to delegate fuse mount by a (non-systemd) service, running in another container.

[1] https://github.com/pfnet-research/meta-fuse-csi-plugin#fusermount3-proxy-modified-fusermount3-approach

The README says that sshfs, s3fs and other high profile fuse fs have been tested with this approach and they do not require any rebuild.

So it bears the question...

Quoted 9 lines

d. meson/autoconf/cmake are a pain to deal with, hopefully the changes I made are correct

I have also converted a handful more fuse servers (fat, exfat, iso, http) to the new service architecture so that I can run a (virtual) Debian system with EFI completely off of containerized fuse servers. These will be sent at the end.

Quoted 5 lines

... what is the added value of rebuilding those packages with systemd service support?

I am not implying that there is no added value, I just am not well versed in the world of container and system services.

From the discussion of fusermount3-proxy:
https://github.com/pfnet-research/meta-fuse-csi-plugin/raw/main/assets/inside-fusermount3-proxy.png
or
https://tech.preferred.jp/wp-content/uploads/2023/11/figures-6.png

Their approach spins up a second "CSI driver pod" (aka another contained environment) to run fusermount3 with CAP_SYS_ADMIN. This means that the "user pod" has to be able to access all resources necessary to mount the filesystem, e.g. virtual disk images, actual block devices, networking, etc. Once the fuse server is running, it's obviously still running in the same environment as the user pod.

With my approach, resource acquisition can be done up front, and the fuse server can run in a very sealed environment. No block devices, no networking, no /home, and the minimal root filesystem. It's systemd, so you can be more permissive with the environment if you'd like.

The downside is that requires code changes in the fuse server because open() won't work if you've trimmed the directory tree. Hmm, there's not much provision for sockets, maybe I need to extend the protocol.

A big roadblock: none of that code can be merged into libfuse because it's all Apache 2.0 licensed, whereas libfuse is GPL2/LGPL2. LLMwash notwithstanding.

--D