Relative lookups into `/proc`, `/sys` and `/dev/shm` from a descriptor on `/` reach the intercepts through `openat` only
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- c, linux, macos
调研方向
Start with path_translate_at in src/syscall/path.c, then trace path_rebase_hostdirfd and the lookup entry points in src/syscall/fs.c and src/syscall/fs-stat.c. Use the supplied C reproducer on macOS and the qemu reference lane to compare relative lookups. Done means relative descriptor lookups consistently reach the intercepts, including when the sysroot contains an empty directory, without leaving stat, access, or readlink behind.
由索引模型根据 Issue 内容生成。
描述
Symptom
Measured on 2c4a8f4, macOS 15.6.1, Apple M1. Three runs of each, identical.
A name relative to a directory that no intercept serves, such as /, reaches the intercepts only through openat. When it lands in /proc, /sys or /dev/shm, the other lookups in the table answer ENOENT for a file openat has just opened. No sysroot:
relative to a descriptor on / openat O_PATH fstatat nofollow statx faccess readlnk cwd-stat
proc/self/status ok ok ENOENT ENOENT ENOENT ENOENT ENOENT ENOENT
proc/self/exe ok ok ENOENT ENOENT ENOENT ENOENT ENOENT ENOENT
sys/devices/system/cpu/online ok ok ENOENT ENOENT ENOENT ENOENT ENOENT ENOENT
dev/shm ok ok ENOENT ENOENT ENOENT ENOENT ENOENT ENOENT
On Linux 6.18.54-0-virt, through the qemu reference lane, every column answers. EINVAL there is readlinkat on a name that is not a link:
relative to a descriptor on / openat O_PATH fstatat nofollow statx faccess readlnk cwd-stat
proc/self/status ok ok ok ok ok ok EINVAL ok
proc/self/exe ok ok ok ok ok ok ok ok
sys/devices/system/cpu/online ok ok ok ok ok ok EINVAL ok
dev/shm ok ok ok ok ok ok EINVAL ok
With a sysroot whose /proc is an empty directory, which is how the Alpine rootfs ships it, openat of the directory itself stops reaching the intercept too. The host finds the empty directory first, so a listing taken through openat(root, "proc") has 2 entries where /proc has 5:
/proc lists 5 entries absolutely, 2 through openat(root, "proc")
The table reads the same with that sysroot.
Reproducer
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
static const char *rc(long r) {
static char buf[16][16];
static int i;
i = (i + 1) % 16;
if (r >= 0)
return "ok";
snprintf(buf[i], sizeof(buf[i]),
errno == ENOENT ? "ENOENT"
: errno == EINVAL ? "EINVAL"
: "E%d",
errno);
return buf[i];
}
static const char *opened(int fd) {
const char *r = rc(fd);
if (fd >= 0)
close(fd);
return r;
}
static int entries(int fd) {
DIR *d = fdopendir(fd);
int n = 0;
while (d && readdir(d))
n++;
if (d)
closedir(d);
return n;
}
int main(void) {
static const char *names[] = {"proc/self/status", "proc/self/exe",
"sys/devices/system/cpu/online", "dev/shm"};
int root = open("/", O_RDONLY | O_DIRECTORY);
struct stat st;
struct statx sx;
char link[256];
printf("relative to a descriptor on / openat O_PATH fstatat "
"nofollow statx faccess readlnk cwd-stat\n");
for (int i = 0; i < 4; i++) {
const char *n = names[i];
const char *o = opened(openat(root, n, O_RDONLY | O_NONBLOCK));
const char *p = opened(openat(root, n, O_PATH | O_NOFOLLOW));
const char *f = rc(fstatat(root, n, &st, 0));
const char *nf = rc(fstatat(root, n, &st, AT_SYMLINK_NOFOLLOW));
const char *x = rc(statx(root, n, 0, STATX_BASIC_STATS, &sx));
const char *a = rc(faccessat(root, n, F_OK, 0));
const char *l = rc(readlinkat(root, n, link, sizeof(link)));
fchdir(root);
const char *c = rc(stat(n, &st));
printf("%-31s %-6s %-6s %-7s %-8s %-6s %-7s %-7s %s\n", n, o, p, f, nf, x,
a, l, c);
}
printf(
"/proc lists %d entries absolutely, %d through openat(root, \"proc\")\n",
entries(open("/proc", O_RDONLY | O_DIRECTORY)),
entries(openat(root, "proc", O_RDONLY | O_DIRECTORY)));
return 0;
}
Mechanism
- The gates that send a name to the intercepts answer false for any name that does not start with
/(path_might_use_open_intercept,src/syscall/path.c:84;path_might_use_stat_intercept,src/syscall/path.c:222). The intercepts themselves match absolute names, sosys_readlinkat, which callsproc_intercept_readlinkwith no gate (src/syscall/fs.c:2974), finds nothing either. - A relative name is rebuilt into an absolute guest path for three kinds of base: a descriptor carrying a stamp (
resolve_proc_dirfd_path,src/syscall/path.c:1355), a cwd on/proc,/dev/pts,/sysor/dev/bus(src/syscall/path.c:1421), and a FUSE mount (fuse_resolve_at_path,src/syscall/fuse.c:2990). A descriptor on/is none of them, and neither is a cwd of/, so the name reaches the host as written. sys_openat_pathgives the host answer a second chance. After a hostENOENTit rebases the name through the descriptor's host path and retries the absolute spelling (src/syscall/fs.c:1016-1035,path_rebase_hostdirfdatsrc/syscall/path.c:1469; the comment there names systemd'schase()as the walker it is for). Nothing else calls the rebase, sostat_at_path(src/syscall/fs-stat.c:289), which servesnewfstatatandstatx,sys_faccessat(src/syscall/fs.c:3512) andsys_readlinkat(src/syscall/fs.c:2958) report the host'sENOENT.- The second chance runs only after
ENOENT. A sysroot that holds an empty directory under the same name answers the host open, so the intercept is never asked.
Direction
The rebase belongs where a relative name is first translated, in path_translate_at, so every entry point gets it. It also cannot wait for the host to fail, since a sysroot may hold an empty directory under the same name.
What that costs has to be weighed. path_rebase_hostdirfd asks the host for the base's path with F_GETPATH, which is one more host call on every relative lookup if it runs unconditionally.
Found while measuring #398, and listed there under "Not in this change".
- 主要语言
- C
- 星标
- 273
- 派生
- 29
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 17
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sysprog21/elfuse 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 30/100
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 3 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
OpenPrinting/cups#1772 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
snowballstem/snowball#311 ·
-
tech-debt
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100