Skip to content

Commit 81fa8d5

Browse files
w15eacredroidmonkey
authored andcommitted
Refactor YubiKey key to avoid deadlock
- Add mutex to get m_connectedKeys - Fix deadlock when the app uses Quick Unlock and the YubiKey is unplugged
1 parent 5ee5e49 commit 81fa8d5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/keys/drivers/YubiKey.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ bool YubiKey::findValidKeys()
7575
{
7676
QMutexLocker lock(&s_interfaceMutex);
7777

78+
findValidKeys(lock);
79+
80+
return !m_usbKeys.isEmpty() || !m_pcscKeys.isEmpty();
81+
}
82+
83+
void YubiKey::findValidKeys(const QMutexLocker& locker)
84+
{
85+
// Check QMutexLocker since version 6.4
86+
Q_UNUSED(locker);
87+
7888
m_connectedKeys = 0;
7989
m_usbKeys = YubiKeyInterfaceUSB::instance()->findValidKeys(m_connectedKeys);
8090
m_pcscKeys = YubiKeyInterfacePCSC::instance()->findValidKeys(m_connectedKeys);
81-
82-
return !m_usbKeys.isEmpty() || !m_pcscKeys.isEmpty();
8391
}
8492

8593
void YubiKey::findValidKeysAsync()
@@ -98,6 +106,8 @@ YubiKey::KeyMap YubiKey::foundKeys()
98106

99107
int YubiKey::connectedKeys()
100108
{
109+
QMutexLocker lock(&s_interfaceMutex);
110+
101111
return m_connectedKeys;
102112
}
103113

@@ -171,7 +181,7 @@ YubiKey::challenge(YubiKeySlot slot, const QByteArray& challenge, Botan::secure_
171181

172182
// Make sure we tried to find available keys
173183
if (m_usbKeys.isEmpty() && m_pcscKeys.isEmpty()) {
174-
findValidKeys();
184+
findValidKeys(lock);
175185
}
176186

177187
if (m_usbKeys.contains(slot)) {

src/keys/drivers/YubiKey.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class YubiKey : public QObject
8484
private:
8585
explicit YubiKey();
8686

87+
void findValidKeys(const QMutexLocker& locker);
88+
8789
static YubiKey* m_instance;
8890

8991
QTimer m_interactionTimer;

0 commit comments

Comments
 (0)