libvirt/src/rpc
Marc Hartmayer 94bbbcee1f rpc: virnetserver: Fix race on srv->nclients_unauth
There is a race between virNetServerProcessClients (main thread) and
remoteDispatchAuthList/remoteDispatchAuthPolkit/remoteSASLFinish (worker
thread) that can lead to decrementing srv->nclients_unauth when it's
zero. Since virNetServerCheckLimits relies on the value
srv->nclients_unauth the underrun causes libvirtd to stop accepting
new connections forever.

Example race scenario (assuming libvirtd is using policykit and the
client is privileged):
  1. The client calls the RPC remoteDispatchAuthList =>
     remoteDispatchAuthList is executed on a worker thread (Thread
     T1). We're assuming now the execution stops for some time before
     the line 'virNetServerClientSetAuth(client, 0)'
  2. The client closes the connection irregularly. This causes the
     event loop to wake up and virNetServerProcessClient to be
     called (on the main thread T0). During the
     virNetServerProcessClients the srv lock is hold. The condition
     virNetServerClientNeedAuth(client) will be checked and as the
     authentication is not finished right now
     virNetServerTrackCompletedAuthLocked(srv) will be called =>
     --srv->nclients_unauth => 0
  3. The Thread T1 continues, marks the client as authenticated, and
     calls virNetServerTrackCompletedAuthLocked(srv) =>
     --srv->nclients_unauth => --0 => wrap around as nclient_unauth is
     unsigned
  4. virNetServerCheckLimits(srv) will disable the services forever

To fix it, add an auth_pending field to the client struct so that it
is now possible to determine if the authentication process has already
been handled for this client.

Setting the authentication method to none for the client in
virNetServerProcessClients is not a proper way to indicate that the
counter has been decremented, as this would imply that the client is
authenticated.

Additionally, adjust the existing test cases for this new field.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
..
gendispatch.pl perl: Don't hardcode interpreter path 2017-09-19 16:04:53 +02:00
genprotocol.pl perl: Don't hardcode interpreter path 2017-09-19 16:04:53 +02:00
gensystemtap.pl perl: Don't hardcode interpreter path 2017-09-19 16:04:53 +02:00
virkeepalive.c rpc: fix keep alive timer segfault 2017-04-24 12:19:13 +02:00
virkeepalive.h maint: fix up copyright notice inconsistencies 2012-09-20 16:30:55 -06:00
virkeepaliveprotocol.x
virnetclient.c Remove backslash alignment attempts 2017-11-03 13:24:12 +01:00
virnetclient.h remote: expose a new libssh transport 2016-11-15 15:50:51 +01:00
virnetclientprogram.c Print hex values with '0x' prefix and octal with '0' in debug messages 2017-09-25 13:34:53 +01:00
virnetclientprogram.h maint: fix up copyright notice inconsistencies 2012-09-20 16:30:55 -06:00
virnetclientstream.c Print hex values with '0x' prefix and octal with '0' in debug messages 2017-09-25 13:34:53 +01:00
virnetclientstream.h Introduce virNetClientStreamRecvHole 2017-05-18 07:42:13 +02:00
virnetdaemon.c rpc,lockd: Add missing netserver refcount increment on reload 2017-11-06 16:19:11 -05:00
virnetdaemon.h Change virNetDaemonGetServerNames to virNetDaemonGetServers 2016-03-11 12:58:41 +01:00
virnetlibsshsession.c rpc: libssh: allow a NULL known_hosts file 2017-01-11 13:37:24 +01:00
virnetlibsshsession.h libssh_transport: add new libssh-based transport 2016-11-15 15:50:51 +01:00
virnetmessage.c rpc: for messages with FDs always decode count of FDs from the message 2017-09-27 18:56:32 +02:00
virnetmessage.h rpc: use virNetMessageClearPayload in client 2016-05-05 14:28:19 -04:00
virnetprotocol.x rpc: Bump maximum message size to 32M 2017-05-24 14:02:29 +02:00
virnetsaslcontext.c Ignore SASL deprecation warnings on OS-X 2017-04-19 10:51:51 +01:00
virnetsaslcontext.h build: workaround broken SASL header (again) 2016-03-31 17:36:49 +02:00
virnetserver.c rpc: virnetserver: Fix race on srv->nclients_unauth 2018-01-04 06:55:31 -05:00
virnetserver.h rpc: Introduce virNetServerSetClientAuthenticated 2018-01-04 06:55:31 -05:00
virnetserverclient.c rpc: virnetserver: Fix race on srv->nclients_unauth 2018-01-04 06:55:31 -05:00
virnetserverclient.h rpc: virnetserver: Fix race on srv->nclients_unauth 2018-01-04 06:55:31 -05:00
virnetservermdns.c Use ATTRIBUTE_FALLTHROUGH 2017-06-12 19:11:30 -04:00
virnetservermdns.h Change file names in comments to match the files they are in 2014-03-10 14:26:04 +01:00
virnetserverprogram.c rpc: First test if authentication is required 2018-01-04 06:55:31 -05:00
virnetserverprogram.h daemon: Introduce virNetServerProgramSendStreamHole 2017-05-18 07:42:13 +02:00
virnetserverservice.c rpc: Fix potentially segfaults 2017-02-12 15:02:42 -05:00
virnetserverservice.h rpc: Add typedef for the anonymous enum used for authentication methods 2018-01-04 06:55:31 -05:00
virnetsocket.c rpc: avoid ssh interpreting malicious hostname as arguments 2017-08-29 18:02:03 +01:00
virnetsocket.h Revert "Prevent more compiler optimization of mockable functions" 2017-07-13 13:07:06 +01:00
virnetsshsession.c build: add GCC 6.0 -Wlogical-op workaround 2016-04-11 12:09:14 +02:00
virnetsshsession.h remote: Improve libssh2 password authentication 2013-07-12 09:22:38 +02:00
virnettlscontext.c Report what TLS priority string we use for a session 2017-03-16 11:03:33 +00:00
virnettlscontext.h rpc: allow priority string to be passed to TLS context 2016-06-08 13:48:45 +01:00