[Bug] lwp: sys_poll nfds wraparound on 32-bit RT-Smart — 8-byte heap block walked as 0x20000001 entries, kernel heap OOB read/write and crash
Maintainer thường phản hồi trong vòng 2 ngày
@Yunlk đang làm issue này rồi.
Từ ngày 24/10/2026.
Đá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
- 28/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ệ
- c
- Lĩnh vực
- operating-systems, security
Hướng nghiên cứu
Start with sys_poll in components/lwp/lwp_syscall.c and the poll traversal in components/libc/posix/io/poll/poll.c; trace how the byte count, allocation, copy, and traversal use nfds. Also inspect sys_epoll_pwait in components/lwp/lwp_syscall.c for the sibling overflow described in the report. Done means oversized counts are rejected consistently before memory access, allocation, copy, or traversal, with regression coverage for both paths.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report: sys_poll integer wraparound on 32-bit RT-Smart gives kernel heap out-of-bounds read/write
RT-Thread Version
v5.0.0 – v5.3.0 and current master (v5.4.0-dev, verified at commit 5d1fb66d).
Introduced by commit ecf2d821 (2022-12-03, "sync branch rt-smart. (#6641)"), first release: v5.0.0.
Affected area
Kernel / RT-Smart (light-weight process) — components/lwp/lwp_syscall.c (sys_poll),
components/libc/posix/io/poll/poll.c.
Hardware-BSP vendor
Other (architecture-dependent, not vendor-dependent)
Architecture
ARM 32-bit (any sizeof(size_t) == 4 target with RT_USING_SMART enabled).
64-bit builds are NOT affected (the product nfds * sizeof is promoted to 64-bit and does not
wrap; the oversized allocation simply fails with -ENOMEM).
Board and hardware details
Reproduced on bsp/qemu-vexpress-a9 (Cortex-A9, QEMU vexpress-a9 machine) with the official
CI RT-Smart configuration fragment (.github/utest/configs/rtsmart/rtsmart.cfg) and the
official CI musl toolchain (toolchains-ci v1.7, arm-linux-musleabi-gcc 7.3.0).
Develop Toolchain
GCC (arm-linux-musleabi 7.3.0 for the kernel; the PoC is a freestanding user program that
issues raw svc calls, no libc needed).
Describe the bug
On 32-bit RT-Smart builds, sys_poll() computes the size of the kernel-side pollfd array
with a multiplication that wraps modulo 2^32, while still handing the unwrapped fd count
to the kernel poll loop. An unprivileged user process can therefore make the kernel allocate
an 8-byte heap block and then linearly read and write far beyond it, corrupting the kernel
heap and deterministically killing the system.
Vulnerable code (components/lwp/lwp_syscall.c, sys_poll):
if (!lwp_user_accessable((void *)fds, nfds * sizeof *fds)) /* nfds_t = unsigned int */
return -EFAULT;
kfds = (struct pollfd *)kmem_get(nfds * sizeof *kfds); /* wraps on 32-bit */
...
lwp_get_from_user(kfds, fds, nfds * sizeof *kfds);
ret = poll(kfds, nfds, timeout); /* original nfds, unwrapped */
With nfds = 0x20000001 and sizeof(struct pollfd) == 8:
0x20000001 * 8 = 0x1_00000008, which wraps to 8 on a 32-bit size_t.
The !size early-out in lwp_user_accessible_ext() only catches products that wrap to
exactly zero, so the wrapped size passes the access check, kmem_get(8) (= rt_malloc(8))
returns an 8-byte kernel heap block, and poll(kfds, 0x20000001, 0) walks
536,870,913 entries starting at that block.
Inside do_pollfd() (poll.c:207-242), for each entry pf:
fd = pollfd->fd— out-of-bounds read of kernel heap memory past the 8-byte block;fd_get(fd)— the garbage fd is used as an fdt index (further OOB access);pollfd->revents = mask— out-of-bounds write of a 4-byte value at every 8-byte offset
(POLLNVAL= 0x20, ormask & (events | POLLERR | POLLHUP)whereeventsitself is the
OOB-read heap data, i.e. partially groomable).
Steps to reproduce (full chain, no host-side shortcuts):
- Build the
qemu-vexpress-a9BSP with the official CI smart fragment:
cat .github/utest/configs/rtsmart/rtsmart.cfg >> bsp/qemu-vexpress-a9/.config
(plusscons --pyconfig-silent && sconswithRTT_CC_PREFIX=arm-linux-musleabi-). - Place a freestanding user program as
/sbin/initon the FATsd.binrootfs
(RT-Smart execs/sbin/initas pid 1 at boot). The program issues one raw syscall:
sys_call(SYS_poll /* RT-Thread syscall #9 */, fds, 0x20000001, 0)
withfdspointing at a valid user buffer{fd=1, events=POLLIN}.
PoC source: one file, ~200 lines, no libc, puresvc(available on request). - Run:
qemu-system-arm -M vexpress-a9 -m 512 -kernel rtthread.bin -sd sd.bin -serial stdio
Actual result (serial log):
msh />[poc] sys_poll nfds wraparound attack start
[W/mm.fault] rt_aspace_fault_try_fix: varea not found at 0x48000
data abort:Execption:
r00:0xc0125800 r01:0x00000000 r02:0x0000fdfd r03:0x0004801c
...
sp :0xc0141450 lr :0xc002a25c pc :0xc0040d8c
dfsr:0x00000005
dfar:0x00048040
Backtrace (addr2line on the crash addresses printed by the kernel):
fd_get components/dfs/dfs_v2/src/dfs.c:500
poll_do components/libc/posix/io/poll/poll.c:281
poll components/libc/posix/io/poll/poll.c:355
sys_poll components/lwp/lwp_syscall.c:933 <-- poll(kfds, nfds, timeout) with unwrapped nfds
arch_syscall_exit components/lwp/arch/arm/cortex-a/lwp_gcc.S:193
r03 = 0x0004801c is the linearly advanced pf pointer — the walk has already covered
dozens of KB past the 8-byte kmem block when the first unmapped access (dfar=0x48040)
faults. Because do_pollfd() assigns pf->revents on every iteration, 4096+ out-of-bounds
4-byte writes into the kernel heap occur before the fault point. After the first data abort
the kernel then enters a cascade of 726 consecutive data aborts (heap metadata corrupted;
every subsequent kernel path dies) — a full system crash.
Control run: the same program with the legal value nfds = 1 returns 0, sets
revents = 0, and the system stays alive (msh keeps running). The only differing input is
the nfds value.
Expected result: sys_poll() must validate that nfds * sizeof *fds does not overflow
(e.g. if (nfds > (SIZE_MAX / sizeof *fds)) return -EINVAL;) — the same for sys_epoll_pwait's
cnt * sizeof(struct epoll_event) (see below) — or clamp/limit the count consistently for
allocation, copy and traversal.
Other additional context
- Suggested fix (one-line family):
if (nfds > (size_t)-1 / sizeof *fds) return -EINVAL; /* sys_poll, before access check */ if ((unsigned)cnt > (size_t)-1 / sizeof(struct epoll_event)) return -EINVAL; /* sys_epoll_pwait */ - Sibling path with the same root cause (not the subject of this report but should be fixed
together):sys_epoll_pwait()atlwp_syscall.c:10519-10522—
kmem_get(cnt * sizeof(struct epoll_event))wraps the same way on 32-bit
(cnt = 0x10000001,sizeof = 16→ allocates 16 bytes) whileepoll_do()uses the
originalcntasmaxeventsandmemcpys a 16-bytestruct epoll_eventper ready-list
entry whose 8-bytedatapayload is fully attacker-chosen viaepoll_ctl(EPOLL_CTL_ADD);
level-triggered entries are re-appended to the ready list, so a single ready fd can smear
the same attacker-controlled 16-byte pattern linearly across the kernel heap. We verified
the code path statically; on our boardepoll_create1()currently fails for an unrelated
reason so we did not complete a runtime reproduction of this variant. - Attack prerequisites (explicit): 32-bit RT-Smart build; the attacker needs to run code
as any unprivileged user process (e.g. a third-party application or module on the device);
no privileges, no race, no user interaction, single syscall. - CVSS 3.1: 6.8 (AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:H) — deterministic kernel heap
OOB write + full system crash; 64-bit builds unaffected. - CWE: CWE-190 (Integer Overflow or Wraparound) leading to CWE-787/CWE-125
(OOB write/read) and CWE-400. - Relationship to existing reports: none found (issue search for poll/epoll overflow
empty; #10298 concerns sys_select's timeout pointer validation — different function, root
cause and sink; the CVE-2025 lwp family covers pointer-validation bugs, not size arithmetic).
- Ngôn ngữ chính
- C
- Star
- 12.4k
- Fork
- 5.5k
- Merge trung bình
- 3 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 79
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RT-Thread/rt-thread
-
Arch: ARM/AArch64 Doc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
RT-Thread/rt-thread#12082 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
RT-Thread/rt-thread#11951 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] [libc] timer_gettime 拆秒前将总纳秒截断为 uint32_t,剩余时间查询错误Có thể làm lại được @Yunlk đã nhận 28 ngày trước và không có pull request nào đang mở. Đang mởin progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
RT-Thread/rt-thread#11924 · 7 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] dfs_v2 tmpfs: ftruncate(fd, 0) frees the file buffer but reports success — use-after-free read/write and double free from a legal POSIX callCó thể đã có người làm @remukisama đã nhận 33 ngày trước. Đang mởin progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
RT-Thread/rt-thread#11902 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[bsp][stm32][bluepill] README「快速上手」缺少重新生成 MDK 工程这一步,按文档操作无法编译通过Có thể làm lại được @moment-NEW đã nhận 50 ngày trước và không có pull request nào đang mở. Đang mởin progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
RT-Thread/rt-thread#11818 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của RT-Thread/rt-thread
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/nuttx-apps#4108 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
trezor/trezor-firmware#8357 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ivorysql_ora: DBMS_SESSION lacks SLEEP (documented, not covered by #2763)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue kernel
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
JackFurton/who-would-build-a-kernel-in-java#316 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bandwidth selector rotary direction is inconsistent with the regular menu on portable modelsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
PE5PVB/TEF6686_ESP32#970 ·