pipewire/spa
Barnabás Pőcze 7647ea7c83 spa: support: loop: fix use-after-free when loop is reentered
The core of the issue is the following: what happens if an
active source is destroyed before it could be dispatched?

For loop-managed sources (`struct source_impl`) this was addressed
by storing all destroyed sources in a list, and only freeing them
after dispatching has been finished. (0eb73f0f06)
This approach works for both strictly single-threaded
and `pw_thread_loop` loops assuming the loop is not
reentered.

However, if the loop is reentered, there can still be issues.
Assume that in one iteration sources A and B are active,
and returned from the system call, and source B is destroyed
before the loop starts dispatching. Consider what happens when
"A" is dispatched first, and it reenters the loop with timeout 0.
Imagine there are no new events, so `loop_iterate()` will immediately
return, but it will first destroy everything in the destroy list
(this is done at the end of `loop_iterate()`).
And herein lies the problem. In the previous iteration,
there exists a `spa_poll_event` object which points to source "B",
but that has just been destroyed at the end of the recursive
iteration. This will trigger a use-after-free once the previous
iteration inspects it.

Fix that by processing the destroy list right after first
processing the returned `spa_poll_event` objects, and
"detach" the source from the loop and its iterations
in `process_destroy()` before the source is destroyed.

See #2114 #2147
2022-03-06 18:40:43 +00:00
..
examples treewide: meson.build: use dependency variable for SPA 2021-12-28 18:34:06 +01:00
include spa: fix compilation with c++ 2022-03-01 21:40:30 +01:00
plugins spa: support: loop: fix use-after-free when loop is reentered 2022-03-06 18:40:43 +00:00
tests Fix build on recent FreeBSD 13-STABLE 2022-01-26 14:37:19 +03:00
tools json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
meson.build treewide: meson.build: use feature.allowed() 2022-02-04 00:15:59 +01:00