]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip_pubsub: Eliminate race during initial NOTIFY. 68/1268/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:22 +0000 (11:12 -0500)
commite47396721f9c73b16ac7c7632dcd530f4e5b06c7
tree3a8a424725fd4a3872371d9ab8ff1b3e755a55b0
parent0a74c803004c1c7d4d53aecc9e818b63d5a1e9d6
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