Open Bug 764646 Opened 10 years ago Updated 3 months ago

Always initialize the SSL session cache locks lazily


(NSS :: Libraries, defect, P1)



(Not tracked)



(Reporter: wtc, Unassigned, NeedInfo)



(2 files)

Attached patch Proposed patchSplinter Review
In bug 403240, Julien added code to initialize the two SSL session cache
locks (cacheLock in sslnonce.c and symWrapKeysLock in ssl3con.c) lazily
using PR_CallOnce, and also a way for SSL servers to initialize the locks
early in SSL_ConfigServerSessionIDCache etc. to avoid the overhead of
PR_CallOnce.  The assumption is that an SSL server needs to call
SSL_ConfigServerSessionIDCache early in the program, before it starts to
do SSL.

This assumption no longer holds in a client application that is
predominantly an SSL client but may also act as an SSL server in a
peer-to-peer protocol.  See the Chromium bug 131622:

The cleanest solution is to always initialize the locks lazily.  But we
need to keep the overhead of PR_CallOnce low.  Right now we initialize
the locks lazily right before we use the locks.

After analyzing the code that uses the two locks, I found that the locks
are always used with an sslSocket 'ss', except in SSL3_ShutdownServerCache
and SSL_ClearSessionCache.  This matches our expectation that only SSL
sockets use the SSL session cache.  Therefore we only need to initialize
the locks lazily before we create sslSocket objects.  This is the approach
taken in the attached patch.

You can also review the patch at
Attachment #632952 - Flags: review?(rrelyea)
Comment on attachment 632952 [details] [diff] [review]
Proposed patch


One question, is there a strong reason not to do this init in the new ssl_init function which we've already created?

Question 2: I didn't check, but the code is presuming the FreeSessionCacheLocks(); is safe to call if InitSessionCacheLocks() is never called.

Attachment #632952 - Flags: review?(rrelyea) → review+
Target Milestone: 3.14 → 3.14.1
Target Milestone: 3.14.1 → 3.14.2
Target Milestone: 3.14.2 → 3.14.3
Priority: P2 → P1
Target Milestone: 3.14.3 → 3.15.3
I'm splitting my patch into two steps. The first step, done by Adam in this
patch, is easy to verify correct. It simply changes ssl_InitSessionCacheLocks()
to always call PR_CallOnce to protect the lock creation.

Patch checked in:

I will create the patch for the second step, which moves the
ssl_InitSessionCacheLocks() call into ssl_Init() to reduce the overhead of
calling PR_CallOnce. The second step is harder to verify correct because we
need to identify the libSSL functions that are considered "entry points" to
the session cache and make sure they all call ssl_Init().
Attachment #810131 - Flags: review+
Attachment #810131 - Flags: checked-in+
changing target milestone to 3.15.4
Target Milestone: 3.15.3 → 3.15.4
Comment on attachment 810131 [details] [diff] [review]
Step 1: simply use PR_CallOnce to protect the lock creation, by Adam Langley

I backed out this patch in
because selfserv calls SSL_ConfigServerSessionIDCache, which ultimately calls
NSS_RegisterShutdown, before calling NSS_Initialize.
Attachment #810131 - Flags: checked-in+ → checked-in-
Target Milestone: 3.15.4 → 3.15.5
Target Milestone: 3.15.5 → 3.16
Target Milestone: 3.16 → 3.16.1

The bug assignee didn't login in Bugzilla in the last months and this bug has priority 'P1'.
:beurdouche, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: wtc → nobody
Flags: needinfo?(bbeurdouche)
You need to log in before you can comment on or make changes to this bug.