nuttx/net
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
..
arp include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
bluetooth net/bluetooth: fix BTPROTO_HCI socket device lookup 2026-05-06 14:45:46 +08:00
can include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
devif net/ipfilter: Reassemble IPv6 fragments before filtering 2026-08-01 17:40:07 -03:00
icmp !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
icmpv6 !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
ieee802154 include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
igmp net/igmp: fix checksum validation that always dropped valid IGMP packets 2026-08-07 16:36:42 +08:00
inet include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
ipfilter include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
ipforward net/ipv4: Forward fragments before local reassembly 2026-08-01 17:40:07 -03:00
ipfrag net/ipv4: Forward fragments before local reassembly 2026-08-01 17:40:07 -03:00
local include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
mld !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
nat net/nat: Reassemble IPv6 fragments before NAT66 2026-08-01 17:40:07 -03:00
neighbor include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
netdev net/netdev/netdev_txnotify.c: add debug log with interface name 2026-05-06 01:16:40 +08:00
netfilter net/netfilter: fix match name for UDP in ipt_filter 2026-04-13 08:46:57 -03:00
netlink net/netlink: fix memory leak in netlink_get_neighbor 2026-04-13 08:46:57 -03:00
pkt include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
procfs !include/fcntl.h: align open flags with Linux values 2026-06-30 13:43:44 +08:00
route net/route: fix return value of net_writeroute_ipv6 2026-04-13 08:46:57 -03:00
rpmsg include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
sixlowpan net/sixlowpan: Fix protosize to 16-bit 2026-07-28 10:19:05 +08:00
socket include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
tcp net/tcp/tcp_send: Remove work_available check when updating retransmit timer 2026-08-05 10:56:59 +02:00
udp net/udp: fix d_len corruption for 2nd+ SO_REUSEADDR listener 2026-08-12 09:41:52 -03:00
usrsock arch/sim: Add AF_LOCAL support to host usrsock 2026-07-23 15:34:02 +08:00
utils !sys/types.h: change time_t and clock_t to int64_t to align with other OSes 2026-05-19 16:21:28 +08:00
CMakeLists.txt net: Support no-lto option for the network build. 2026-01-20 10:12:45 +08:00
Kconfig net: Support no-lto option for the network build. 2026-01-20 10:12:45 +08:00
Makefile tools: fix stale archive members surviving a Kconfig-driven CSRCS change 2026-07-28 21:26:03 -03:00
net_initialize.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00