|
|
c6cc0b |
# HG changeset patch
|
|
|
c6cc0b |
# User Kamil Dudka <kdudka@redhat.com>
|
|
|
c6cc0b |
# Date 1484568851 -3600
|
|
|
c6cc0b |
# Mon Jan 16 13:14:11 2017 +0100
|
|
|
c6cc0b |
# Node ID 754a4a1f6220fa99e72197408726da14419fc187
|
|
|
c6cc0b |
# Parent b6a26d34c0e354344f81a73137deeb682c7961e0
|
|
|
c6cc0b |
Bug 1297397, avoid race condition in nssSlot_IsTokenPresent() that caused spurious SEC_ERROR_NO_TOKEN, r=rrelyea
|
|
|
c6cc0b |
|
|
|
c6cc0b |
diff --git a/lib/dev/devslot.c b/lib/dev/devslot.c
|
|
|
c6cc0b |
--- a/lib/dev/devslot.c
|
|
|
c6cc0b |
+++ b/lib/dev/devslot.c
|
|
|
c6cc0b |
@@ -91,7 +91,7 @@ nssSlot_ResetDelay(
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
|
|
|
c6cc0b |
static PRBool
|
|
|
c6cc0b |
-within_token_delay_period(NSSSlot *slot)
|
|
|
c6cc0b |
+within_token_delay_period(const NSSSlot *slot)
|
|
|
c6cc0b |
{
|
|
|
c6cc0b |
PRIntervalTime time, lastTime;
|
|
|
c6cc0b |
/* Set the delay time for checking the token presence */
|
|
|
c6cc0b |
@@ -103,7 +103,6 @@ within_token_delay_period(NSSSlot *slot)
|
|
|
c6cc0b |
if ((lastTime) && ((time - lastTime) < s_token_delay_time)) {
|
|
|
c6cc0b |
return PR_TRUE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
- slot->lastTokenPing = time;
|
|
|
c6cc0b |
return PR_FALSE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
|
|
|
c6cc0b |
@@ -136,6 +135,7 @@ nssSlot_IsTokenPresent(
|
|
|
c6cc0b |
nssSlot_ExitMonitor(slot);
|
|
|
c6cc0b |
if (ckrv != CKR_OK) {
|
|
|
c6cc0b |
slot->token->base.name[0] = 0; /* XXX */
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_FALSE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
slot->ckFlags = slotInfo.flags;
|
|
|
c6cc0b |
@@ -143,6 +143,7 @@ nssSlot_IsTokenPresent(
|
|
|
c6cc0b |
if ((slot->ckFlags & CKF_TOKEN_PRESENT) == 0) {
|
|
|
c6cc0b |
if (!slot->token) {
|
|
|
c6cc0b |
/* token was never present */
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_FALSE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
session = nssToken_GetDefaultSession(slot->token);
|
|
|
c6cc0b |
@@ -165,6 +166,7 @@ nssSlot_IsTokenPresent(
|
|
|
c6cc0b |
slot->token->base.name[0] = 0; /* XXX */
|
|
|
c6cc0b |
/* clear the token cache */
|
|
|
c6cc0b |
nssToken_Remove(slot->token);
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_FALSE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
/* token is present, use the session info to determine if the card
|
|
|
c6cc0b |
@@ -187,8 +189,10 @@ nssSlot_IsTokenPresent(
|
|
|
c6cc0b |
isPresent = session->handle != CK_INVALID_SESSION;
|
|
|
c6cc0b |
nssSession_ExitMonitor(session);
|
|
|
c6cc0b |
/* token not removed, finished */
|
|
|
c6cc0b |
- if (isPresent)
|
|
|
c6cc0b |
+ if (isPresent) {
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_TRUE;
|
|
|
c6cc0b |
+ }
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
/* the token has been removed, and reinserted, or the slot contains
|
|
|
c6cc0b |
* a token it doesn't recognize. invalidate all the old
|
|
|
c6cc0b |
@@ -201,8 +205,11 @@ nssSlot_IsTokenPresent(
|
|
|
c6cc0b |
if (nssrv != PR_SUCCESS) {
|
|
|
c6cc0b |
slot->token->base.name[0] = 0; /* XXX */
|
|
|
c6cc0b |
slot->ckFlags &= ~CKF_TOKEN_PRESENT;
|
|
|
c6cc0b |
+ /* TODO: insert a barrier here to avoid reordering of the assingments */
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_FALSE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
+ slot->lastTokenPing = PR_IntervalNow();
|
|
|
c6cc0b |
return PR_TRUE;
|
|
|
c6cc0b |
}
|
|
|
c6cc0b |
|