Skip to content

Conversation

@szymon-czapracki
Copy link
Contributor

This PR fixes a bug in os_mbuf_dup() that could corrupt memory when duplicating an mbuf chain built from multiple pools of different payload sizes. The previous implementation assumed all segments could be duplicated from the head segment’s pool. When a later segment was larger than the head’s payload size, the memcpy() could write past the destination buffer.

The fix itself is based on apache/mynewt-nimble#2118

Funciton os_mbuf_dup() can overflow on mixed-pool mbuf chains.
It assumes all mbufs match the first pool’s size and memcpy()s
larger segments past the destination.
Make duplication pool-aware.
@github-actions github-actions bot added the size/m label Oct 9, 2025
@szymon-czapracki szymon-czapracki marked this pull request as draft October 9, 2025 20:07
@szymon-czapracki szymon-czapracki force-pushed the mbuf_dup_fix branch 2 times, most recently from 8d0ca6f to 25649d4 Compare October 10, 2025 11:11
@szymon-czapracki szymon-czapracki marked this pull request as ready for review October 10, 2025 11:18
@szymon-czapracki szymon-czapracki force-pushed the mbuf_dup_fix branch 3 times, most recently from d5f2b8e to 1fe7c96 Compare October 10, 2025 13:44
Adds a test that duplicates a small and large mbuf chain.
verifies the second segment comes from the correct pool.
Checks lengths/payloads, and uses inner/outer guards to catch
memcpy overruns—exposing “all-from-head” bug.
@sjanc sjanc merged commit 3845269 into apache:master Oct 15, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants