Skip to content

daemon: scope container working directory creation with os.Root#52978

Open
SABITHSAHEB wants to merge 2 commits into
moby:masterfrom
SABITHSAHEB:scope-workdir-creation
Open

daemon: scope container working directory creation with os.Root#52978
SABITHSAHEB wants to merge 2 commits into
moby:masterfrom
SABITHSAHEB:scope-workdir-creation

Conversation

@SABITHSAHEB

Copy link
Copy Markdown
Contributor

SetupWorkingDirectory ran mkdir/chown on a path from GetResourcePath,
which (per its own doc) is only safe while no component is swapped for a symlink
between resolution and use — letting the operation escape the container root.

This scopes the creation to an os.Root on the container's BaseFS, which
re-checks every component and refuses to follow a symlink out of the root — the
same hardening applied to mount-destination creation in 64a22d80b9. The
only-new create+chown is factored into a reusable scopedMkdirAllAndChown
helper (chown skipped on Windows, as before), with unit and integration tests.

Signed-off-by: SABITH SAHEB <shabi7204192361@gmail.com>
@github-actions github-actions Bot added the area/daemon Core Engine label Jun 28, 2026
@SABITHSAHEB SABITHSAHEB force-pushed the scope-workdir-creation branch from a5dfd7c to 4e70069 Compare June 29, 2026 16:49
Signed-off-by: SABITH SAHEB <shabi7204192361@gmail.com>
@SABITHSAHEB SABITHSAHEB force-pushed the scope-workdir-creation branch from 1b507e9 to 720e71b Compare June 29, 2026 16:58
Comment on lines -338 to +343
if err := user.MkdirAllAndChown(pth, 0o755, uid, gid, user.WithOnlyNew); err != nil {
pthInfo, err2 := os.Stat(pth)
if err2 == nil && pthInfo != nil && !pthInfo.IsDir() {
// GetResourcePath only guarantees that pth stays inside the container while
// none of its components is swapped for a symlink between resolution and use
// (see its doc comment). Re-rooting the creation in the container's BaseFS
// with [os.Root] makes that guarantee hold for every component on every
// operation, the same hardening applied to mount-destination creation in
// commit 64a22d80b9.
root, err := os.OpenRoot(container.BaseFS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Labels

area/daemon Core Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants