Commit Graph
5400 Commits
Author SHA1 Message Date
bernardandClaude Code 9e29e3246b [components][lwp] harden sys_getaddrinfo user pointer handling
sys_getaddrinfo() validated the top-level res buffer, then wrote the
resolved socket address through res->ai_addr, a user-controlled nested
pointer that was never checked. On Smart/MMU builds a user program could
therefore turn getaddrinfo() into an arbitrary kernel write. The hints
fields were also read directly from user memory after the access check,
leaving a TOCTOU window.

Copy res and hints into kernel temporaries with lwp_get_from_user() so
all nested pointers come from one validated snapshot. Write the nested
sockaddr and the outer addrinfo back with lwp_put_to_user(), which
validates the destination range and never dereferences an unchecked user
pointer in kernel context.

Also fix the servname copy check (a size_t result can never be < 0),
allocate the kernel addrinfo with sizeof(*k_hints), and release k_res on
the new error paths.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-03 09:04:56 +08:00
GuEe-GUI 2c88a3b698 [drivers][scmi] Fix reset provider lookup and driver registration order
- register SCMI reset and power-domain drivers during subsystem initialization
- resolve SCMI reset state through the reset-controller provider
- use the parsed DT reset domain ID when querying reset attributes
- retain the SCMI device reference in the reset provider instance

Signed-off-by: GuEe-GUI <2991707448@qq.com>
2026-11-02 18:20:45 +08:00
Old-Ding 08cad4ee9c usbdevice: clamp OS compatible ID response length 2026-11-02 11:47:57 +08:00
Old-Ding cb9dc59180 usbdevice: validate string descriptor index 2026-11-02 11:47:07 +08:00
zhangyangysuandyang.zhang 7e7237d644 Fix stack corruption in rt_sdhci_init_host() (#11542)
* lwp: fix pid leak on exec failure before task startup

When msh tries to execute a non-ELF path, lwp_execve() may allocate a PID
before lwp_load() fails. The old error path only dropped the LWP reference,
leaving the PID tree entry pointing to a freed LWP.

In an init-less boot flow, this can poison pid 1 after a failed command from
msh. A later LWP launch may then treat the stale pid 1 entry as a valid parent
LWP, resulting in invalid pgrp/session state and a job-control assertion during
process exit.

Add lwp_pid_rollback() for exec/spawn failures before the process becomes
runnable. Unlike lwp_pid_put(), it always releases the PID lock and does not
enter the "no more pid allocation" state when the PID tree becomes empty.

Use the rollback helper in lwp_execve() failure paths after PID allocation.

Signed-off-by: zhangyang <gaoshanliukou@163.com>

* [drivers][sdio] avoid SDHCI device name stack overflow

rt_sdhci_init_host() allocated a fixed 32-byte buffer for device-derived object names, but sdio_host_set_name() may copy up to RT_NAME_MAX bytes into the output buffer. When RT_NAME_MAX is larger than 32, this can overwrite the stack and corrupt nearby locals.

Size the temporary name buffer with RT_NAME_MAX, force it to be NUL-terminated, and derive the append offset from the actual string length. Also replace the suffix rt_sprintf() calls with bounded rt_snprintf() so timer and workqueue suffixes cannot overflow the buffer when the base name is already close to RT_NAME_MAX.

Signed-off-by: zhangyangysu <zhangyangysu0928@gmail.com>

---------

Signed-off-by: zhangyang <gaoshanliukou@163.com>
Signed-off-by: zhangyangysu <zhangyangysu0928@gmail.com>
Co-authored-by: yang.zhang <zhangyang01@kylinos.cn>
2026-11-02 11:24:11 +08:00
usualtreee 506dbc6d6a [dlmodule] fix: uninitialized globals in relocatable modules (#11915) 2026-10-30 10:54:53 +08:00
bernard 6b287856f9 [components][lwp] apply clang-format to syscall sources
- format the newly split syscall implementation files
- no functional change
2026-10-29 14:50:07 +08:00
bernard 68757abdcc [components][lwp] split syscall implementation by subsystem
- move syscall implementations from lwp_syscall.c into syscall/
- group memory, file, socket, process, IPC and time syscalls
- add a shared syscall dispatch table and internal header
- register the new directory from the LWP build script
- no functional change
2026-10-29 14:50:07 +08:00
bernard b4c6828cf4 [components][lwp] fix TTY init format and control character copy
- place the TIOCLINUX case brace on its own line
- use sizeof(tty_ctrl_charset) directly as the memcpy size
- fix the cppcheck sizeofDivisionMemfunc warning
2026-10-29 14:48:33 +08:00
bernard 24c624aa7a [components][lwp] handle TIOCLINUX and default window size
- return zero keyboard modifiers for TIOCLINUX instead of failing
- keep terminal applications that probe console state working
- initialize the TTY window size to 24x80 when none is reported
2026-10-29 14:48:33 +08:00
Huoyanlifusu 6040d6cf2c [components][netdev] Fix ping maximum & minimum latency counting 2026-10-29 09:33:44 +08:00
Bernard Xiong b88861d285 [bsp][qemu-virt64] enable RT-Thread Smart #11896 2026-10-29 09:29:21 +08:00
usualtree 30a61febbe [dhcp] fix raw server option bounds checks
Validate option headers and declared lengths before walking or returning options. Check minimum value sizes at the MESSAGE_TYPE and REQUESTED_IP call sites and bound parsing by the received packet length.

Fixes: #11913
2026-10-28 19:04:31 +08:00
CYFS3 ff82e23d13 style: format code with clang-format [skip ci] 2026-10-28 14:44:20 +08:00
CYFS 90e06f354b utest: stabilize CI test execution 2026-10-28 14:44:20 +08:00
CYFS 58d1377f01 utest: keep testcase failures across units 2026-10-28 14:44:20 +08:00
bernard e6905134d5 [drivers][8250] honor register width for ns16550 earlycon
- read reg-shift and reg-io-width from the device tree
- select the MMIO access width from reg-io-width
- reject unsupported register widths during early setup
- keep the generic 8250 path for other compatibles
2026-10-27 19:26:35 +08:00
bernard 6bce506bed [libc] use DFS file operations in poll
- resolve fops from dfs_file instead of vnode directly
- keep compatibility with both DFSv1 and DFSv2
- validate fops before dereferencing to avoid NULL access
2026-10-27 19:21:46 +08:00
Bernard Xiong 9e7065c85a [net][sal] validate RAW socket protocol (#11888)
* [net][sal] validate RAW socket protocol

- replace the IPPROTO_RAW-only check with VALID_PROTOCOL()
- allow RAW sockets for protocols such as ICMP
- keep the existing domain and type validation unchanged

* [net][sal] fix clang-format alignment

- align the macro continuation after the RAW protocol check
- no functional change
2026-10-27 19:21:16 +08:00
bernard f29b9ae21c [dfs] fix UTIME_OMIT handling in utimensat
- UTIME_OMIT means the corresponding timestamp must not be changed
- the inverted condition overwrote mtime and ignored a valid timestamp
- correct the comparison so UTIME_OMIT leaves the attribute untouched
2026-10-27 19:20:33 +08:00
bernard 9e6dec3b14 [net][lwip] add loopback netdev support
- add RT_LWIP_USING_LOOPBACK as a configurable option
- register lo/lo0 as a netdev and bring the link up
- make loopback the default interface when none is configured
- increase the RAW receive mailbox size for loopback echo
2026-10-25 19:26:53 +08:00
GUI 1c801efabc [bsp][spacemit/k1] first version #11132 2026-10-19 18:49:16 +08:00
seteiroandGrok 54f5cac5b4 drivers/misc: register rt_null at BOARD init for default console (#11472)
rt_console_set_device() is typically called in rt_hw_board_init() right
after rt_components_board_init(). null was INIT_DEVICE (level 3), so it
was not registered yet and could not be RT_CONSOLE_DEVICE_NAME.

Raise to INIT_BOARD_EXPORT; null is a pure software sink with no HW deps.

Co-Authored-By: Grok <seteiro@mail.grokbot.com>
2026-10-19 16:53:09 +08:00
zhangyuyang 8159dc81b7 [drivers][touch] Remove redundant path from global CPPPATH
The touch framework has no private headers in its source directory, so
adding the directory to CPPPATH is unnecessary. Remove it to avoid
polluting the global header search path, as discussed in #10980.
2026-10-17 16:42:48 +08:00
GUIandseteiro 8d8dc96b67 [ARCH/RISC-V] Next RISC-V (#10320)
* [libcpu][risc-v] Refactor the RISC-V architecture port

Introduce an opt-in unified RISC-V common layer for RV32 and RV64 while keeping existing BSPs on the legacy implementation during migration.

- use ARCH_RISCV and ARCH_CPU_64BIT for architecture and XLEN selection
- unify context, trap, MMU, cache, timer, SBI, SMP and ISA handling
- add PLIC, CLIC, ACLINT, APLIC and IMSIC support
- map physical hart IDs to contiguous logical CPU IDs
- add T-Head vendor overrides while preserving legacy ports
- migrate qemu-virt64-riscv with RV32 and RV64 support
- update clock_time, MM, LWP, OFW, PCI and Rust integration

Existing BSPs continue using legacy_common or common64 unless they select RT_USING_RISCV_NEW_COMMON.

Signed-off-by: GuEe-GUI <2991707448@qq.com>

* [libcpu][risc-v] skip disabled CPU nodes in early FDT walk

Rbb666 noted that rt_hw_fdt_install_early() walked every /cpus child
without checking status, so disabled cores still joined hart registration
and MMU capability probing. Skip nodes that are not okay/ok via
rt_fdt_device_is_available() before reading reg or mmu-type.

Signed-off-by: seteiro <chenmoushun@163.com>

* [libcpu][risc-v] Fix per-CPU page table mapping

- reuse existing non-leaf page table entries when mapping per-CPU areas
- reject leaf entry conflicts instead of overwriting mappings

Signed-off-by: GuEe-GUI <2991707448@qq.com>

---------

Signed-off-by: GuEe-GUI <2991707448@qq.com>
Signed-off-by: seteiro <chenmoushun@163.com>
Co-authored-by: seteiro <chenmoushun@163.com>
2026-10-17 09:44:26 +08:00
Huoyanlifusu 5d1fb66d13 [drivers][ofw] Fix phandle hash buffer overflow 2026-10-15 13:50:46 +08:00
rcitach 3f0c11116c [wlan] synchronize AP lifecycle and direct RX handling 2026-10-15 13:28:57 +08:00
rcitach efc5a9df82 [lwip] configure buffer options and preserve PBUF tailroom 2026-10-15 13:28:57 +08:00
rcitach 1e24039cf8 [DHCP] Optimize the DHCP startup logic 2026-10-15 13:28:57 +08:00
ymj0440 20881ec571 fix(netdev): correct ping delay logic for last packet and avoid rt_thread_delay(0)
The 'index == times' condition in the delay_tick calculation is never true,
so the delay was still applied after the last ping, contrary to the comment.
Skip the delay on the final ping by checking 'index != times - 1'.

Also only call rt_thread_delay() when delay_tick > 0, since passing 0
returns -RT_EINVAL.
2026-10-15 09:10:50 +08:00
W GTO 8acbb5df8e [drivers][usb] Clarify the configuration interface count check 2026-10-14 10:17:15 +08:00
W GTO 06f193d682 [usb][host] Bound interface enumeration and detach cleanup
Reject full configuration descriptors with more interfaces than the instance can hold. Clean up using the fixed interface-array capacity so an attach failure cannot leave detach trusting an oversized device-supplied count.

Fixes #11288
2026-10-14 10:17:15 +08:00
Zhaoqi Xu 8ec9d87959 [components][netdev] fix divide-by-zero in ping statistics when no reply
netdev_cmd_ping() computed avg_time / received before checking that any
reply arrived. When every request times out, received is 0 and the
integer division traps (SIGFPE on the simulator, a fault on Cortex-M),
taking the shell thread down. Only compute the average inside the
existing received > 0 branch where it is printed.

Fixes #11852
2026-10-14 09:33:19 +08:00
Jiang Yu 9e0e6dbba7 [components/drivers] reset: Fix build error when reset and ulog are both enabled.
The '#define assert ASSERT' in ulog_def.h conflicts with the 'assert'
used in reset.c (rstc->rstcer->ops->assert), causing unintended macro expansion.

Signed-off-by: Jiang Yu <yu.jiang@rock-chips.com>
2026-10-14 09:16:11 +08:00
Jaeyeong Lee ceef6e0ccd fix[usb]: support VCOM polling receive with Serial V2
Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
2026-10-11 17:37:11 +08:00
Jaeyeong Lee 8a3ca7bfa3 fix[usb]: stop aliasing rt_ringbuffer as rt_serial_rx_fifo in VCOM
With RT_USB_DEVICE_CDC and RT_USING_SERIAL_V2 both enabled, _function_enable
assigned the embedded rx_ringbuffer to serial.serial_rx. Serial V2 reads that
pointer as a struct rt_serial_rx_fifo, whose first member is a rt_ringbuffer,
so ring-buffer access happened to work while rx_cpt, rx_cpt_index and
rx_timeout landed on the following members of struct vcom, corrupting tx_rbp.
The layout shifts again with RT_SERIAL_USING_DMA, which inserts dma_ping_rb
ahead of those fields.

Serial V2 already owns the receive FIFO: dev_serial_v2.c allocates it with
rt_malloc on open and releases it with rt_free on close, so the assignment
also made rt_free run on memory inside struct vcom.

Drop the assignment and read the FIFO Serial V2 owns. rt_hw_serial_isr
reports RX_IND from serial_rx->rb, so the endpoint handler now fills that
ring buffer and _vcom_getc drains it. The Serial V1 path is unchanged.

Fixes #11739

Signed-off-by: Jaeyeong Lee <lee@jaeyeong.cc>
2026-10-11 17:37:11 +08:00
seteiro 3577e7a6ed [components][libc] run .init_array constructors in cplusplus_system_init
Newer GCC emits C++ global constructors into .init_array, which many
linker scripts keep outside [__ctors_start__, __ctors_end__), so they
never ran. Walk __init_array_start/__init_array_end (weak) as well,
skipping entries already covered by the ctors range.

Add RT_USING_CPP_CRT_INIT for ports whose startup runtime already runs
.init_array, default on for the simulator. With it set, only the
.init_array walk is skipped; the ctors range is still walked.

Renesas RA/RA_WIRELESS/RZ families select it when C++ is enabled: FSP
SystemInit() already walks .init_array, so boards whose linker script
only provides __init_array_* would run constructors twice. Boards that
fold .init_array into the ctors range (ra6m3-hmi-board, ra8d1, rz)
still run them once via RT-Thread.

Also source env.sh and restore RTT_EXEC_PATH in ToolsCI project generate
and dist steps so scons is on PATH (exit 127) and the ARM toolchain path
is not overwritten by env.sh.

Fixes #11778
2026-10-11 16:11:07 +08:00
陈谋顺 ba0f47edb3 [components][lwip] dhcpd: apply clang-format to dhcp_server.c 2026-10-10 17:20:57 +08:00
陈谋顺 887ca7175c [components][lwip] dhcpd: check buffer bounds when parsing options
The option loop advanced by the option length without checking the
number of bytes actually received by recvfrom(), so a malformed or
truncated DHCP packet could make the server read past the end of the
receive buffer.

Check that the option type, length and payload stay inside the received
data before reading them, and stop parsing when a requested IP option
is shorter than 4 bytes or a message type option is shorter than 1 byte.

Fixes #11323
2026-10-10 17:20:57 +08:00
陈谋顺 914dda7d02 [components][ulog] 用仓库的 clang-format 整理 ulog.c
按根目录 .clang-format 跑过 clang-format 19.1.7。
颜色复位仍在换行之前。
2026-10-09 08:58:47 +08:00
陈谋顺 572b7392b7 [components][ulog] 带颜色日志先恢复默认颜色再换行
Fixes #11296

ulog_tail_formater() 原来先写换行再写 CSI_END,颜色复位落在下一行开头,
shell 提示符不会回到默认颜色。现在先写 CSI_END,再写换行。
2026-10-09 08:58:47 +08:00
Tim Wang c3e94f7b5f [lwip] fix sio_write signature conflict 2026-10-03 12:59:43 +08:00
Tim Wang 8bdb76a12c [lwip] clean lwip doc files 2026-10-03 12:59:43 +08:00
Tim Wang f1cc628cf2 [lwip] add lwIP 2.2.1 as a selectable version alongside 1.4.1/2.0.3/2.1.2
- Kconfig: RT_USING_LWIP221 choice, RT_USING_LWIP_VER_NUM=0x20201
  - SConscript for lwip-2.2.1 (acd.c, mdns split files, tftp.c)
  - replay RTT patch set from lwip-2.1.2 onto 2.2.1
  - import RTT ping.c and tftp_port.c (adapted to 2.2.x TFTP API)
  - SAL: version-gated netconn socket accessor (callback_arg union >= 2.2.0)
  - lwipopts: DHCP ACD (RFC 5227) and MEMP_NUM_SYS_TIMEOUT version gates
2026-10-03 12:59:43 +08:00
Tim Wang 4422241f09 [lwip] import pristine lwIP 2.2.1 source tree
Verbatim upstream lwIP 2.2.1 official release (STABLE-2.2.1),
  complete with apps/, test/ and Filelists.
2026-10-03 12:59:43 +08:00
蒙蒙plus 05badce954 [drivers][ipc] 移除 SConscript 中冗余的 __RT_IPC_SOURCE__ 宏定义 2026-09-27 12:18:44 +08:00
Onlyou_tzZ 0edbc15ea9 [cherryusb][fsdev] add N32H4x USBFS device support #11764 2026-09-21 15:43:37 +08:00
wyf-777 3eff2d5c7e [net][at] Reject overlong numeric hostnames
Numeric hostnames were copied into a fixed stack buffer without a length bound.

Cache the length, reject values that cannot fit, and terminate the copy explicitly.

Fixes #11332

Assisted-by: OpenAI Codex:GPT-5
2026-09-21 10:18:56 +08:00
zhangyuyang 5d1aee9b32 [components][sdio] Fix CIS tuple memory leak 2026-09-21 10:12:51 +08:00
zhangyuyang c2f5a28321 [components][sdio] fix possible memory leak of sdio driver unregistration 2026-09-21 09:34:06 +08:00