]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip_pubsub: Eliminate race during initial NOTIFY. 67/1267/2
authorMark Michelson <mmichelson@digium.com>
Wed, 16 Sep 2015 22:36:32 +0000 (17:36 -0500)
committerMark Michelson <mmichelson@digium.com>
Thu, 17 Sep 2015 16:12:16 +0000 (11:12 -0500)
commit20702e0cf23c159a22350ccc0fd37cff2a098072
tree7eeae626f6e86d2cfb20b65fd283212747b34246
parent3ef74244a4711d20faad7a166256c50a42f6ef0a
res_pjsip_pubsub: Eliminate race during initial NOTIFY.

There is a slim chance of a race condition occurring where two threads
can both attempt to manipulate the same area.

Thread A can be handling an incoming initial SUBSCRIBE request. Thread A
lets the specific subscription handler know that the subscription has
been established.

At this point, Thread B may detect a state change on the subscribed
resource and queue up a notification task on Thread C, the subscription
serializer thread.

Now Thread A attempts to generate the initial NOTIFY request to send to
the subscriber at the same time that Thread C attempts to generate a
state change NOTIFY request to send to the subscriber.

The result is that Threads A and C can step on the same memory area,
resulting in a crash. The crash has been observed as happening when
attempting to allocate more space to hold the body for the NOTIFY.

The solution presented here is to queue the subscription establishment
and initial NOTIFY generation onto the subscription serializer thread
(Thread C in the above scenario). This way, there is no way that a state
change notification can occur before the initial NOTIFY is sent, and if
there is a quick succession of NOTIFYs, we can guarantee that the two
NOTIFY requests will be sent in succession.

Change-Id: I5a89a77b5f2717928c54d6efb9955e5f6f5cf815
res/res_pjsip_pubsub.c