Skip to main content
Menu
Advisories

Race in docker cp lets a container write through read-only bind mounts

GHSA-VFMQ-R373-X89FPublished Updated GitHub

Description

A race condition during docker cp mount setup allows a malicious container to leave a read-only bind mount writable while an archive is extracted into the container, potentially modifying host files that were meant to be protected.

When copying files into a container, the daemon bind-mounts the container's volumes into a temporary view and applies the read-only flags afterwards, through a path inside the container's filesystem. A process in the container can change that path in between, so the flags land on a different mount and the intended bind mount stays writable for the duration of the copy.

Conditions for exploitation

  • The container has at least one read-only bind mount.
  • A process inside the running container can modify a path leading to that mount's destination.
  • An operator or API client copies files into that container with docker cp or PUT /containers/{id}/archive.

Not affected

  • Containers without read-only bind mounts.
  • Stopped containers, because no container process can interfere during the copy.
  • Copies out of a container, such as GET and HEAD on /containers/{id}/archive, because they do not write to the mounts.

Rootless Docker Engine is affected, but the impact is limited to files accessible to the daemon's user.

Impact

A malicious container can make a read-only bind mount writable while a docker cp into it is running. The archive being copied can then create or overwrite files in the host directory behind the mount.

  • The attacker does not choose the content written. It comes from the archive supplied by whoever runs the copy.
  • The attacker cannot start the copy. An operator or API client has to do it.
  • The mount is temporary, but files written through it persist after the copy completes.

Workarounds

  • Do not copy files into running containers that run untrusted workloads.
  • Stop the container before copying files into it.
  • Use authorization plugins to restrict access to PUT /containers/{id}/archive.

Credits

This issue was reported by Jaeyeong Lee

Affected versions

References

GitHub · moby/moby