[Asterisk-code-review] res pjsip transport websocket: Fix use-after-free bugs. (asterisk[master])

Ivan Poddubny asteriskteam at digium.com
Mon Jun 8 14:46:15 CDT 2015


Hello Joshua Colp,

I'd like you to reexamine a change.  Please visit

    https://gerrit.asterisk.org/598

to look at the new patch set (#4).

Change subject: res_pjsip_transport_websocket: Fix use-after-free bugs.
......................................................................

res_pjsip_transport_websocket: Fix use-after-free bugs.

This patch fixes use-after-free bugs caught by AddressSanitizer.

1. PJSIP transport manager may decide to destroy transport on its own.
For example, when the contact registered via websocket has not renewed
its registration in time. The transport was destoyed, but the websocket
listener thread was still active until the socket closes, and then tried
to call transport_shutdown on transport that has been freed.

Also, the transport destructor accessed wstransport->rdata.tp_info.pool
right after freeing memory that contained wstransport itself.

This patch converts transport to an ao2 object, allowing it to be
refcounted, so that it is available until both websocket listener and
pjsip transport manager are finished with it.

2. The websocket listener deletes the last reference on websocket session
when the tcp connection is closed, and it gets destroyed, but
the transport manager may still use it, for example when disconnect
happens in the middle of a SIP transaction.

A new reference to websocket session has been added that is released
with the transport to prevent this.

ASTERISK-25096 #close
Reported by: Josh Kitchens

ASTERISK-24963 #close
Reported by: Badalian Vyacheslav

Change-Id: Idc0b63eb6e459c1ddfb2430127d34b3c4d8d373b
---
M res/res_pjsip_transport_websocket.c
1 file changed, 33 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/598/4
-- 
To view, visit https://gerrit.asterisk.org/598
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Idc0b63eb6e459c1ddfb2430127d34b3c4d8d373b
Gerrit-PatchSet: 4
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Ivan Poddubny <ivan.poddubny at gmail.com>
Gerrit-Reviewer: Ivan Poddubny <ivan.poddubny at gmail.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list