gstpad: Avoid race in (un)setting EOS flag on sinkpads
authorEdward Hervey <edward@centricular.com>
Wed, 21 Sep 2022 08:05:05 +0000 (10:05 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Mon, 7 Nov 2022 05:28:39 +0000 (06:28 +0100)
commit605cb6a4d464567880b3a957de2323bb8fb344f9
treee6c01c08606221592bb263342e02eef031139d93
parente81e212610de50bd853da59bbf032933e3e457b2
gstpad: Avoid race in (un)setting EOS flag on sinkpads

The scenario is the following:

* Thread 1 is pushing an EOS event on a sinkpad
* Thread 2 is pushing a STREAM_START event on the same sinkpad before Thread 1
returns. Note : It starts pushing the event after Thread 1 took the object lock.

There is a potential race between:

* The moment Thread 1 sets the EOS flag once it has finished sending the
event (via store_sticky_event). When it does that it has both the STREAM and
OBJECT lock

* The moment Thread 2 sends the STREAM_START event (Which should release that
EOS status), but removing the EOS flag is only done while holding the OBJECT
lock and not the STREAM_LOCK, which means it could be re-set by Thread 1 before
it then checks again the EOS flag (without the STREAM lock taken).

The EOS flag unsetting by STREAM_START should be done with the STREAM lock
taken, otherwise it will be racy.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1452

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3320>
subprojects/gstreamer/gst/gstpad.c