From a10abe7fb30bdcee7e0c9f4e61322fa7195d093d Mon Sep 17 00:00:00 2001 From: "wtc%netscape.com" Date: Sat, 10 May 2003 14:21:40 +0000 Subject: [PATCH] Bug 202593 and bug 204980: fixed a recursive deadlock introduced by the fix for bug 202593. The session returned by nssSlot_CreateSession doesn't need its own lock. It is either protected by a higher-level lock (the slot or module lock) or used by only one thread throughout its lifetime. Modified Files: dev/devslot.c pk11wrap/dev3hack.c --- security/nss/lib/dev/devslot.c | 4 ++-- security/nss/lib/pk11wrap/dev3hack.c | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/security/nss/lib/dev/devslot.c b/security/nss/lib/dev/devslot.c index 7b452f8168c..7e68d73c570 100644 --- a/security/nss/lib/dev/devslot.c +++ b/security/nss/lib/dev/devslot.c @@ -32,7 +32,7 @@ */ #ifdef DEBUG -static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.13 $ $Date: 2003-04-19 00:03:13 $ $Name: $"; +static const char CVS_ID[] = "@(#) $RCSfile: devslot.c,v $ $Revision: 1.14 $ $Date: 2003-05-10 14:21:38 $ $Name: $"; #endif /* DEBUG */ #ifndef NSSCKEPV_H @@ -795,7 +795,7 @@ nssSlot_CreateSession return (nssSession *)NULL; } if (nssModule_IsThreadSafe(slot->module)) { - /* If the parent module is not threadsafe, + /* If the parent module is threadsafe, * create lock to protect just this session. */ rvSession->lock = PZ_NewLock(nssILockOther); diff --git a/security/nss/lib/pk11wrap/dev3hack.c b/security/nss/lib/pk11wrap/dev3hack.c index 7269c43b1d4..eddcc40d420 100644 --- a/security/nss/lib/pk11wrap/dev3hack.c +++ b/security/nss/lib/pk11wrap/dev3hack.c @@ -32,7 +32,7 @@ */ #ifdef DEBUG -static const char CVS_ID[] = "@(#) $RCSfile: dev3hack.c,v $ $Revision: 1.18 $ $Date: 2003-04-19 00:03:32 $ $Name: $"; +static const char CVS_ID[] = "@(#) $RCSfile: dev3hack.c,v $ $Revision: 1.19 $ $Date: 2003-05-10 14:21:40 $ $Name: $"; #endif /* DEBUG */ #ifndef NSS_3_4_CODE @@ -93,8 +93,22 @@ nssSlot_CreateSession } rvSession->isRW = PR_TRUE; rvSession->slot = slot; - /* actually, should get it's own lock if slot->lock is NULL */ - rvSession->lock = slot->lock; + /* + * The session doesn't need its own lock. Here's why. + * 1. If we are reusing the default RW session of the slot, + * the slot lock is already locked to protect the session. + * 2. If the module is not thread safe, the slot (or rather + * module) lock is already locked. + * 3. If the module is thread safe and we are using a new + * session, no higher-level lock has been locked and we + * would need a lock for the new session. However, the + * NSS_3_4_CODE usage of the session is that it is always + * used and destroyed within the same function and never + * shared with another thread. + * So the session is either already protected by another + * lock or only used by one thread. + */ + rvSession->lock = NULL; rvSession->ownLock = PR_FALSE; return rvSession; } else {