mount: "bind" with recursive propagation (rprivate/rslave/rshared) performs a recursive bind (rbind)

Abierto
#279 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@f-sommerauer ya está trabajando en esto.

Desde el 6/11/2026.

  • #1 de @f-sommerauer — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go, linux

Línea de trabajo

Start in mount/mounter_linux.go and trace how parseOptions separates mount flags before the initial and propagation mount(2) calls. The issue proposes returning separate flag and propagation masks and updating MakeMount and ensureMountedAs; inspect their existing tests and add coverage for bind,rprivate, bind,rslave, and bind,rshared. Done means these options no longer copy submounts, while rbind still does.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

mount.Mount(src, dst, "none", "bind,rprivate") performs a recursive bind mount instead of a plain bind mount. The same happens with bind,rslave, bind,rshared, and bind,runbindable.

Cause
  1. parseOptions ORs every option into a single int mask, so "bind,rprivate" produces MS_BIND|MS_PRIVATE|MS_REC (0x45000).
  2. In mount() (mount/mounter_linux.go), oflags := flags &^ ptypes strips the propagation type bits before the first mount(2) call, but leaves MS_REC (0x4000) set.
  3. The initial mount(2) call runs with MS_BIND|MS_REC, which the kernel treats as rbind, copying all submounts under src into dst before the second mount(2) call applies rprivate.

We hit this via Moby local volumes (volume/local), which pass o= directly to mount.Mount. A local volume with type=none,device=<dir>,o=bind,rprivate exposes every submount under <dir> inside the container; with o=bind,rshared, docker volume rm also unmounts those submounts on the host because the volume became a shared recursive bind.

Details and dockerd reproduction matrix

Tested on Linux with dockerd built from moby/moby master using local volumes type=none,device=/src,o=<opts>, where /src is a shared tmpfs with a tmpfs submount at /src/sub:

o= /src/sub visible in container host /src/sub after docker volume rm
bind, bind,private no kept
bind,rprivate, bind,rslave yes (expected: no) kept
bind,rshared yes (expected: no) unmounted (expected: kept)
rbind, rbind,r* yes rbind/rbind,rshared: unmounted; rprivate/rslave: kept

Minimal standalone Go reproducer (run as root or under unshare -Urm --propagation private):

src, _ := os.MkdirTemp("", "src")
dst, _ := os.MkdirTemp("", "dst")
_ = mount.Mount("tmpfs", src, "tmpfs", "shared")
_ = os.Mkdir(filepath.Join(src, "sub"), 0o755)
_ = mount.Mount("tmpfs", filepath.Join(src, "sub"), "tmpfs", "")

_ = mount.Mount(src, dst, "none", "bind,rprivate")
mounted, _ := mountinfo.Mounted(filepath.Join(dst, "sub"))
fmt.Println("dst/sub mounted:", mounted) // prints true (expected: false)
Proposed fix

Split propagation options out of parseOptions (flag, propFlag, data) so the initial mount(2) call receives flag and the propagation mount(2) call receives propFlag. MakeMount and ensureMountedAs are updated to match, and the exported API stays unchanged.

Callers passing bind,r<prop> that relied on submounts being copied would now get a non-recursive bind (matching mount --bind --make-r<prop>). Callers that want submounts would need rbind,r<prop>.

Does this approach look good to maintainers? Happy to open a PR with unit and root mount tests if so.


AI disclosure: Used Antigravity (Gemini) to help trace the MS_REC bitmask interaction, build the dockerd reproducer, and draft this issue; reviewed and verified by the author.

Lenguaje dominante
Go
Estrellas
104
Forks
64
Merge medio
2 d 4 h
PR fusionados (30 d)
11

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de moby/sys

Todos los issues de moby/sys

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.