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 84d0b66107f845c4b1380a3c9423c4a0de2d8e1b Author: dongjiuzhu1 <[email protected]> AuthorDate: Tue Feb 3 13:58:01 2026 +0800 mm/iob: use IOB_LINK_GET macro to access io_flink to prevent unaligned access. When calling iob_peek_queue, the iob retrieved from the queue may have its io_flink field containing a flink pointer. Directly accessing this field could cause unaligned memory access issues. To solve this problem, all places in the code that access io_flink must use the IOB_LINK_GET macro to properly retrieve the link pointer, ensuring proper memory alignment and preventing potential crashes or undefined behavior on architectures that don't support unaligned access. issue backtrace: 0x4619513d in iob_copyout ../../nuttx/mm/iob/iob_copyout.c:91 0x46397a8d in icmp_readahead ../../nuttx/net/icmp/icmp_recvmsg.c:236 0x463988ae in icmp_recvmsg ../../nuttx/net/icmp/icmp_recvmsg.c:345 0x4625816c in psock_recvmsg ../../nuttx/net/socket/recvmsg.c:110 0x46254d20 in psock_recvfrom ../../nuttx/net/socket/recvfrom.c:96 0x4625513b in recvfrom ../../nuttx/net/socket/recvfrom.c:202 0x46525805 in icmp_ping ../../apps/netutils/ping/icmp_ping.c:379 0x4a536181 in ping_main ../../apps/system/ping/ping.c:403 0x46acb9a0 in nxtask_startup ../../nuttx/libs/libc/sched/task_startup.c:66 0x4640d722 in nxtask_start ../../nuttx/sched/task/task_start.c:107 0x46782807 in pre_start ../../nuttx/arch/sim/src/sim/sim_initialstate.c:57 Signed-off-by: dongjiuzhu1 <[email protected]> --- mm/iob/iob_alloc.c | 4 ++-- mm/iob/iob_clone.c | 12 ++++++------ mm/iob/iob_concat.c | 4 ++-- mm/iob/iob_contig.c | 2 +- mm/iob/iob_copyin.c | 4 ++-- mm/iob/iob_copyout.c | 4 ++-- mm/iob/iob_count.c | 2 +- mm/iob/iob_dump.c | 2 +- mm/iob/iob_free.c | 2 +- mm/iob/iob_pack.c | 4 ++-- mm/iob/iob_reserve.c | 2 +- mm/iob/iob_tailroom.c | 4 ++-- mm/iob/iob_test.c | 2 +- mm/iob/iob_trimhead.c | 2 +- mm/iob/iob_trimtail.c | 2 +- mm/iob/iob_update_pktlen.c | 8 ++++---- 16 files changed, 30 insertions(+), 30 deletions(-) diff --git a/mm/iob/iob_alloc.c b/mm/iob/iob_alloc.c index 0073eee7254..8d83dbc6971 100644 --- a/mm/iob/iob_alloc.c +++ b/mm/iob/iob_alloc.c @@ -88,7 +88,7 @@ static FAR struct iob_s *iob_alloc_committed(void) { /* Remove the I/O buffer from the committed list */ - g_iob_committed = iob->io_flink; + g_iob_committed = IOB_LINK_GET(iob); /* Put the I/O buffer in a known state */ @@ -125,7 +125,7 @@ static FAR struct iob_s *iob_tryalloc_internal(bool throttled) * IOBs. */ - g_iob_freelist = iob->io_flink; + g_iob_freelist = IOB_LINK_GET(iob); g_iob_count--; DEBUGASSERT(g_iob_count >= 0); diff --git a/mm/iob/iob_clone.c b/mm/iob/iob_clone.c index fadb56603a8..084cd6432ec 100644 --- a/mm/iob/iob_clone.c +++ b/mm/iob/iob_clone.c @@ -50,7 +50,7 @@ static int iob_next(FAR struct iob_s *iob, bool throttled, bool block) { - FAR struct iob_s *next = iob->io_flink; + FAR struct iob_s *next = IOB_LINK_GET(iob); /* Allocate new destination I/O buffer and hook it into the * destination I/O buffer chain. @@ -140,7 +140,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len, while (iob1 != NULL && (int)(offset1 - iob1->io_len) >= 0) { offset1 -= iob1->io_len; - iob1 = iob1->io_flink; + iob1 = IOB_LINK_GET(iob1); } /* Skip requested offset from the destination iob */ @@ -162,7 +162,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len, return ret; } - iob2 = iob2->io_flink; + iob2 = IOB_LINK_GET(iob2); } /* Pack each entry from iob1 to iob2 */ @@ -213,7 +213,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len, { /* Yes.. move to the next source I/O buffer */ - iob1 = iob1->io_flink; + iob1 = IOB_LINK_GET(iob1); } while (iob1 && iob1->io_len <= 0); @@ -235,7 +235,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len, return ret; } - iob2 = iob2->io_flink; + iob2 = IOB_LINK_GET(iob2); offset2 = 0; } } @@ -255,7 +255,7 @@ int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled, bool block) { DEBUGASSERT(iob2->io_len == 0 && iob2->io_offset == 0 && - iob2->io_pktlen == 0 && iob2->io_flink == NULL); + iob2->io_pktlen == 0 && IOB_LINK_GET(iob2) == NULL); return iob_clone_partial(iob1, iob1->io_pktlen, 0, iob2, 0, throttled, block); diff --git a/mm/iob/iob_concat.c b/mm/iob/iob_concat.c index 7404743f65a..82ca19b9408 100644 --- a/mm/iob/iob_concat.c +++ b/mm/iob/iob_concat.c @@ -53,9 +53,9 @@ void iob_concat(FAR struct iob_s *iob1, FAR struct iob_s *iob2) /* Find the last buffer in the iob1 buffer chain */ - while (iob1->io_flink) + while (IOB_LINK_GET(iob1) != NULL) { - iob1 = iob1->io_flink; + iob1 = IOB_LINK_GET(iob1); } /* Then connect iob2 buffer chain to the end of the iob1 chain */ diff --git a/mm/iob/iob_contig.c b/mm/iob/iob_contig.c index 0327e98d780..1906ea16371 100644 --- a/mm/iob/iob_contig.c +++ b/mm/iob/iob_contig.c @@ -92,7 +92,7 @@ int iob_contig(FAR struct iob_s *iob, unsigned int len) { /* Get the next I/O buffer in the chain */ - next = iob->io_flink; + next = IOB_LINK_GET(iob); DEBUGASSERT(next != NULL); /* Copy what we need or what we can from the next buffer */ diff --git a/mm/iob/iob_copyin.c b/mm/iob/iob_copyin.c index b7e060ba786..b74528b320e 100644 --- a/mm/iob/iob_copyin.c +++ b/mm/iob/iob_copyin.c @@ -91,14 +91,14 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, while ((int)(offset - iob->io_len) > 0) { offset -= iob->io_len; - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); } /* Then loop until all of the I/O data is copied from the user buffer */ while (len > 0) { - next = iob->io_flink; + next = IOB_LINK_GET(iob); /* Get the destination I/O buffer address and the amount of data * available from that address. diff --git a/mm/iob/iob_copyout.c b/mm/iob/iob_copyout.c index 68808e3d7a5..33c392b4c12 100644 --- a/mm/iob/iob_copyout.c +++ b/mm/iob/iob_copyout.c @@ -71,7 +71,7 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob, while ((int)(offset - iob->io_len) >= 0) { offset -= iob->io_len; - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); if (iob == NULL) { /* We have no requested data in iob chain */ @@ -106,7 +106,7 @@ int iob_copyout(FAR uint8_t *dest, FAR const struct iob_s *iob, /* Skip to the next I/O buffer in the chain */ - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); offset = 0; } diff --git a/mm/iob/iob_count.c b/mm/iob/iob_count.c index cd193dd65d5..56feb316ed6 100644 --- a/mm/iob/iob_count.c +++ b/mm/iob/iob_count.c @@ -45,7 +45,7 @@ int iob_count(FAR struct iob_s *iob) int count; for (count = 0; iob != NULL; - iob = iob->io_flink, count++); + iob = IOB_LINK_GET(iob), count++); return count; } diff --git a/mm/iob/iob_dump.c b/mm/iob/iob_dump.c index 570987d3523..5af58422e15 100644 --- a/mm/iob/iob_dump.c +++ b/mm/iob/iob_dump.c @@ -100,7 +100,7 @@ void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len, /* Dump I/O buffer headers */ - for (; iob; iob = iob->io_flink) + for (; iob; iob = IOB_LINK_GET(iob)) { syslog(LOG_DEBUG, " iob=%p len=%d offset=%d\n", iob, iob->io_len, iob->io_offset); diff --git a/mm/iob/iob_free.c b/mm/iob/iob_free.c index 0e8b7413b8a..4d9cfc56b5a 100644 --- a/mm/iob/iob_free.c +++ b/mm/iob/iob_free.c @@ -79,7 +79,7 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob) { - FAR struct iob_s *next = iob->io_flink; + FAR struct iob_s *next = IOB_LINK_GET(iob); irqstate_t flags; #ifdef CONFIG_IOB_NOTIFIER int16_t navail; diff --git a/mm/iob/iob_pack.c b/mm/iob/iob_pack.c index 0f3e0db3fe2..ede5501496f 100644 --- a/mm/iob/iob_pack.c +++ b/mm/iob/iob_pack.c @@ -55,7 +55,7 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob) /* Handle special cases, preserve at least one iob. */ - while (iob->io_len <= 0 && iob->io_flink != NULL) + while (iob->io_len <= 0 && IOB_LINK_GET(iob) != NULL) { iob = iob_free(iob); } @@ -68,7 +68,7 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob) while (iob) { - next = iob->io_flink; + next = IOB_LINK_GET(iob); /* Eliminate the data offset in this entry */ diff --git a/mm/iob/iob_reserve.c b/mm/iob/iob_reserve.c index 7f6fafd2c69..637d75c0a34 100644 --- a/mm/iob/iob_reserve.c +++ b/mm/iob/iob_reserve.c @@ -73,7 +73,7 @@ void iob_reserve(FAR struct iob_s *iob, unsigned int reserved) iob->io_len -= trimlen; iob->io_offset = offset; - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); reserved -= offset; } } diff --git a/mm/iob/iob_tailroom.c b/mm/iob/iob_tailroom.c index ee478e313c1..971d0215dc9 100644 --- a/mm/iob/iob_tailroom.c +++ b/mm/iob/iob_tailroom.c @@ -45,9 +45,9 @@ unsigned int iob_tailroom(FAR struct iob_s *iob) { - while (iob->io_flink != NULL) + while (IOB_LINK_GET(iob) != NULL) { - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); } return IOB_BUFSIZE(iob) - (iob->io_offset + iob->io_len); diff --git a/mm/iob/iob_test.c b/mm/iob/iob_test.c index d9a8767241f..e5650aab0c2 100644 --- a/mm/iob/iob_test.c +++ b/mm/iob/iob_test.c @@ -66,7 +66,7 @@ static void dump_chain(struct iob_s *iob) printf("%d. len=%d, offset=%d\n", n, iob->io_len, iob->io_offset); pktlen += iob->io_len; - iob = iob->io_flink; + iob = IOB_LINK_GET(iob); n++; } diff --git a/mm/iob/iob_trimhead.c b/mm/iob/iob_trimhead.c index e78f0380528..169297321be 100644 --- a/mm/iob/iob_trimhead.c +++ b/mm/iob/iob_trimhead.c @@ -77,7 +77,7 @@ FAR struct iob_s *iob_trimhead(FAR struct iob_s *iob, unsigned int trimlen) /* Check if this was the last entry in the chain */ - next = iob->io_flink; + next = IOB_LINK_GET(iob); if (next == NULL) { /* Yes.. break out of the loop returning the empty diff --git a/mm/iob/iob_trimtail.c b/mm/iob/iob_trimtail.c index 84befd99f72..b6f31a6e0a6 100644 --- a/mm/iob/iob_trimtail.c +++ b/mm/iob/iob_trimtail.c @@ -69,7 +69,7 @@ FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen) penultimate = NULL; last = NULL; - for (entry = iob; entry; entry = entry->io_flink) + for (entry = iob; entry; entry = IOB_LINK_GET(entry)) { /* Remember the last and the next to the last in the chain */ diff --git a/mm/iob/iob_update_pktlen.c b/mm/iob/iob_update_pktlen.c index fac126ccaa7..12a660b4f26 100644 --- a/mm/iob/iob_update_pktlen.c +++ b/mm/iob/iob_update_pktlen.c @@ -76,7 +76,7 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, remain -= IOB_BUFSIZE(next) - next->io_offset; } - next = next->io_flink; + next = IOB_LINK_GET(next); } if (remain > 0) @@ -113,7 +113,7 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, else { penultimate = next; - next = next->io_flink; + next = IOB_LINK_GET(next); } } } @@ -128,7 +128,7 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, while (next != NULL && nrequire > ninqueue) { next->io_flink = iob_tryalloc(throttled); - next = next->io_flink; + next = IOB_LINK_GET(next); ninqueue++; } } @@ -151,7 +151,7 @@ int iob_update_pktlen(FAR struct iob_s *iob, unsigned int pktlen, next->io_len = len; pktlen -= len; - next = next->io_flink; + next = IOB_LINK_GET(next); } /* Adjust final pktlen if it's not fully increased (e.g. alloc fail) */
