tls: Add a mutex lock on 'tlsCtxt'

Prevent the handshake function from reading 'tlsCtxt' while
updating 'tlsCtxt'.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
This commit is contained in:
Zhang Bo 2020-03-07 19:31:01 +08:00 committed by Daniel P. Berrangé
parent 15d280fa97
commit b461178639
1 changed files with 4 additions and 0 deletions

View File

@ -1114,7 +1114,9 @@ int virNetServerClientInit(virNetServerClientPtr client)
client->tls);
/* Begin the TLS handshake. */
virObjectLock(client->tlsCtxt);
ret = virNetTLSSessionHandshake(client->tls);
virObjectUnlock(client->tlsCtxt);
if (ret == 0) {
/* Unlikely, but ... Next step is to check the certificate. */
if (virNetServerClientCheckAccess(client) < 0)
@ -1435,7 +1437,9 @@ virNetServerClientDispatchHandshake(virNetServerClientPtr client)
{
int ret;
/* Continue the handshake. */
virObjectLock(client->tlsCtxt);
ret = virNetTLSSessionHandshake(client->tls);
virObjectUnlock(client->tlsCtxt);
if (ret == 0) {
/* Finished. Next step is to check the certificate. */
if (virNetServerClientCheckAccess(client) < 0)