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 2e81adf56ba4efe39e5d1eddc98c5492f7166bef Author: vela-autotest08 <[email protected]> AuthorDate: Sat Aug 1 00:45:26 2026 +0800 mm/iob: preserve IOB_CHAIN_END when growing chain in iob_update_pktlen. Root cause: iob_update_pktlen() extended an IOB chain by directly assigning `next->io_flink = iob_tryalloc_next(...)`, which overwrote the old tail's io_flink and dropped any IOB_CHAIN_END queue flag while leaving the new tail with a plain NULL io_flink. This is inconsistent with iob_copyin(), which explicitly carries IOB_CHAIN_END from the old tail to the new tail. When a chain that also resides in an iob_queue (e.g. the netdev TX queue) was grown through this path, the queue lost its chain boundary marker, so later iob_add_queue()/iob_remove_queue() walked past the real chain end and dereferenced stale/freed IOB pointers, causing a data abort in iob_add_queue() during curl upload R X (hpwork, dev->d_iob use-after-free, io_flink holding a freed-IOB poison value). Fix: mirror iob_copyin() - carry IOB_FLAG_GET(next) onto the newly allocated tail before linking, and clear the flag on the old tail. On allocation failure, stop extending and let the pktlen adjustment below account for the shortfall instead of clobbering the tail link. Signed-off-by: vela-autotest08 <[email protected]> --- mm/iob/iob_update_pktlen.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/mm/iob/iob_update_pktlen.c b/mm/iob/iob_update_pktlen.c index 12a660b4f26..a4d49ed0dfb 100644 --- a/mm/iob/iob_update_pktlen.c +++ b/mm/iob/iob_update_pktlen.c @@ -50,6 +50,7 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, bool throttled) { FAR struct iob_s *penultimate; + FAR struct iob_s *newnext; FAR struct iob_s *next; int remain = pktlen; int ninqueue = 0; @@ -127,9 +128,36 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, while (next != NULL && nrequire > ninqueue) { - next->io_flink = iob_tryalloc(throttled); - next = IOB_LINK_GET(next); - ninqueue++; + newnext = iob_tryalloc(throttled); + + /* 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. This mirrors the + * chain-extension logic in iob_copyin(); without it, extending + * a chain that also sits in an iob_queue loses the IOB_CHAIN_END + * marker and corrupts the queue's chain boundaries, which can + * later make iob_add_queue()/iob_remove_queue() walk past the + * real chain end and dereference stale/freed IOB pointers. + */ + + if (newnext != NULL) + { + IOB_FLAG_SET(newnext, NULL, IOB_FLAG_GET(next)); + next->io_flink = newnext; + next = newnext; + ninqueue++; + } + else + { + /* No more buffers available; stop extending. The pktlen + * adjustment below accounts for the shortfall. + */ + + next->io_flink = NULL; + break; + } } }
