diff --git a/security/nss/lib/softoken/pkcs11.c b/security/nss/lib/softoken/pkcs11.c index 50aa8d884d..1e1b12cfec 100644 --- a/security/nss/lib/softoken/pkcs11.c +++ b/security/nss/lib/softoken/pkcs11.c @@ -2803,10 +2803,10 @@ sftk_CloseAllSessions(SFTKSlot *slot, PRBool logout) SKIP_AFTER_FORK(PZ_Unlock(lock)); SKIP_AFTER_FORK(PZ_Lock(slot->slotLock)); --slot->sessionCount; - SKIP_AFTER_FORK(PZ_Unlock(slot->slotLock)); if (session->info.flags & CKF_RW_SESSION) { - (void)PR_ATOMIC_DECREMENT(&slot->rwSessionCount); + --slot->rwSessionCount; } + SKIP_AFTER_FORK(PZ_Unlock(slot->slotLock)); } else { SKIP_AFTER_FORK(PZ_Unlock(lock)); } @@ -3523,9 +3523,9 @@ NSC_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) PORT_Memcpy(pInfo->model, "NSS 3 ", 16); PORT_Memcpy(pInfo->serialNumber, "0000000000000000", 16); PORT_Memcpy(pInfo->utcTime, "0000000000000000", 16); - pInfo->ulMaxSessionCount = 0; /* arbitrarily large */ - pInfo->ulMaxRwSessionCount = 0; /* arbitrarily large */ - PZ_Lock(slot->slotLock); /* Protect sessionCount / rwSessioncount */ + pInfo->ulMaxSessionCount = CK_EFFECTIVELY_INFINITE; + pInfo->ulMaxRwSessionCount = CK_EFFECTIVELY_INFINITE; + PR_Lock(slot->slotLock); /* Protect sessionCount / rwSessioncount */ pInfo->ulSessionCount = slot->sessionCount; pInfo->ulRwSessionCount = slot->rwSessionCount; PZ_Unlock(slot->slotLock); /* Unlock before sftk_getKeyDB */ @@ -4023,10 +4023,10 @@ NSC_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, } PZ_Lock(slot->slotLock); ++slot->sessionCount; - PZ_Unlock(slot->slotLock); if (session->info.flags & CKF_RW_SESSION) { - (void)PR_ATOMIC_INCREMENT(&slot->rwSessionCount); + ++slot->rwSessionCount; } + PZ_Unlock(slot->slotLock); do { PZLock *lock; @@ -4086,13 +4086,13 @@ NSC_CloseSession(CK_SESSION_HANDLE hSession) sftkdb_ClearPassword(handle); } } + if (session->info.flags & CKF_RW_SESSION) { + --slot->rwSessionCount; + } PZ_Unlock(slot->slotLock); if (handle) { sftk_freeDB(handle); } - if (session->info.flags & CKF_RW_SESSION) { - (void)PR_ATOMIC_DECREMENT(&slot->rwSessionCount); - } sftk_DestroySession(session); session = NULL; } diff --git a/security/nss/lib/softoken/pkcs11i.h b/security/nss/lib/softoken/pkcs11i.h index e533981741..4eaffe387c 100644 --- a/security/nss/lib/softoken/pkcs11i.h +++ b/security/nss/lib/softoken/pkcs11i.h @@ -309,9 +309,9 @@ struct SFTKSessionStr { * (head[]->refCount), objectLock protects all elements of the slot's * object hash tables (sessObjHashTable[] and tokObjHashTable), and * sessionObjectHandleCount. - * slotLock protects the remaining protected elements: - * password, needLogin, isLoggedIn, ssoLoggedIn, and sessionCount, - * and pwCheckLock serializes the key database password checks in + * slotLock protects password, needLogin, isLoggedIn, ssoLoggedIn, + * sessionCount, and rwSessionCount. + * pwCheckLock serializes the key database password checks in * NSC_SetPIN and NSC_Login. * * Each of the fields below has the following lifetime as commented @@ -351,8 +351,7 @@ struct SFTKSlotStr { int sessionIDConflict; /* not protected by a lock */ /* (preserved) */ int sessionCount; /* variable - reset */ - PRInt32 rwSessionCount; /* set by atomic operations */ - /* (reset) */ + int rwSessionCount; /* variable - reset */ int sessionObjectHandleCount; /* variable - perserved */ CK_ULONG index; /* invariant */ PLHashTable *tokObjHashTable; /* invariant */