userns: RunningInUserNS reports true inside gVisor (nsfs inode is not PROC_USER_INIT_INO)

未关闭 适合新手
#285 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go

调研方向

从 userns/userns.go 开始:阅读 runningInUserNS()、PROC_USER_INIT_INO 常量以及现有的 runningInUserNSFromUIDMap 回退逻辑(在 #255 中为 OpenVZ 添加)。改动是:在任何 inode 不匹配时都查询 uid_map,而不是只在 /proc/self/ns/user 不存在时才查询,同时保留 inode 快速路径。在 moby/sys 中运行 go test ./userns/...;完成意味着混合检查通过现有测试,并且一个 inode 为 1、带有 identity uid_map 的用例报告 false。

由索引模型根据 Issue 内容生成。

描述

Since v0.2.0 (#240), runningInUserNS() treats any /proc/self/ns/user inode other than PROC_USER_INIT_INO (0xEFFFFFFD) as being inside a user namespace. It only falls back to uid_map when /proc/self/ns/user is missing, or on OpenVZ (#255).

gVisor (runsc, checked on release-20261005.0) gives the initial user namespace's nsfs entry inode 1, and uid_map reads 0 0 4294967295. So inside any gVisor sandbox, RunningInUserNS() returns true even though the process is in the initial namespace:

$ stat -L -c %i /proc/self/ns/user
1
$ cat /proc/self/uid_map
         0          0 4294967295
$ ls /proc/vz
ls: /proc/vz: No such file or directory

Impact: containerd's core/diff/apply (v2.4.2) skips its overlay fast path when RunningInUserNS() is true, and extracts every layer through a temporary overlay mount of all its lower layers. For BuildKit v0.34.2 running in a gVisor pod, unpacking a 36-layer, ~7 GB parent went from 75 s to 234 s. A single 18k-file layer took 60 s instead of 9 s.

Patching inUserNS to use runningInUserNSFromUIDMap brings unpack back to normal.

Suggestion: the hybrid check proposed in moby/moby#53592. Keep the inode fast path, but when the inode doesn't match, also consult uid_map before reporting a user namespace, rather than doing that only for OpenVZ. Virtualized procfs implementations (OpenVZ, gVisor, possibly others) don't reproduce the kernel's fixed inode.

AI disclosure: Used Claude Code + Opus 5.5 to discover and write this issue

主要语言
Go
星标
104
派生
64
平均合并
2 天 4 小时
30 天内合并 PR
11

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

moby/sys 的其他 Issue

查看 moby/sys 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。