Skip to content

Can pbuf bug#39

Merged
johandc merged 3 commits intomasterfrom
can_pbuf_bug
Mar 10, 2026
Merged

Can pbuf bug#39
johandc merged 3 commits intomasterfrom
can_pbuf_bug

Conversation

@edvardxyz
Copy link
Copy Markdown

This PR removes use after free from pbuf functions

After freeing packet the code uses packet->next
Its more of an issue when task_woken is NULL meaning we are not in ISR
Also added fast bail out with return to jump out of while loop
After freeing packet the code uses packet->next
Its more of an issue when task_woken is NULL meaning we are not in ISR
Skip updating prev if packet is freed
The new return makes sure that it will not deref the freed packet next
iter.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes use-after-free behavior in the CAN and Ethernet pbuf linked-list management by ensuring traversal does not dereference freed nodes.

Changes:

  • Add early return after removing/freeing a specific pbuf in *_pbuf_free.
  • Update *_pbuf_cleanup to cache next before potential free and to avoid advancing via freed memory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/interfaces/csp_if_eth_pbuf.c Prevents UAF by returning after free and by iterating cleanup via a cached next pointer.
src/interfaces/csp_if_can_pbuf.c Same UAF prevention pattern applied to CAN pbuf free/cleanup traversal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@johandc johandc merged commit d7978b6 into master Mar 10, 2026
161 checks passed
@johandc johandc deleted the can_pbuf_bug branch March 10, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants