os/posix: mknodat transform_path leaves '..' in host path (rootfs containment, same class as #1076)
还没有人认领这个 Issue。
评估
调研方向
Start in qiling/os/posix/syscall/stat.py by reading transform_path and ql_syscall_mknodat, then compare their path handling with the openat containment flow referenced in the issue. Check the absolute path case and the relative path with dir_fd; done means mknodat cannot create a file outside rootfs, with regression coverage for both cases.
由索引模型根据 Issue 内容生成。
描述
related: https://github.com/qilingframework/qiling/pull/1076
This is a sibling gap from the same rootfs-containment work as #1076 — not a “bypass of #1076”.
#1076 removed the open_ql_file branch that skipped transform_to_real_path when dir_fd was set, and landed tests/test_elf.py::test_elf_linux_x8664_path_traversion plus examples/rootfs/.../path_traverse_static. That establishes the project invariant: guest paths should stay under rootfs. RWCTF2022 QLaaS used the same boundary (write-up: “Qiling Sandbox Escape”).
Users who run Qiling on untrusted samples (malware analysis / CI) typically trust that rootfs fence — so this gap has a realistic trigger surface.
Authority: qiling @ 86c927cb329993b14e2586e04d1dd7a90deee5fb
1. Root cause (where it actually sits)
This is not “mknodat forgot to call transform_to_real_path”.
The absolute virtual-path arm only does:
os.path.join(ql.rootfs, path.lstrip('/'))
The resulting host string still contains ... When that string is passed to os.mknod (or a similar host API), the kernel pathname lookup resolves .. and leaves rootfs.
At 86c927cb, qiling/os/posix/syscall/stat.py:
if path.startswith('/'):
return None, os.path.join(ql.rootfs, path.lstrip('/'))
def ql_syscall_mknodat(ql: Qiling, dirfd: int, path: int, mode: int, dev: int):
dirfd, real_path = transform_path(ql, dirfd, path)
try:
os.mknod(real_path, mode, dev, dir_fd=dirfd)
...
By contrast, open / openat go through virtual_abspath_at → open_ql_file → is_safe_host_path (#1076 area).
Note: on this same pin, QlOsPath already has __strip_parent_refs for relative path resolution inside QlOsPath. That helper is not applied by the transform_path absolute join arm used by mknodat — same class of blind spot.
transform_path call sites in this file: mknodat (write; this report’s mainline), plus fstatat64 / newfstatat / statx (read-side side channel only; not a separate issue).
2. Sibling contrast (path math)
Both columns measured at pin 86c927cb (same tree as the root-cause pin).
Right column = QlOsPath.virtual_to_host_path + is_safe_host_path (openat-style).
Bug column = transform_path absolute join (mknodat path).
__strip_parent_refs on this pin helps relative resolution inside QlOsPath; it does not cover the transform_path absolute arm.
Same guest path "/../../../../../../etc/x" (path-math contrast at the same pin):
| Arm | Behavior |
|---|---|
QlOsPath.virtual_to_host_path + is_safe_host_path |
lands under rootfs/etc/x, is_safe=True |
transform_path absolute arm |
join result still contains .. (Python does not resolve) |
Any normpath in the check is display-only for contrast; it is not what transform_path does.
3. Reproduction
Environment: Ubuntu 22.04, kernel 6.8, non-root (euid=1000). Authority: qiling @ 86c927cb.
3a. Host-sink contrast (no Unicorn) — pins the attribution layer
Mirror of the absolute arm (join(rootfs, path.lstrip('/'))) then os.mknod with S_IFREG|0644 as non-root:
guest= /../q1_escape_marker
transform_join= /tmp/q1_ql_…/rootfs/../q1_escape_marker # still contains ..
mknod_ok= True
escaped outside_rootfs= True
REPRO_OK: non-root S_IFREG mknod via transform_path join escaped rootfs
This shows the escape is **join leaves .. → host API → kernel resolve**, not a Unicorn-only quirk. S_IFREG+ non-root → noCAP_MKNOD` required.
3b. Unicorn guest → mknodat (end-to-end)
Static guest: syscall(SYS_mknodat, AT_FDCWD, "/../q1_escape_marker", S_IFREG|0644, 0).
pin_expect=86c927cb329993b14e2586e04d1dd7a90deee5fb
euid=1000
guest_path=/../q1_escape_marker
rootfs=/tmp/q1_ql_e2e_av6jkjnq/rootfs
expected_escaped=/tmp/q1_ql_e2e_av6jkjnq/q1_escape_marker
escaped_exists=True outside_rootfs=True isreg=True
inside_marker_exists=False
REPRO_OK: Unicorn guest mknodat escaped rootfs (non-root S_IFREG)
4. Impact (honest upper bound)
- Boundary: same invariant as #1076 / QLaaS — untrusted guest must not reach host paths outside
rootfs. - What this report proves: via
mknodat, a guest can create an empty regular file outsiderootfs, within the Qiling process uid’s writable range. - What this is not: remote RCE, privilege escalation, or a claim that we wrote payload bytes into that file.
- Optional discussion only (not claimed here): composition with fs mapper / hooks, or an isomorphic issue in the open family closer to classic QLaaS — not reproduced in this PoC.
- Severity: no specific score claimed.
AV:L / AC:H / PR:L / S:U— local user machine running a user-supplied sample.
5. Follow-ups (static reading only)
(Static code reading; not automated. If confirmed, a fix should cover these too.)
- Relative path +
dir_fdarm: source returns(fileno(), raw_relative_path)with nois_safe_host_pathvisible on that path.
Suggested fix
Reuse virtual_abspath_at / virtual_to_host_path / is_safe_host_path (or equivalent containment already used by openat) so there is not a second path-handling path for mknodat.
transform_path returns (dirfd|None, path) — different contract from the openat chain. Keep the caller signature; expect a small patch. Please include the relative + dir_fd arm in the same change if it is confirmed unsafe.
Related
- #1076 — openat /
open_ql_filerootfs containment (fixed). This issue:transform_pathabsolute arm used bymknodat, separate code path. - #572 — earlier public report of guest write outside rootfs (directory traversal); same containment class.
🉠
- 主要语言
- Python
- 星标
- 6.2k
- 派生
- 806
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qilingframework/qiling 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
qilingframework/qiling#1690 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
qilingframework/qiling#1689 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
qilingframework/qiling#1688 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
qilingframework/qiling#1686 ·
-
难度 2/5 半天 新手友好度 82/100
qilingframework/qiling#1640 ·
查看 qilingframework/qiling 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
huggingface/datasets#9128 ·
维护者通常 1 天内回复
-
priority:low ready-for-dev
难度 2/5 1-3 小时 新手友好度 68/100
OpenHands/extensions#975 ·
维护者通常 1 天内回复
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)未关闭
难度 2/5 1-3 小时 新手友好度 78/100
pact-foundation/pact-python#1789 ·
维护者通常 9 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 82/100
juandresrodca/AdminForge#66 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复