meta_handle2session() has the following code -
124 /* Lock to ensure the magic-check + read-lock is atomic. */
125 (void) pthread_rwlock_rdlock(&meta_sessionclose_lock);
126
127 if (tmp_session->magic_marker != METASLOT_SESSION_MAGIC) {
128 (void) pthread_rwlock_unlock(&meta_sessionclose_lock);
129 *session = NULL;
130 return (CKR_SESSION_HANDLE_INVALID);
131 }
132 (void) pthread_rwlock_unlock(&meta_sessionclose_lock);
The meta_sessionclose_lock offers no protection because it is dropped on line 132. We can check the magic_marker without holding the lock and check it again under the protection of tmp_session->session_lock. The thread that is setting
session->magic_marker = METASLOT_SESSION_BADMAGIC;
in meta_session_deactivate() is holding the session_lock. So, this is safe to do.
Looking at the other libraries ...
handle2_session() routine in pkcs11_softtoken library can be improved. It is needlessly holding soft_sessionlist_mutex. handle2_session() routine in pkcs11_kernel can be improved. It is needlessly holding the slot lock.
Moved to evaluation.