Skip to content

[mod_sofia] use-after-free crash - ensure that sofia_private is cleared in all cases where the nh handle is destroyed (since it is allocated out of nh's memory pool).#3082

Open
creslin287 wants to merge 1 commit into
signalwire:masterfrom
creslin287:sofia_private_use_after_free
Open

Conversation

@creslin287

@creslin287 creslin287 commented Jul 15, 2026

Copy link
Copy Markdown

This particular bug was found when running load testing under very adverse calling circumstances. Bug originally manifested as a heap metadata corruption issue causing random crashes in memory allocation and free functions.

After running the test using ASAN, it was found that the corrupting write was during a call to sofia_on_hangup(). At this callsite, tech_pvt->nh had already been set to NULL somewhere else, but tech_pvt->sofia_private was still set to a non-NULL pointer. This is problematic as this likely meant that the nua_handle had been destroyed and any child allocations on the same memory pool (such as tech_pvt->sofia_private) were likely free'd and shouldn't be touched.

After auditing the event callback code path, a case was found where tech_pvt->nh was destroyed without clearing sofia_private, prompting this fix. After re-running the load test, this patch resolved our issue - no more crashes.

destroyed (it is allocated out of nh's memory pool).

This particular use case was found when running load testing under very adverse
calling circumstances.  Bug originally manifested as a heap metadata corruption
issue causing random crashes in memory allocation and free functions.

After running the test using ASAN, it was found that the corrupting write was
during a call to sofia_on_hangup().  At this callsite, tech_pvt->nh had already
been set to NULL somewhere else, but tech_pvt->sofia_private was still set to a
non-NULL pointer.  This is problematic as this likely meant that the nua_handle
had been destroyed and any child allocations on the same memory pool (such as
tech_pvt->sofia_private) were likely free'd and shouldn't be touched.

After auditing the event callback code path a case was found where tech_pvt->nh
was destroyed without clearing sofia_private, prompting this fix.  After
re-running the load test, this patch resolved our issue - no more crashes.
@creslin287 creslin287 changed the title Ensure that sofia_private is cleared in all cases where the nh handle is destroyed (it is allocated out of nh's memory pool). [mod_sofia] Ensure that sofia_private is cleared in all cases where the nh handle is destroyed (it is allocated out of nh's memory pool). Jul 15, 2026
@creslin287 creslin287 changed the title [mod_sofia] Ensure that sofia_private is cleared in all cases where the nh handle is destroyed (it is allocated out of nh's memory pool). [mod_sofia] Ensure that sofia_private is cleared in all cases where the nh handle is destroyed (since it is allocated out of nh's memory pool). Jul 15, 2026
@creslin287 creslin287 changed the title [mod_sofia] Ensure that sofia_private is cleared in all cases where the nh handle is destroyed (since it is allocated out of nh's memory pool). [mod_sofia] use-after-free crash - ensure that sofia_private is cleared in all cases where the nh handle is destroyed (since it is allocated out of nh's memory pool). Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant