nuttx/net/udp
zhanghongyu 8422531f93 net/udp: fix d_len corruption for 2nd+ SO_REUSEADDR listener
In udp_input()'s broadcast/multicast fan-out loop, each iteration
calls netdev_iob_replace(dev, iob) to swap in a freshly cloned iob
before handing the packet to the next matching connection. That
function unconditionally sets dev->d_len = iob->io_pktlen, which is
the full frame length (IP + UDP headers + payload), undoing the
'dev->d_len -= udpiplen' done once before the loop to strip the
headers off for udp_input_conn().

As a result, every connection after the first sees a d_len that is
udpiplen (IP+UDP header length, eg 28 bytes for IPv4) too large.
This value flows into udp_datahandler() as buflen (it reads
dev->d_len directly) and is stored as the queued packet's declared
length in the connection's read-ahead iob chain. Once more than one
such oversized entry has queued up in the same chain, the consumer
(udp_readahead() in udp_recvfrom.c) parses the following entry's
metadata starting at the wrong offset, so whatever byte happens to
land on src_addr_size is trusted as-is. That single byte (0-255) is
then used as the length in iob_copyout(srcaddr, iob, src_addr_size,
...), which fills a fixed-size stack buffer with no bounds check
outside a DEBUGASSERT - compiled out in release builds - so an
oversized value overflows that stack buffer.

Re-apply the same '-= udpiplen' header-stripping after each
netdev_iob_replace() call in the loop, matching what's already done
once before the loop for the first connection.

Inside udp_input_conn, d_appdata is always set first, and since neither
the ICMP nor ICMPv6 process accesses d_appdata, the redundant d_appdata
settings have been removed.

Signed-off-by: yi chen <94xhn1@gmail.com>
2026-08-12 09:41:52 -03:00
..
CMakeLists.txt net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
Kconfig net: Enable dynamic allocation of tcp/udp/ipfwd buffer by default 2025-01-07 22:00:21 +08:00
Make.defs net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
udp.h net/devif_callback: change flags type from uint16_t to uint32_t 2026-01-02 00:04:16 +08:00
udp_callback.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_close.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_conn.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_devpoll.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_finddev.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
udp_input.c net/udp: fix d_len corruption for 2nd+ SO_REUSEADDR listener 2026-08-12 09:41:52 -03:00
udp_ioctl.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_ipselect.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_netpoll.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_notifier.c udp:Resolve UDP exit delay due to high CPU usage 2025-12-29 09:42:18 +08:00
udp_recvfrom.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_send.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_sendto_buffered.c net/udp: fix conn_unlock not called outside conditional block 2026-04-09 03:04:15 +08:00
udp_sendto_unbuffered.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_setsockopt.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_txdrain.c net: replace net_sem*wait with conn_dev_sem*wait to simplify code logic 2026-01-02 07:48:06 -03:00
udp_wrbuffer.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
udp_wrbuffer_dump.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00