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

Đang mở
#1,681 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

🉠

Ngôn ngữ chính
Python
Star
6.2k
Fork
806
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của qilingframework/qiling

Tất cả issue của qilingframework/qiling

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.