os/posix: mknodat transform_path leaves '..' in host path (rootfs containment, same class as #1076)

オープン
#1,681 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend, security

調査の方向性

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 outside rootfs, 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_fd arm: source returns (fileno(), raw_relative_path) with no is_safe_host_path visible 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_file rootfs containment (fixed). This issue: transform_path absolute arm used by mknodat, 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 ファイルあり
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

qilingframework/qiling のほかの issue

qilingframework/qiling の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。