<font size=2 face="sans-serif">Hi Rob</font>
<br>
<br><font size=2 face="sans-serif">I'm a little confused as to why you're
asking me about Opencryptoki. Are there known issues with it?</font>
<br><font size=2 face="sans-serif">No, we are talking to a hardware PKCS#11
implementation based on the IBM 4765 (which Opencryptoki</font>
<br><font size=2 face="sans-serif">can also do, but based on the standard
(CCA) firmware and not the specific PKCS#11 code that I use).</font>
<br>
<br><font size=2 face="sans-serif">With your description below, I was able
to find the problem in this snippet of mod_nss code:</font>
<br>
<br><font size=2 face="sans-serif">   if (chdir(mc->pCertificateDatabase)
!= 0) {</font>
<br><font size=2 face="sans-serif">        ap_log_error(APLOG_MARK,
APLOG_ERR, 0, base_server,</font>
<br><font size=2 face="sans-serif">           
"Unable to change directory to %s", mc->pCertificateDatabase);</font>
<br><font size=2 face="sans-serif">        if (mc->nInitCount
== 1)</font>
<br><font size=2 face="sans-serif">           
nss_die();</font>
<br><font size=2 face="sans-serif">        else</font>
<br><font size=2 face="sans-serif">           
return;</font>
<br><font size=2 face="sans-serif">    }</font>
<br><font size=2 face="sans-serif">   rv = NSS_Initialize(mc->pCertificateDatabase,
mc->pDBPrefix, mc->pDBPrefix, "secmod.db", NSS_INIT_READONLY);</font>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="sans-serif">On my test machine, the apache user
had no access to the NSS database directory (it was in /root/y4nss), </font>
<br><font size=2 face="sans-serif">and I had missed this in the logs. According
to the above, if that chdir fails, then nss_init_SSLLibrary returns</font>
<br><font size=2 face="sans-serif">with no indication of error, and without
calling NSS_Initialize. The very next line of nss_init_Child then</font>
<br><font size=2 face="sans-serif">goes on to make an NSS call, and fails
with a segfault. So this could be argued to be an NSS bug, but also,</font>
<br><font size=2 face="sans-serif">mod_nss should arguably handle the situation
more gracefully on its end.</font>
<br>
<br><font size=2 face="sans-serif">Now I at least know what caused it.
Thanks, Rob!</font>
<br>
<br><font size=2 face="sans-serif">Best regards</font>
<br>
<br><font size=2 face="sans-serif">Lars</font>
<br>
<br><tt><font size=2>Rob Crittenden <rcritten@redhat.com> wrote on
11/01/2013 01:59:36 PM:<br>
<br>
> Rob Crittenden <rcritten@redhat.com> </font></tt>
<br><tt><font size=2>> 11/01/2013 01:59 PM</font></tt>
<br><tt><font size=2>> <br>
> To</font></tt>
<br><tt><font size=2>> <br>
> Lars Skovlund/Denmark/IBM@IBMDK, mod_nss-list@redhat.com, </font></tt>
<br><tt><font size=2>> <br>
> cc</font></tt>
<br><tt><font size=2>> <br>
> Subject</font></tt>
<br><tt><font size=2>> <br>
> Re: [Mod_nss-list] Crashing apache processes</font></tt>
<br><tt><font size=2>> <br>
> Lars Skovlund wrote:<br>
> > Hello list,<br>
> ><br>
> > As part of a customer case I'm working on, I've been trying to
set up<br>
> > the combination of Apache, mod_nss and our own PKCS#11 provider.<br>
> > I've gotten the Apache server to start, but the tasks spawned
by Apache<br>
> > are dying left and right:<br>
> ><br>
> > [Thu Oct 31 15:48:15 2013] [notice] child pid 6649 exit signal<br>
> > Segmentation fault (11)<br>
> > [Thu Oct 31 15:48:15 2013] [notice] child pid 6650 exit signal<br>
> > Segmentation fault (11)<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6645 exit signal<br>
> > Segmentation fault (11), possible coredump in /tmp<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6646 exit signal<br>
> > Segmentation fault (11), possible coredump in /tmp<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6647 exit signal<br>
> > Segmentation fault (11), possible coredump in /tmp<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6648 exit signal<br>
> > Segmentation fault (11), possible coredump in /tmp<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6651 exit signal<br>
> > Segmentation fault (11)<br>
> > [Thu Oct 31 15:48:16 2013] [notice] child pid 6653 exit signal<br>
> > Segmentation fault (11)<br>
> > [Thu Oct 31 15:48:18 2013] [notice] child pid 6668 exit signal<br>
> > Segmentation fault (11), possible coredump in /tmp<br>
> ><br>
> > and so on. My investigation points toward NSS being shut down<br>
> > prematurely (by the main process?) while the incipient worker
processes<br>
> > continue to call it (heavily edited for brevity):<br>
> ><br>
> > [root@cccclab4 ~]# gdb --args httpd -X -D FOREGROUND<br>
> > GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6)<br>
> > [...]<br>
> > (gdb) break NSS_Initialize<br>
> > Breakpoint 1 (NSS_Initialize) pending.<br>
> > (gdb) run<br>
> > Starting program: /usr/sbin/httpd -X -D FOREGROUND<br>
> > Breakpoint 1, NSS_Initialize (configdir=0x7ffff82bf0a0 "/root/y4nss/",<br>
> >      certPrefix=0x0, keyPrefix=0x0, secmodName=0x7fffed87c9ae
"secmod.db",<br>
> >      flags=1) at nssinit.c:817<br>
> > (gdb) watch g_default_trust_domain<br>
> > Hardware watchpoint 2: g_default_trust_domain<br>
> > (gdb) cont<br>
> > Continuing.<br>
> > Hardware watchpoint 2: g_default_trust_domain<br>
> ><br>
> > Old value = (NSSTrustDomain *) 0x0<br>
> > New value = (NSSTrustDomain *) 0x7ffff8426be0<br>
> > STAN_LoadDefaultNSS3TrustDomain () at pki3hack.c:153<br>
> > 153    return PR_SUCCESS;<br>
> > (gdb) cont<br>
> > Continuing.<br>
> > Please enter password for "TEST" token:<br>
> > [Thread 0x7fffe3c37700 (LWP 10913) exited]<br>
> > (gdb) cont<br>
> > Hardware watchpoint 2: g_default_trust_domain<br>
> ><br>
> > Old value = (NSSTrustDomain *) 0x7ffff8426be0<br>
> > New value = (NSSTrustDomain *) 0x0<br>
> > 0x00007ffff34a1828 in STAN_Shutdown () at pki3hack.c:212<br>
> > 212            g_default_trust_domain
= NULL;<br>
> > (gdb) cont<br>
> > Continuing.<br>
> > [New Thread 0x7fffe3c37700 (LWP 10916)]<br>
> ><br>
> > Program received signal SIGSEGV, Segmentation fault.<br>
> > nssTrustDomain_GetCertsFromCache (td=0x0, certListOpt=0x7ffff836a7e0)<br>
> >      at tdcache.c:1127<br>
> > 1127    PZ_Lock(td->cache->lock);<br>
> > (gdb) print td<br>
> > $1 = (NSSTrustDomain *) 0x0<br>
> > (gdb) bt<br>
> > #0  nssTrustDomain_GetCertsFromCache (td=0x0, certListOpt=0x7ffff836a7e0)<br>
> >      at tdcache.c:1127<br>
> > #1  0x00007ffff349b727 in NSSTrustDomain_TraverseCertificates
(td=0x0,<br>
> >      callback=0x7ffff34623e0 <pk11ListCertCallback>,
arg=0x7fffffffdf20)<br>
> >      at trustdomain.c:1015<br>
> > #2  0x00007ffff34622fc in PK11_ListCerts (type=PK11CertListUser,
pwarg=0x0)<br>
> >      at pk11cert.c:2509<br>
> > #3  0x00007fffed872772 in nss_init_Child (p=0x7ffff83d4c08,<br>
> >      base_server=0x7ffff8212880) at nss_engine_init.c:1370<br>
> > #4  0x00007ffff7fd6b0c in ap_run_child_init (pchild=0x7ffff83d4c08,<br>
> >      s=0x7ffff8212880) at /usr/src/debug/httpd-2.2.15/server/config.c:155<br>
> > #5  0x00007ffff7fea725 in child_main (child_num_arg=<value
optimized out>)<br>
> >      at /usr/src/debug/httpd-2.2.15/server/mpm/prefork/prefork.c:518<br>
> > #6  0x00007ffff7feac46 in make_child (s=0x7ffff8212880,
slot=0)<br>
> >      at /usr/src/debug/httpd-2.2.15/server/mpm/prefork/prefork.c:707<br>
> > #7  0x00007ffff7feb293 in ap_mpm_run (_pconf=<value optimized
out>,<br>
> >      plog=<value optimized out>, s=<value
optimized out>)<br>
> >      at /usr/src/debug/httpd-2.2.15/server/mpm/prefork/prefork.c:983<br>
> > #8  0x00007ffff7fc2900 in main (argc=4, argv=0x7fffffffe408)<br>
> >      at /usr/src/debug/httpd-2.2.15/server/main.c:760<br>
> ><br>
> > The NULL pointer that is dereferenced in the final steps comes
from the<br>
> > global variable I watched. Is this a known bug, or are there<br>
> > configuration problems that are known to cause this?<br>
> > The versions of Apache and nss I am using are these (they are
the<br>
> > versions I got from our local RHN node):<br>
> ><br>
> > [root@cccclab4 ~]# rpm -qa nss httpd<br>
> > httpd-2.2.15-29.el6_4.x86_64<br>
> > nss-3.14.0.0-12.el6.x86_64<br>
> > [root@cccclab4 ~]#<br>
> ><br>
> > Any help you can give is greatly appreciated.<br>
> <br>
> Ok, so Apache makes things difficult for us. It loads and reloads
the <br>
> modules a couple of times during startup.<br>
> <br>
> During the initial start stdout/stdin are still open and things are
<br>
> launched as root. This, from an Apache perspective, is just a sanity
<br>
> startup to get the list of configuration options available in the
<br>
> module. We take this opportunity to prompt for any token passwords
that <br>
> are needed.<br>
> <br>
> Then Apache unloads the module. We have to shut down NSS when this
happens.<br>
> <br>
> Then it restarts things, perhaps in multiple forked children. In each
<br>
> one we initialize NSS and apply the configuration.<br>
> <br>
> Is this the opencryptoki module?<br>
> <br>
> rob<br>
> <br>
</font></tt><font size=2 face="sans-serif"><br>
<br>
Medmindre andet er angivet ovenfor: / Unless Otherwise Stated Above:<br>
IBM Danmark ApS<br>
Nymøllevej 91<br>
2800 Kongens Lyngby, Danmark<br>
CVR nr.: 65305216 </font>