This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e1f6c600c7e441b10aa82527c011a2154f2bd03a
Author: vela-autotest05 <[email protected]>
AuthorDate: Wed Aug 5 00:05:36 2026 +0800

    mm/iob: preserve IOB_CHAIN_END when growing chain in iob_clone_partial.
    
    Root cause: iob_next() (the chain-extension helper used by
    iob_clone_partial()) hooked a newly allocated tail IOB into the
    destination chain via a direct `iob->io_flink = next` assignment.
    This overwrote the old tail's io_flink and dropped any IOB_CHAIN_END
    queue flag stored in its low bits, leaving the new tail with a plain
    NULL io_flink. When a chain that also resides in an iob_queue (e.g.
    dev->d_iob queued for ARP/neighbor resolution or TX) was grown through
    iob_clone_partial() (devif_iobsend / RX clone paths), the queue lost
    its chain boundary marker; a later iob_add_queue() walked past the real
    chain end and dereferenced a stale/freed IOB pointer, causing an
    AddressSanitizer SEGV read in iob_add_queue() during the curl download
    integration test.
    
    This is the same class of bug already fixed in iob_copyin() (24413a0234a)
    and iob_update_pktlen() (d8039c9384a); iob_clone_partial was missed
    because the IOB_CHAIN_END low-bit-flag mechanism (054b1f3702f) never
    touched iob_clone.c.
    
    Fix: mirror iob_copyin()/iob_update_pktlen() - carry IOB_FLAG_GET(iob)
    onto the newly allocated tail before linking, and let the direct
    io_flink assignment clear the flag on the old tail. For chains that do
    not carry IOB_CHAIN_END (the common fresh-destination case) the
    behaviour is unchanged.
    
    Signed-off-by: vela-autotest05 <[email protected]>
---
 mm/iob/iob_clone.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mm/iob/iob_clone.c b/mm/iob/iob_clone.c
index 084cd6432ec..2a465b03bfb 100644
--- a/mm/iob/iob_clone.c
+++ b/mm/iob/iob_clone.c
@@ -73,6 +73,19 @@ static int iob_next(FAR struct iob_s *iob, bool throttled, 
bool block)
           return -ENOMEM;
         }
 
+      /* Add the new, empty I/O buffer to the end of the buffer chain.
+       * Carry over any queue flags (e.g. IOB_CHAIN_END) from the
+       * current tail to the new tail so that the chain boundary is
+       * preserved, then clear the flags on the old tail since it is
+       * no longer the last buffer in the chain.  Without this, extending
+       * a chain that also resides in an iob_queue loses the IOB_CHAIN_END
+       * marker and can later make iob_add_queue()/iob_remove_queue() walk
+       * past the real chain end and dereference stale/freed IOB pointers.
+       * Mirrors the chain-extension logic in iob_copyin() and
+       * iob_update_pktlen().
+       */
+
+      IOB_FLAG_SET(next, NULL, IOB_FLAG_GET(iob));
       iob->io_flink = next;
     }
   else

Reply via email to