pipewire/spa/plugins/support
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
..
cpu-arm.c cpu: disable VFP asm when not available 2021-10-25 16:32:16 +02:00
cpu-x86.c cpu: only run SSE code when supported 2021-11-02 20:12:35 +01:00
cpu.c cpu: fix compilation on some architectures 2021-10-21 11:09:48 +02:00
dbus.c dbuf: use log topic 2021-10-03 12:27:20 +02:00
evl-plugin.c Add evl system support 2019-06-24 09:42:05 +02:00
evl-system.c treewide: replace strcmp() == 0 with spa_streq() 2021-05-18 22:10:27 +10:00
journal.c spa: support: do not include C source file 2021-09-29 15:07:36 +00:00
log-patterns.c json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
log-patterns.h spa: support: do not include C source file 2021-09-29 15:07:36 +00:00
logger.c support: close log file when we opened it 2022-02-08 11:30:39 +01:00
loop.c spa: support: loop: fix use-after-free when loop is reentered 2022-03-06 18:40:43 +00:00
meson.build treewide: meson.build: use feature.allowed() 2022-02-04 00:15:59 +01:00
node-driver.c support: add property to configure clock name 2021-12-10 11:22:23 +01:00
null-audio-sink.c Use configured quantum_limit instead of hardcoded value 2022-01-12 17:50:12 +01:00
plugin.c support: add null audio sink 2020-08-20 18:00:00 +02:00
system.c spa: sprinkle more log topics into spa 2021-09-28 09:35:39 +02:00