Skip to content

Add a mkcomposefs+mount service #409

Open

Description

@cgwalters

In order to be able to use composefs everywhere we should
support a mechanism for runtimes like podman/flatpak to
be able to safely mount a composefs as non-root. Privileges
for mounting EROFS are currently restricted to root for
security reasons. A decent solution for this problem is
basically "mkcomposefs --from-file + mount" as a (DBus/plain-socket) service.
This accepts the following arguments:

  • format version: string (e.g. "1.1")
  • textual composefs dump file: file descriptor (sealed memfd)
  • fsverity: bool
  • user namespace: file descriptor
  • mount namespace: file descriptor
  • composefs base directory: file descriptor
  • existing erofs: file descriptor (optional)

Steps taken

  • Generate an erofs from the dump file
  • if fsverity, enable fsverity on the erofs (and error if this is unsupported)
  • if "existing erofs" is passed, compare the fsverity digest of our generated version against the provided one. If the provided one matches, discard our copy and use the provided one - otherwise error.
  • enter the user & mount namespace of the target, and get a detached mount fd for it
  • Send the fd for the erofs and the detached mount fd back to the client (note in the existing erofs path, the returned erofs fd should be exactly the passed fd)

Caching

By passing back a fd for the erofs (and accepting as optional input again), we allow the caller to maintain their own cache mapping from e.g. OCI config -> erofs, and avoid creating new ones each time.

Access control

In practice, this service only really needs to be accessible IMO to logged in human users, so we could check the login state by querying systemd for its state via the pid of the caller.

For system services running as unprivileged users (e.g. httpd) I can't think of a good use case for this, so it'd probably make sense to deny access by default.

OTOH I have heard of people running podman as non-root via system users which I think is probably better done via just ensuring userns on system containers (ref podman-container-tools/podman#13728 ) but...if we did add access control those folks could just set require-login=false in /etc/mkmount-composefs.conf or whatever.

Actually or hmm...I bet instead of us implementing "check pid for login session" we could just make our socket accessible only to root by default, but have a bridge service which integrates with the login process and makes a socket accessible in /run/user/$uid/mkcomposefs.socket or so? Would need to dig at the details of this; there's some prior art in how we used ACLs to expose physical devices to unprivileged users too.

Other trackers

Activity

  1. added
    enhancement
    on Jan 24, 2025
  2. alexlarsson commented on Feb 11, 2025

    @alexlarsson
    Collaborator

    Is this truly safe though?

    For example, what if I create a dump file that maps a readable /a/file to /etc/shadow, then have the service mount (as root) the erofs+overlayfs, If i then read /a/file, will I be allowed to read the backing /etc/shadow? I don't actually think this will be allowed, but I'm not 100% sure.

    I would feel safer if all it did was mount the erofs image, however that is not gonna work, as you need to be root to properly mount the right kind of overlayfs for composefs to work.

  3. cgwalters commented on Feb 11, 2025

    @cgwalters
    ContributorAuthor

    I edited the proposal to include composefs base directory: file descriptor which was forgotten before, but is also important here. We could require that that base directory is owned by the user.

    Or maybe even more strictly, we require that the base directory have e.g. a system.composefs.objectdir extended attribute.

    I think then if we enforce that the overlayfs lookups don't follow symlinks (do they today? need to look) then we mostly mitigate that concern.


    A stronger fix here though would be mount option for overlayfs which ties it to the credentials associated with the user namespace or so?

  4. cgwalters commented on Apr 7, 2025

    @cgwalters
    ContributorAuthor

    I would feel safer if all it did was mount the erofs image, however that is not gonna work, as you need to be root to properly mount the right kind of overlayfs for composefs to work.

    It sounds like this is in progress of being fixed https://marc.info/?l=linux-unionfs&m=174289929624236&w=2

  5. cgwalters commented on Jan 19, 2026

    @cgwalters
    ContributorAuthor

    We already have FUSE implementations of composefs, and that's also viable here. In the medium term it's going to be quite interesting to see if FUSE continues to progress in increasing viability for more "production" use cases (ref https://lwn.net/Articles/1044432/).

  6. jluebbe commented on Jan 19, 2026

    @jluebbe
    Collaborator

    As I understood the issue, the blocker is that you can't mount an EROFS image from a user namespace and not so much related overlayfs.

    If that is correct, wouldn't it be enough to extract the erofs metadata image to a new tmpfs (in the user namespace) and use that as the overlayfs metadata layer instead of mounting the erofs image directly?

  7. jluebbe commented on Jan 19, 2026

    @jluebbe
    Collaborator

    I did some tests with mounting overlayfs in a container and it works fine on newer kernels if you use the userxattr mount option:

    $ podman run -it --privileged debian 
    root@c4581c4a93bf:/# mkdir /mnt/lower
    root@c4581c4a93bf:/# mkdir /mnt/data 
    root@c4581c4a93bf:/# mkdir /mnt/compose
    root@c4581c4a93bf:/# mount -t tmpfs tmpfs /mnt/lower
    root@c4581c4a93bf:/# mount -t tmpfs tmpfs /mnt/data 
    root@c4581c4a93bf:/# mount -t overlay composefs -o ro,lowerdir+=/mnt/lower,datadir+=/mnt/data,userxattr /mnt/compose
    root@c4581c4a93bf:/# umount /mnt/compose
    root@c4581c4a93bf:/# mount -t overlay composefs -o ro,lowerdir+=/mnt/lower,datadir+=/mnt/data,verity=require,userxattr /mnt/compose
    root@c4581c4a93bf:/# umount /mnt/compose

    The normal mount used by mount.composefs uses redirect_dir=on,metacopy=on, which fails with overlayfs: redirect_dir requires permission to access trusted xattrs in dmesg.

    According to https://docs.kernel.org/filesystems/overlayfs.html#data-only-lower-layers, metacopy=on is implictly enabled when specifying a data-only layer.

    So, extracting the erofs metadata image with the xattr namespace remapped from trusted. to user. should work in a user namespace and would seem to be usable as the overlayfs lowerdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions