]> git.ipfire.org Git - thirdparty/libvirt.git/commit
remoteDispatchAuthPolkit: Fix lock ordering deadlock if client closes connection...
authorPeter Krempa <pkrempa@redhat.com>
Wed, 17 Jan 2024 14:55:35 +0000 (15:55 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jan 2024 14:25:53 +0000 (15:25 +0100)
commitc697aff8a1b5542d51c0b4a10046ad37089d12d5
tree9eae328618f19fbb0aebdeb0f7556166c9b61300
parentf95675fdbb42eee07fc4864d7c135dcb8b00c3a9
remoteDispatchAuthPolkit: Fix lock ordering deadlock if client closes connection during auth

Locks in following text:
A: virNetServer
B: virNetServerClient
C: daemonClientPrivate

'virNetServerSetClientAuthenticated' locks A then B

'remoteDispatchAuthPolkit' calls 'virNetServerSetClientAuthenticated'
while holding C.

If a client closes its connection 'virNetServerProcessClients' with the
lock A and B locked will call 'virNetServerClientCloseLocked' which will
try to dispose of the 'client' private data by:

  ref(b);
  unlock(b);
  remoteClientFreePrivateCallbacks();
  lock(b);
  unref(b);

Unfortunately remoteClientFreePrivateCallbacks() tries lock C.

Thus the locks are held in the following order:

 polkit auth: C -> A
 connection close: A -> C

causing a textbook-example deadlock. To resolve it we can simply drop
lock 'C' before calling 'virNetServerSetClientAuthenticated' as the lock
is not needed any more.

Resolves: https://issues.redhat.com/browse/RHEL-20337
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/remote/remote_daemon_dispatch.c