Closed Bug 679524 Opened 14 years ago Closed 14 years ago

Crash in NSS when using NSS_InitContext

Categories

(NSS :: Libraries, defect)

3.12.10
x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: elio.maldonado.batiz, Assigned: rrelyea)

References

Details

Attachments

(3 files)

Attached file stack trace
As reported by Rich Meggison This is with the latest NSS on RHEL 6.1 Name : nss Relocations: (not relocatable) Version : 3.12.9 Vendor: Red Hat, Inc. Release : 9.el6 Build Date: Thu 21 Apr 2011 03:10:06 PM MDT The stack trace is attached. The code has two threads calling NSS_InitContext at the same time. The crash occurs in SECOID_Init. I don't believe this barrier is sufficient: if (oidhash) { return SECSuccess; /* already initialized */ } The crash occurs here: for ( i = 0; i < SEC_OID_TOTAL; i++ ) { oid = &oids[i]; PORT_Assert ( oid->offset == i ); -> entry = PL_HashTableAdd( oidhash, &oid->oid, (void *)oid ); because there are two different threads accessing oidhash at the same time. It's not easy to reproduce because it is a timing thing, but I suppose I could try to write a small test program.
Traditionally NSS was initialized once for an application. This code still expects the application wide initialization to happen once. Now, however, various libraries can now initialize NSS on the fly. Often these libraries will initialize NSS use it, then shut it down (because the library doesn't have any forward carrying state). It's also possible that these libraries may be working on different threads, thus making it possible for NSS_Init and NSS_Shutdown to be called on different threads at the same time. this code protects the various NSS initialization routines from multiple calls. The locks NSS uses to protect this are now leaked because it's not safe to free them at shutdown (as they may still be in use). bob
Assignee: nobody → rrelyea
Status: NEW → ASSIGNED
Attachment #553640 - Flags: superreview?(emaldona)
Attachment #553640 - Flags: review?(wtc)
Comment on attachment 553640 [details] [diff] [review] Allow only one thread to init and shutdown at a time. r+ from me.
Attachment #553640 - Flags: superreview?(emaldona) → superreview+
cvs commit: Examining . Checking in nssinit.c; /cvsroot/mozilla/security/nss/lib/nss/nssinit.c,v <-- nssinit.c new revision: 1.109; previous revision: 1.108 done wtc, you can still review this if you want. If you have any comments that need addressing just reopen the bug, otherwise you can just clear the review flag. bob
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
This fixes compilation error on Windows. I think it should also fix some test failures on other platforms. Patch checked in on the NSS trunk (NSS 3.13). Checking in nssinit.c; /cvsroot/mozilla/security/nss/lib/nss/nssinit.c,v <-- nssinit.c new revision: 1.110; previous revision: 1.109 done
Attachment #556977 - Flags: review?(rrelyea)
Bob: I didn't get your comment 3 because I was not on the cc list. Sorry about the late review. I will review your patch later.
Target Milestone: --- → 3.13
Comment on attachment 553640 [details] [diff] [review] Allow only one thread to init and shutdown at a time. This patch causes all the NSS "memleak" tinderboxes to fail because it introduces two memory leaks: NEW STACK: vfychain/main/NSS_Init/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewCondVar/PR_Malloc/malloc NEW STACK: vfychain/main/NSS_Init/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewLock/PR_Calloc/calloc Other examples: NEW STACK: selfserv/main/NSS_Initialize/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewCondVar/PR_Malloc/malloc NEW STACK: selfserv/main/NSS_Initialize/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewLock/PR_Calloc/calloc NEW STACK: strsclnt/main/NSS_Initialize/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewCondVar/PR_Malloc/malloc NEW STACK: strsclnt/main/NSS_Initialize/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewLock/PR_Calloc/calloc NEW STACK: ocspclnt/main/NSS_Init/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewCondVar/PR_Malloc/malloc NEW STACK: ocspclnt/main/NSS_Init/nss_Init/PR_CallOnce/nss_doLockInit/PR_NewLock/PR_Calloc/calloc We need to fix the memory leaks, or arrange for the "memleak" tinderboxes to ignore these two memory leak call stacks.
They should be on the ignore list. The introduction of a new one-time leak with this patch is already known. The stack should be */nss_init/PR_CallOnce/nss_doLockInit/* wtc, do you remember where the exclude stack files are? bob
Bob: I don't remember. I always asked Slavo to exclude memory leak call stacks for me. If the exclude stack files are in the NSS CVS tree, they should be under mozilla/security/nss/tests. I hope they are not just on the "memleak" tinderboxes' file systems.
Bob: I found the file of ignored leak stacks: http://mxr.mozilla.org/security/find?text=&string=leak Could you add the stack to mozilla/security/nss/tests/memleak/ignored? Thanks.
dhcp-227.sjc.redhat.com(57) cvs commit cvs commit: Examining . Checking in ignored; /cvsroot/mozilla/security/nss/tests/memleak/ignored,v <-- ignored new revision: 1.81; previous revision: 1.80 done
Bob: the leak stack that you checked in has nss_init. I think "init" needs to be capitalized: nss_Init.
The CVS commit message referenced the wrong bug number 679424. (The bug number is the tests/memleak/ignored file is correct.)
Fixed typo nss_init => nss_Init. Checking in ignored; /cvsroot/mozilla/security/nss/tests/memleak/ignored,v <-- ignored new revision: 1.82; previous revision: 1.81 done
Comment on attachment 556977 [details] [diff] [review] Add a missing return statement to NSS_Shutdown r+ rrelyea
Attachment #556977 - Flags: review?(rrelyea) → review+
Comment on attachment 553640 [details] [diff] [review] Allow only one thread to init and shutdown at a time. clearing review request
Attachment #553640 - Flags: review?(wtc)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: