cederom opened a new pull request, #22146: URL: https://github.com/apache/nuttx/pull/22146
## Summary `ip_fragin_check()` marked a datagram as complete as soon as a tail fragment's offset equalled the summed length of the preceding more-fragments entries but did not require the zero fragment what might lead to invalid memory access. The sum-based test also accepted overlapping fragments (producing a reassembled packet with a hole in it) and fragments located beyond the tail fragment (which were concatenated past the end of the datagram). Only declare the datagram complete when both the zero and the tail fragment have been seen and the offset-ordered list starts at 0, has no holes or overlaps and ends with the tail fragment. Added `DEBUGASSERT` in both reassembly functions documenting this precondition. Assisted-by: Claude:claude-opus-5.5 ## Impact * Fix for the TCP/IP IPv4/IPv6 users with `CONFIG_NET_IPFRAG=y` (default off). ## Testing **Anyone with good network setup with NuttX board and (fragmenting fuzzer) packet generator please help testing! :-)** ### Functional test Functional comparison test (using [test.tar.gz](https://github.com/user-attachments/files/35222719/test.tar.gz)): ``` % cc -Wall -Wextra -o test ipfrag_check_test.c && ./test Functional test before/old and after/new results comparison: normal 3 frags in order old=COMPLETE new=COMPLETE ok normal 3 frags reversed old=COMPLETE new=COMPLETE ok duplicate of middle frag old=COMPLETE new=COMPLETE ok REPORT: no zero frag (8/16 + tail16) old=COMPLETE new=wait ok no zero frag, overlapping MF + tail old=COMPLETE new=wait ok hole: 0/16, tail at 24 + 40 MF old=wait new=wait ok overlap: 0/16, 8/8, tail 24 old=COMPLETE new=wait ok frag beyond tail (arrives first) old=COMPLETE new=wait ok missing middle, tail first old=wait new=wait ok ``` New/Old were extracted like this: ``` % extract(){ awk '/^static void ip_fragin_check\(.*\)$/{p=1} p{print} p&&/^}/{exit}' "$1" \ | sed '1s/ip_fragin_check/ip_fragin_check_'"$2"'/'; } % extract old/net/ipfrag/ipfrag.c old > old.inc % extract new/net/ipfrag/ipfrag.c new > new.inc ``` ### Build test ``` $ uname -a Linux hexagon 5.15.0 FreeBSD 14.5-RELEASE-p4 releng/14.5-n274932-1e85e58a3d48 GENERIC x86_64 GNU/Linux $ git reflog -1 0bbdef55d45 (HEAD -> cederom-20261122-ip_reassembly_no_offset0_fix, cederom/cederom-20261122-ip_reassembly_no_offset0_fix) HEAD@{0}: commit (amend): net/ipfrag: Fix IPv4/IPv6 incomplete/incontiguous fragments reassembly. % grep -r CONFIG_NET_IPFRAG boards/sim/sim/sim/configs boards/sim/sim/sim/configs/windows64/defconfig:CONFIG_NET_IPFRAG=y boards/sim/sim/sim/configs/dynconns/defconfig:CONFIG_NET_IPFRAG=y boards/sim/sim/sim/configs/windows/defconfig:CONFIG_NET_IPFRAG=y $ ./tools/configure.sh sim:dynconns Copy files Select CONFIG_HOST_LINUX=y Refreshing... (..) # # configuration written to .config # $ make -j Create version.h LN: platform/board to /XXX/nuttx-apps.git/platform/dummy Register: init Register: nsh Register: sh Register: dd CP: /XXX/nuttx.git/include/nuttx/config.h CP: /XXX/nuttx.git/include/nuttx/fs/hostfs.h In file included from bluetooth/bt_hcicore.c:66: bluetooth/bt_queue.h:61:4: warning: #warning WARNING: not enough pre-allocated messages [-Wcpp] 61 | # warning WARNING: not enough pre-allocated messages | ^~~~~~~ In file included from bluetooth/bt_conn.c:59: bluetooth/bt_queue.h:61:4: warning: #warning WARNING: not enough pre-allocated messages [-Wcpp] 61 | # warning WARNING: not enough pre-allocated messages | ^~~~~~~ In file included from bluetooth/bt_queue.c:38: bluetooth/bt_queue.h:61:4: warning: #warning WARNING: not enough pre-allocated messages [-Wcpp] 61 | # warning WARNING: not enough pre-allocated messages | ^~~~~~~ CC: tcp/tcp_recvwindow.c tcp/tcp_input.c: In function ‘tcp_input’: tcp/tcp_send.c: In function ‘tcp_send’: tcp/tcp_send.c:387:9: note: ‘#pragma message: CONFIG_NET_TCP_DEBUG_DROP_SEND is selected, this is debug feature to drop the tcp send packet on the floor, please confirm the configuration again if you do not want debug the TCP stack.’ 387 | #pragma message \ | ^~~~~~~ tcp/tcp_input.c:1201:9: note: ‘#pragma message: CONFIG_NET_TCP_DEBUG_DROP_RECV is selected, this is debug feature to drop the tcp received packet on the floor, please confirm the configuration again if you do not want debug the TCP stack.’ 1201 | #pragma message \ | ^~~~~~~ LD: nuttx Pac SIM with dynamic libs.. '/lib/x86_64-linux-gnu/libc.so.6' -> 'sim-pac/libs/libc.so.6' '/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/ld-linux-x86-64.so.2' SIM elf with dynamic libs archive in nuttx.tgz $ ./nuttx nsh> uname -a NuttX 13.1.1-RC0 0bbdef55d4 Nov 22 2026 00:36:29 sim sim nsh> help help usage: help [-v] [<cmd>] . break exec mkdir rm true [ cat exit mkfifo rmdir truncate ? cd expr mkrd rmmod uname addroute cp false mount set umount alias cmp help mv kill unset unalias dirname hexdump nslookup sleep uptime arp date insmod poweroff usleep watch base64dec delroute losetup quit source xd base64enc dmesg ls printf test basename echo du pwd time Builtin Apps: dd init nsh sh ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
