Skip to content

Commit 206fa10

Browse files
jhrozekclaude
andcommitted
Fix rootfs root directory permissions and xattr
os.MkdirTemp creates the rootfs root with mode 0700 and no OCI tar entry covers it, so guest processes running as non-root (e.g. uid 1000) cannot traverse /. Chmod it to 0755 after extraction and set the override_stat xattr so libkrun reports root ownership. Also copy the root dir's xattr in CloneDir — the walk skips "." so it was previously missed. Fixes #39 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e9a5e9 commit 206fa10

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

image/pull.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ func PullWithFetcher(ctx context.Context, imageRef string, cache *Cache, fetcher
130130
}
131131
}
132132

133+
// Ensure the rootfs root directory itself is world-accessible and has
134+
// the override_stat xattr. The root dir is created by os.MkdirTemp
135+
// (mode 0700) and no tar entry covers it, so without this fix the
136+
// guest's uid 1000 user cannot traverse /.
137+
if err := os.Chmod(tmpDir, 0o755); err != nil {
138+
slog.Warn("chmod rootfs root dir failed", "err", err)
139+
}
140+
xattr.SetOverrideStat(tmpDir, 0, 0, os.ModeDir|0o755)
141+
133142
// Move into cache if available. The extraction is fresh and this is
134143
// the only reference, so FromCache stays false — callers may safely
135144
// modify the rootfs in place without a COW clone.

rootfs/clone.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ func CloneDir(srcDir, dstDir string) error {
115115
_ = os.Chmod(dirsToRestore[i].path, dirsToRestore[i].perm)
116116
}
117117

118+
// Copy the override_stat xattr on the root directory itself.
119+
// The walk skips "." so the root dir's xattr is not covered above.
120+
xattr.CopyOverrideStat(srcDir, dstDir)
121+
118122
return nil
119123
}
120124

0 commit comments

Comments
 (0)