Skip to content

idmapped bind mount on /dev with "ro": container fails to start with EROFS (follow-up to #3719 and #3876) #3941

Backlog

Description

@saku3

This is a follow-up note for two open PRs, #3719 (idmapped mounts) and #3876 (finalize_rootfs).

With #3719 , a container does not start when /dev is an idmapped bind mount with the ro option:

ERROR libcontainer::rootfs::symlink: failed to symlink kcore
ERROR libcontainer::process::init::process: failed to prepare rootfs err=Symlink(Syscall { source: IO(Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" }) })

mount_idmapped sets the mount attributes, including MOUNT_ATTR_RDONLY, on the detached mount before move_mount. After that prepare_rootfs creates the symlinks and device nodes in /dev, and the first of them fails with EROFS.

finalize_rootfs (#3876) defers the read-only flag of tmpfs mounts and /dev to finalize_rootfs, but it does so in the default branch of setup_mount. The idmap branch added by #3719 returns from setup_mount before that, so it is not covered.

Steps to Reproduce

setting idmapped mount to config.json

    {
      "destination": "/dev",
      "type": "bind",
      "source": "/var/tmp/dev-ro-idmap/devsrc",
      "options": [
        "rbind",
        "idmap",
        "ro"
      ]
    }
config.json
{
  "ociVersion": "1.0.2-dev",
  "root": {
    "path": "rootfs",
    "readonly": true
  },
  "mounts": [
    {
      "destination": "/proc",
      "type": "proc",
      "source": "proc"
    },
    {
      "destination": "/dev",
      "type": "bind",
      "source": "/var/tmp/dev-ro-idmap/devsrc",
      "options": [
        "rbind",
        "idmap",
        "ro"
      ]
    },
    {
      "destination": "/sys",
      "type": "sysfs",
      "source": "sysfs",
      "options": [
        "nosuid",
        "noexec",
        "nodev",
        "ro"
      ]
    },
    {
      "destination": "/sys/fs/cgroup",
      "type": "cgroup",
      "source": "cgroup",
      "options": [
        "nosuid",
        "noexec",
        "nodev",
        "relatime",
        "ro"
      ]
    }
  ],
  "process": {
    "terminal": false,
    "user": {
      "uid": 0,
      "gid": 0
    },
    "args": [
      "sh"
    ],
    "env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
      "TERM=xterm"
    ],
    "cwd": "/",
    "capabilities": {
      "bounding": [
        "CAP_KILL",
        "CAP_AUDIT_WRITE",
        "CAP_NET_BIND_SERVICE"
      ],
      "effective": [
        "CAP_KILL",
        "CAP_AUDIT_WRITE",
        "CAP_NET_BIND_SERVICE"
      ],
      "permitted": [
        "CAP_KILL",
        "CAP_AUDIT_WRITE",
        "CAP_NET_BIND_SERVICE"
      ]
    },
    "rlimits": [
      {
        "type": "RLIMIT_NOFILE",
        "hard": 1024,
        "soft": 1024
      }
    ],
    "noNewPrivileges": true
  },
  "hostname": "youki",
  "annotations": {},
  "linux": {
    "uidMappings": [
      {
        "containerID": 0,
        "hostID": 200000,
        "size": 65536
      }
    ],
    "gidMappings": [
      {
        "containerID": 0,
        "hostID": 200000,
        "size": 65536
      }
    ],
    "resources": {
      "devices": [
        {
          "allow": false,
          "access": "rwm"
        }
      ]
    },
    "namespaces": [
      {
        "type": "user"
      },
      {
        "type": "pid"
      },
      {
        "type": "network"
      },
      {
        "type": "ipc"
      },
      {
        "type": "uts"
      },
      {
        "type": "mount"
      },
      {
        "type": "cgroup"
      }
    ],
    "maskedPaths": [
      "/proc/acpi",
      "/proc/asound",
      "/proc/kcore",
      "/proc/keys",
      "/proc/latency_stats",
      "/proc/timer_list",
      "/proc/timer_stats",
      "/proc/sched_debug",
      "/sys/firmware",
      "/proc/scsi"
    ],
    "readonlyPaths": [
      "/proc/bus",
      "/proc/fs",
      "/proc/irq",
      "/proc/sys",
      "/proc/sysrq-trigger"
    ]
  }
}
$ mkdir -p /var/tmp/dev-ro-idmap/bundle/rootfs /var/tmp/dev-ro-idmap/devsrc
$ chmod 0777 /var/tmp/dev-ro-idmap/devsrc
$ cd /var/tmp/dev-ro-idmap/bundle
$ docker export $(docker create busybox) | tar -C rootfs -xvf -

$ sudo youki run container

Activity

  1. added this to the v1.0.0 milestone on Nov 25, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions