]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip_pubsub: Eliminate race during initial NOTIFY. 66/1266/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:03:13 +0000 (11:03 -0500)
commitfe5077b1f8caed2df419e1bd7b872657b7def726
tree57e1183187364d1d88640f31f6ff6021ef5dcca4
parent4fd0af298e48c65118b72618bb6e0edbba5d68d9
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