Skip to content

pjmedia-videodev: fix use-after-free crash in v4l2_scan_devs() - #5327

Merged
nanangizz merged 2 commits into
pjsip:masterfrom
jeffreym-emt:fix-v4l2-scan-devs
Oct 9, 2026
Merged

nanangizz merged 2 commits into
pjsip:masterfrom
jeffreym-emt:fix-v4l2-scan-devs

Conversation

@jeffreym-emt

Copy link
Copy Markdown
Contributor

Closes #5326

v4l2_scan_devs() releases dev_pool during refresh but leaves dev_info pointing to freed memory. When the device count stays the same or decreases, allocation can be skipped, causing writes to freed memory and subsequent crashes during format enumeration.

This MR:

  • Resets dev_info to NULL after releasing its pool, ensuring a fresh device array is allocated.
  • Replaces the ineffective j < fmt_cnt check with pdi->info.fmt_cnt == 0, preventing devices without usable formats from being advertised.

Tested in the affected application and confirmed that the changes prevent the previously observed crash.

@CLAassistant

CLAassistant commented Oct 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@nanangizz nanangizz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, both changes look right. Clearing dev_info after the pool release makes the allocation unconditional, so a refresh with the same or fewer devices no longer copies into the released pool. And pdi->info.fmt_cnt == 0 replaces a check that could never be true (j == fmt_cnt after the size loop), so a device without any usable size is no longer listed with an empty format list.

Optional: with dev_info always NULL at that point, f->dev_count > old_count || f->dev_info == NULL is always true, so the condition and old_count could be dropped and the array allocated unconditionally.

@jeffreym-emt
jeffreym-emt requested a review from nanangizz October 8, 2026 13:56
@nanangizz
nanangizz merged commit 19b366a into pjsip:master Oct 9, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pjmedia-videodev: V4L2 device refresh can cause use-after-free crash

4 participants