zhhyu7 opened a new pull request, #22168:
URL: https://github.com/apache/nuttx/pull/22168

   ## Summary
   
   NET_BUFPOOL_TRYALLOC() returned zeroed memory, and the network code relied 
on that: the allocation helpers set only the few fields they care about and 
leave the rest at zero. Commit ae571a4ff8c ("net: 
   replace NET_BUFPOOL with MEMPOOL_DEFINE") replaced the pools with 
MEMPOOL_DEFINE, and mempool_allocate() does not clear the block, so a recycled 
structure now starts with the contents of its previous 
   user.                            
                                                                                
                                                                                
                                               
   devif_callback_alloc() is the clearest case. It only links the new callback 
into the lists it was given, so with a non-NULL list_head the stale nxtconn and 
prevconn survive, and with a NULL list_head so 
   do event, priv, flags and free_flags. The result is a corrupted callback 
list.                                                                           
                                                   
                                                      
   On a bridged simulator the node dies during netinit. First on the 
double-free check in devif_callback_free():
                                                                                
                                                                                
                                               
   dump_assert_info: Assertion failed : at file: devif/devif_callback.c:104 
task: netinit process: init_main
                                                      
                                                                                
                                                                                
                                               
   That DEBUGASSERT is what stops the damage from spreading. Removing it does 
not help, it only lets the corruption reach the pointer dereference, which was 
confirmed under gdb:
                                                      
   Program received signal SIGSEGV, Segmentation fault.                         
                                                                                
                                               
   0x000000004001c49a in devif_callback_free ()                                 
                         
   #0  devif_callback_free ()                                                   
                         
   #1  icmpv6_neighbor ()                                                       
                         
   #2  icmpv6_autoconfig ()                                                     
                         
   #3  psock_vioctl ()       
   #7  netlib_icmpv6_autoconfiguration ()
   #8  netinit_thread ()
   
   
   So the assertion is kept and the cause is fixed instead. The TCP write 
buffer shows the same class of failure once the node survives boot, because a 
recycled buffer keeps a stale wb_sent:
   
   dump_assert_info: Assertion failed : at file: tcp/tcp_send_buffered.c:1073 
task: tcpecho process: tcpecho
   
   
   All 19 mempool_allocate() call sites under net/ were audited; the ones that 
assumed zeroed memory are cleared after allocation: the devif callbacks, the 
forwarding structures, the TCP and UDP write 
   buffers, the UDP, ICMP, ICMPv6, netlink and packet connections, and the IPv4 
and IPv6 route entries. The sites that already fully initialize their structure 
are left untouched.
   
   This is a plain memset() for now. These should move to mempool_zallocate() 
once that helper exists.
   
   ## Impact
   
   Fixes a boot-time crash and TCP data-path corruption on any configuration 
built after ae571a4ff8c. Networking is unusable on the simulator without this 
change, so anything that enables CONFIG_NET is 
   affected, not only the simulator.
   
   No API, Kconfig or configuration change. The pools keep their current 
definitions, and the only behavioural difference is that a freshly allocated 
structure is zeroed again, as it was before ae571a4ff8c.
   
   ## Testing
   
   Host: Ubuntu x86_64, sim:dynconns (in tools/ci/testlist/sim-02.dat) with 
CONFIG_SIM_NET_BRIDGE=y, CONFIG_DEBUG_ASSERTIONS=y, tcpecho on port 80. Host 
bridge nuttx0 10.0.1.1/24, target 10.0.1.2/24.
   
   Before (apache/master, 960459c6503):
   
   === ICMP (ping) ===
   4 packets transmitted, 4 received, 0% packet loss
   === TCP echo: 4 conn x 256 KiB ===
   conn0: sent=2048 recv=0 err=TimeoutError('timed out')
   conn1: sent=2048 recv=0 err=TimeoutError('timed out')
   conn2: sent=2048 recv=0 err=TimeoutError('timed out')
   conn3: sent=2048 recv=0 err=TimeoutError('timed out')
   === sim alive / assert ===
   alive=no
   dump_assert_info: Assertion failed : at file: devif/devif_callback.c:104 
task: netinit process: init_main
   
   
   After (this change):
   
   === ICMP (ping) ===
   4 packets transmitted, 4 received, 0% packet loss
   rtt min/avg/max/mdev = 0.240/3.058/6.331/2.611 ms
   === TCP echo: 4 conn x 256 KiB ===
   conn0: sent=262144 recv=262144 err=None
   conn1: sent=262144 recv=262144 err=None
   conn2: sent=262144 recv=262144 err=None
   conn3: sent=262144 recv=262144 err=None
   === sim alive / assert ===
   alive=yes
   
   
   


-- 
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]

Reply via email to