Skip to content

fix(docker): don't give app containers CAP_MKNOD - #598

Open
andrewdunndev wants to merge 1 commit into
games-on-whales:betafrom
andrewdunndev:fix/app-mknod-isolation
Open

andrewdunndev wants to merge 1 commit into
games-on-whales:betafrom
andrewdunndev:fix/app-mknod-isolation

Conversation

@andrewdunndev

Copy link
Copy Markdown
Contributor

Fixes #597.

Summary

App containers get c 13:* rwm and c <hidraw>:* rwm device cgroup rules, and the default profiles add MKNOD (Docker grants it anyway). Root in an app container can therefore create and open other sessions' input nodes, or the host's. This drops MKNOD from app containers.

The change

  • DockerAPI::exec takes bool privileged = false; the plug exec (mkdir, mknod, chmod, fake-udev) now runs privileged. The unplug exec is unchanged.
  • drop_mknod_capability() runs at create: it removes MKNOD/CAP_MKNOD from CapAdd and adds MKNOD to CapDrop. Containers with Privileged: true are left alone. The CapAdd strip matters on Podman, which rejects an add and a drop of the same capability.
  • MKNOD is removed from config.v7.toml, its include and the docs. Older config versions are untouched, since the strip at create covers them.
    Hotplug keeps working because Wolf's exec creates the node, so the container no longer needs the capability.

Testing

One AMD host, Podman and Docker 27.5.1 (Docker-in-Podman), scripted sessions, 3 reps per arm per engine, base is beta ac2461f.

check base fix
session 2 root: mknod + read session 1's pad 6/6 read 6/6 EPERM
mknod + open host power button / DualSense hidraw 6/6 opened 6/6 EPERM
pad hotplug, 3 pads, hidraw, unplug, SDL (as uid 1000) 3/3 3/3
old profile with MKNOD still starts, MKNOD gone 3/3 3/3

Both halves are needed: without the privileged exec no node is created, and without the CapDrop Docker keeps MKNOD.
Unit: 1120 assertions in 40 test cases pass (daemon [DOCKER] cases not run), plus a new case for the capability handling (8 assertions).

Limits

  • Not closed: with SYS_ADMIN, root can mount devtmpfs and open the nodes anyway; a stale node can also be read by the app user (API sessions). The plug exec runs binaries from the app rootfs with all capabilities, so a container could swap one: untested. A Wolf-supplied helper would be the follow-up.
  • Not tested: rootless, Steam, CapAdd: ["ALL"], native Docker. In the hotplug rows the event nodes were partly masked by stale nodes; a run with stale nodes removed first, and the js, mouse and hidraw nodes, show fresh creation (3/3).

We have a test bench (one AMD host with a discrete and an integrated GPU, one NVIDIA host, scripted Moonlight clients) and are glad to take on A/B runs or side quests. GPU age is the one limit worth naming.

Wolf lets every app container open any input and hidraw device through the
`c 13:* rwm` and `c <hidraw>:* rwm` device cgroup rules, and the default
profiles add CAP_MKNOD so that Wolf's hotplug exec can create the nodes.
Together they let any root process in an app container create and open
another session's virtual devices, or the host's own input devices.

Run the hotplug exec privileged instead, and strip MKNOD from the app
container: remove it from CapAdd and add it to CapDrop (Docker grants it by
default). Privileged containers are left as they are. The default config
and the docs no longer add MKNOD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CPq1qsThei84HS1zfu4Zvy

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rootful app containers can mknod and open other sessions' and the host's input devices

1 participant