]> git.ipfire.org Git - thirdparty/libvirt.git/commit
remote_daemon_stream: Hold an extra reference to stream in daemonStreamFilter
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Nov 2019 14:13:17 +0000 (15:13 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 29 Nov 2019 14:00:15 +0000 (15:00 +0100)
commit5e9bdccd92b271abdd3dedcd5ab9ee586da2fb94
tree6ef9cf659c43b1cf41c331059269e292b99be08e
parent21986f5047ba0e4d11268e2fcd9756ddabc78705
remote_daemon_stream: Hold an extra reference to stream in daemonStreamFilter

In v5.9.0-273-g8ecab214de I've tried to fix a lock ordering
problem, but introduced a crasher. Problem is that because the
client lock is unlocked (in order to honour lock ordering) the
stream we are currently checking in daemonStreamFilter() might be
freed and thus stream->priv might not even exist when the control
get to virMutexLock() call.

To resolve this, grab an extra reference to the stream and handle
its cleanup should the refcounter reach zero after the deref.
If that's the case and we are the only ones holding a reference
to the stream, we MUST return a positive value to make
virNetServerClientDispatchRead() break its loop where it iterates
over filters. The problem is, if we did not do so, then
"filter = filter->next" line will read from a memory that was
just freed (freeing a stream also unregisters its filter).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/remote/remote_daemon_stream.c