Open Bug 764646 Opened 10 years ago Updated 8 years ago

Always initialize the SSL session cache locks lazily

Categories

(NSS :: Libraries, defect, P1)

3.11.10
defect

Tracking

(Not tracked)

ASSIGNED
3.16.1

People

(Reporter: wtc, Assigned: wtc)

Details

Attachments

(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:
http://code.google.com/p/chromium/issues/detail?id=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 https://chromiumcodereview.appspot.com/10539144/
Attachment #632952 - Flags: review?(rrelyea)
Comment on attachment 632952 [details] [diff] [review]
Proposed patch

r+

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.

bob
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: https://hg.mozilla.org/projects/nss/rev/4bb4712d7432

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 https://hg.mozilla.org/projects/nss/rev/07dd289c5111
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
You need to log in before you can comment on or make changes to this bug.