Bug 553638

Summary: SIGSEGV on call of NSS_Initialize()
Product: [Fedora] Fedora Reporter: Lorenzo Villani <lorenzo>
Component: nssAssignee: Elio Maldonado Batiz <emaldona>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 12CC: bnocera, dwmw2, emaldona, kdudka, kengert, mefoster, rrelyea, thoger
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard: abrt_hash:09f369ef4f227cf8efadcb876171a28945dd9ccb
Fixed In Version: 3.12.5-8.fc12 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-02-05 01:40:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
File: backtrace
none
pkcs11
none
diff
none
humble fix
none
Patch for SIGSESV
kdudka: review-
Patch V2
none
nsssysinit.c after all patches have been applied
none
Patch V3
rrelyea: review+
Effective cummulative patch
none
Test results before and after
none
fix broken indentation
none
Patch V4 fixes regression and cleans up code none

Description Lorenzo Villani 2010-01-08 14:02:44 UTC
abrt 1.0.3 detected a crash.

How to reproduce
-----
1. Upload the new bip-0.8.4 tarball to the new lookaside cache (via make new-sources)
2. Wait a couple of seconds 
3. ERROR: could not check remote file status
    (curl crashed)


Attached file: backtrace
cmdline: curl -k --cert '                           ' --fail --silent -F name=bip -F md5sum=76fe2800efdfbe54bf72540e40a91150 -F filename=bip-0.8.4.tar.gz https://cvs.fedoraproject.org/repo/pkgs/upload.cgi
component: curl
executable: /usr/bin/curl
kernel: 2.6.31.9-174.fc12.x86_64
package: curl-7.19.7-6.fc12
rating: 4
reason: Process was terminated by signal 11 (Segmentation fault)

Comment 1 Lorenzo Villani 2010-01-08 14:02:47 UTC
Created attachment 382470 [details]
File: backtrace

Comment 2 Kamil Dudka 2010-01-08 14:14:37 UTC
Thanks for the report!

Please report also the version of nss and attach the following file:

/etc/pki/nssdb/pkcs11.txt

Thanks in advance!

Comment 3 Lorenzo Villani 2010-01-08 14:18:11 UTC
[lvillani@normandy bip (master)]$ rpm -q nss
nss-3.12.5-2.fc12.x86_64

Comment 4 Lorenzo Villani 2010-01-08 14:19:20 UTC
Created attachment 382476 [details]
pkcs11

Comment 5 Lorenzo Villani 2010-01-08 14:22:27 UTC
Created attachment 382477 [details]
diff

I have just discovered an .rpmsave (I never touched that file myself, though) file in that directory. Attached the diff between the two files.

Comment 6 Lorenzo Villani 2010-01-08 14:24:27 UTC
Looks like that reverting to pkcs11.txt.rpmsave version fixes the issue.

Comment 7 Kamil Dudka 2010-01-08 14:27:16 UTC
(In reply to comment #6)
> Looks like that reverting to pkcs11.txt.rpmsave version fixes the issue.  

Great!

Otherwise the issue is 100% reproducible, right?

Could you please try the following with the failing configuration?

mv -v /home/lvillani/.pki /home/lvillani/.pki.hidden

Comment 8 Lorenzo Villani 2010-01-08 14:31:52 UTC
(In reply to comment #7)
> 
> Otherwise the issue is 100% reproducible, right?
> 

Yes.

> Could you please try the following with the failing configuration?
> 
> mv -v /home/lvillani/.pki /home/lvillani/.pki.hidden  

[lvillani@normandy ~]$ mv -v /home/lvillani/.pki /home/lvillani/.pki.hidden
`/home/lvillani/.pki' -> `/home/lvillani/.pki.hidden'


[lvillani@normandy devel (master)]$ make new-sources FILES=bip-0.8.4.tar.gz 

Checking : bip-0.8.4.tar.gz on https://cvs.fedoraproject.org/repo/pkgs/upload.cgi...
ERROR: could not check remote file status
make: *** [new-sources] Error 255

Same issue (abrt increases the "crash count", I bet it triggers the same crash).

Comment 9 Kamil Dudka 2010-01-08 14:38:44 UTC
Thanks for your help! Now I see the nonsense just from that backtrace:

    if (sysdb && !strcmp(filename, sysdb))
            filename = NULL;
    if (userdb && !strcmp(filename, userdb))
            filename = NULL;

Comment 10 Kamil Dudka 2010-01-08 14:58:38 UTC
Created attachment 382482 [details]
humble fix

I guess the attached patch fixes at least the reported SIGSEGV.

However someone who know what the nsssysinit.c code is supposed to do should write some comments inside. Just to make it easier for other people fixing bugs like this. Thanks in advance!

Comment 11 Elio Maldonado Batiz 2010-01-08 17:58:21 UTC
(In reply to comment #10) See David's; latest comment's on Bug 547860 he has a slightly different way solving the SIGSEV though nsssysinit isn't working yet.

Comment 12 Kamil Dudka 2010-01-08 18:09:33 UTC
Well, I am new to the code.  Is it documented anywhere?  In particular is get_list() supposed to get non-NULL filename in all cases?  I in fact didn't realize the code causing SIGSEGV is the part of a bugfix :-)

I propose to make the patch for #547860 much more verbose.  Please include some comments into the patch to explain what the new code is supposed to do and how.  Thanks!

Comment 13 Kamil Dudka 2010-01-08 18:29:42 UTC
Well, there are some comments in the patch.  But what definitely needs to be more visible at first glance is the game you play with NULL vs. non-NULL filename ... which has actually caused this bug.  I propose to add at least assertion before the first strcmp().

Btw. if you really want to get the patch upstream at some point, it is not good idea to use strcmp from glibc at all ;-)

Comment 14 Elio Maldonado Batiz 2010-01-08 22:03:47 UTC
We have come to the point where we are patching each others patches. I'll apply David's changes to the other patches so I can check them in. We need an urgent fix the SIGSEV at the very least. I'll use PL_CompareStrings while I'm at it and see if I can add comments on what is essentially workaround or "a temporary hack" in David's own words :-)

Comment 16 Kamil Dudka 2010-01-08 22:56:21 UTC
Comment on attachment 382482 [details]
humble fix

Obsoleting the patch - it should be extended to get rid of the strcmp() calls as mentioned in comment #13.

Comment 18 Elio Maldonado Batiz 2010-01-09 00:04:12 UTC
Created attachment 382577 [details]
Patch for SIGSESV

Patch is based on what's described in Comment #17 From David Woodhouse in Bug 547860. Uses PL_CompareStrings and added some added comments which I hope accurately describe the intent of setting filename to NULL as per earlier patch.

Comment 19 Kamil Dudka 2010-01-09 00:22:27 UTC
Comment on attachment 382577 [details]
Patch for SIGSESV

>@@ -250,9 +251,13 @@ get_list(char *filename, char *stripped_
>     sysdb = getSystemDB();
>     userdb = getUserDB();
> 
>-    if (sysdb && !strcmp(filename, sysdb))
>+	/* Using a NULL filename as a Boolean flag to
>+	 * prevent registering both an application-defined
>+	 * db and the system db. Bug 546211.
>+	 */
>+    if (sysdb && PL_CompareStrings(filename, sysdb))

I suggest to insert PORT_Assert(filename) before the line above and add comment above the function saying the parameter filename must never be NULL.  If you skip this step, you'll most likely run to another SIGSEGV sooner or later, when the get_list() is used elsewhere.  Now you need to go through 3 non-trivial functions to figure out it really can't be NULL.

Additionally I spotted the comment for the get_list() function is not immediately above the function and considered it bug as well.

And maybe one minor nit - "Bug 546211" should be "rhbz #546211".  If you got the patch upstream it would clash with their bz numbers.

Comment 20 Elio Maldonado Batiz 2010-01-09 01:42:40 UTC
Created attachment 382588 [details]
Patch V2

Addresses Kamil's comments. For preliminary review as I still need have testing to do.

Comment 21 Elio Maldonado Batiz 2010-01-09 02:00:51 UTC
Created attachment 382590 [details]
nsssysinit.c after all patches have been applied

The after after all patches. To facilitate Bob's review somewhat as so many patches have been applied.

Comment 22 Kamil Dudka 2010-01-09 09:03:00 UTC
Comment on attachment 382588 [details]
Patch V2

>@@ -212,6 +213,13 @@ getFIPSMode(void)
> 
> #define NSS_DEFAULT_FLAGS "flags=readonly"
> 
>+static const char *nssDefaultFlags = "trustOrder=75 cipherOrder=100 \
>+slotParams={0x00000001=[slotFlags=RSA,RC4,RC2,DES,DH,SHA1,MD5,MD2,SSL,TLS,AES,RANDOM \
>+askpw=any timeout=30 ] }  ";
>+static const char *nssDefaultFIPSFlags = "trustOrder=75 cipherOrder=100 \
>+slotParams={0x00000003=[slotFlags=RSA,RC4,RC2,DES,DH,SHA1,MD5,MD2,SSL,TLS,AES,RANDOM \
>+askpw=any timeout=30 ] }  ";
>+

I know I am annoying today ... but the above looks pretty subtle for maintenance to me:

1) There is absolutely no info why the hard-wired parameters are there and info about their interaction with the same parameters from pcks11.txt.
2) There is not explained why e.g. 0x00000001 and 0x00000003.
3) There is copy-pasted code, which is generally always wrong.

I guess 1+2 might be solved by adding an URL to the documentation of the parameters and documentation of the nsssysinit. As for the copy-pasted code, what about a macro like this?

#define NSS_FLAGS "trustOrder=75 cipherOrder=100"
#define NSS_SLOT_FLAGS "[slotFlags=RSA,RC4,RC2,DES,DH,SHA1,MD5,MD2,SSL,TLS,AES,RANDOM" \
    " askpw=any timeout=30 ]"

static const char *nssDefaultFlags = NSS_FLAGS " slotParams={0x00000001=" NSS_SLOT_FLAGS " }  ";
static const char *nssDefaultFIPSFlags = NSS_FLAGS " slotParams={0x00000003=" NSS_SLOT_FLAGS " }  ";

>@@ -250,9 +251,14 @@ get_list(char *filename, char *stripped_
>     sysdb = getSystemDB();
>     userdb = getUserDB();
> 
>-    if (sysdb && !strcmp(filename, sysdb))
>+	/* Using a NULL filename as a Boolean flag to
>+	 * prevent registering both an application-defined
>+	 * db and the system db. rhbz #546211.
>+	 */
>+	PORT_Assert(filename);

broken indentation here ^^^

Nothing of the comments above should prevent the patch from being applied, but I'd be happy if they were addressed later.  It will help you to decrease the frequency of filling bug reports against nsssysinit.

Comment 23 Elio Maldonado Batiz 2010-01-10 01:25:46 UTC
Created attachment 382735 [details]
Patch V3

In response to Kamil's review comments this one
1) Points to the Wiki for info on configuration parameters
2) Explains magic constants 0x00000001 and 0x00000003.
3) Avoids copy and pasting duplicated common portions of the literals

Comment 24 Elio Maldonado Batiz 2010-01-10 01:31:44 UTC
Created attachment 382736 [details]
Effective cummulative patch

Provides a wider context for ease of review.

Comment 25 Elio Maldonado Batiz 2010-01-10 01:45:09 UTC
Created attachment 382739 [details]
Test results before and after

Thank you Kamil for suggesting this simple test.

Comment 26 Elio Maldonado Batiz 2010-01-10 01:54:46 UTC
Scratch build at http://koji.fedoraproject.org/koji/taskinfo?taskID=1911830

Comment 27 Kamil Dudka 2010-01-10 10:18:06 UTC
Created attachment 382772 [details]
fix broken indentation

Thanks for considering the review comments, it looks much better now. I am attaching an incremental patch making the indentation more consistent (no change in behavior).

It looks to me like you have wrongly set your editor for nsssysinit.c - the code uses tabs 8 characters width and shift width of 4 characters, or am I wrong?

Comment 28 Kamil Dudka 2010-01-10 16:36:39 UTC
*** Bug 554135 has been marked as a duplicate of this bug. ***

Comment 29 Elio Maldonado Batiz 2010-01-10 17:28:41 UTC
(In reply to comment #27)  In the slot comments I should have mentioned http://www.mozilla.org/projects/security/pki/nss/ref/ssl/gtstd.html#1011970
The writing and Fig 2.1 should clarify things quite a bit.

Thanks for the indentation fixes. Yes, that's caused by me switching among eclipse, gedit and vim at different times.

By the way, another test that passes was that as root I added a cert to the system database and not show up in the wrong place, something I will mention in bug 547860.

Comment 30 Kamil Dudka 2010-01-11 10:17:39 UTC
*** Bug 554291 has been marked as a duplicate of this bug. ***

Comment 31 Mary Ellen Foster 2010-01-11 10:26:20 UTC
I can confirm that the scratch build of NSS from comment #26 fixes the issue I was seeing in bug 554291

Comment 32 Bastien Nocera 2010-01-11 11:12:41 UTC
(In reply to comment #31)
> I can confirm that the scratch build of NSS from comment #26 fixes the issue I
> was seeing in bug 554291    

Same here.

Comment 33 Bob Relyea 2010-01-11 17:51:14 UTC
> It looks to me like you have wrongly set your editor for nsssysinit.c - the
> code uses tabs 8 characters width and shift width of 4 characters, or am I
> wrong?  

That's the historical upstream coding standard for all of NSS.

bob

Comment 34 Kamil Dudka 2010-01-11 18:01:37 UTC
> That's the historical upstream coding standard for all of NSS.

If "historical" means still valid, we should respect it to avoid later re-indentation and make it easier to follow downstream patches. At least my attachment 382772 [details] respects it.

Elio, as for the vim, you want to add following to your ~/.vimrc:

set noexpandtab
set shiftwidth=4
set tabstop=8
set tw=80

... not sure with eclipse and gedit since I don't use them myself.

Comment 35 Elio Maldonado Batiz 2010-01-11 18:03:25 UTC
Comment on attachment 382772 [details]
fix broken indentation

I would use this to clean up my patch a bit rather than a patch on its own.

Comment 36 Kamil Dudka 2010-01-11 18:09:41 UTC
(In reply to comment #35)
Sure thing ... that's how it has been intended actually :-)

Comment 37 Bob Relyea 2010-01-13 00:38:07 UTC
Comment on attachment 382735 [details]
Patch V3

r+ rrelyea

Comment 38 Fedora Update System 2010-01-15 19:00:44 UTC
nss-3.12.5-7.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/nss-3.12.5-7.fc12

Comment 39 Fedora Update System 2010-01-17 02:54:35 UTC
nss-3.12.5-7.fc12 has been pushed to the Fedora 12 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update nss'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F12/FEDORA-2010-0685

Comment 40 Lorenzo Villani 2010-01-20 12:23:55 UTC
Looks like it's fixed now.

Comment 41 Fedora Update System 2010-01-25 21:22:25 UTC
nss-3.12.5-8.fc12 has been submitted as an update for Fedora 12.
http://admin.fedoraproject.org/updates/nss-3.12.5-8.fc12

Comment 42 Elio Maldonado Batiz 2010-01-25 21:40:43 UTC
Created attachment 386711 [details]
Patch V4 fixes regression and cleans up code

Attaching this revised patch here were it belongs. It was reviewed in Bug 545779 and checked in.

Comment 43 Fedora Update System 2010-01-27 01:12:06 UTC
nss-3.12.5-8.fc12 has been pushed to the Fedora 12 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update nss'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F12/FEDORA-2010-1127

Comment 44 Fedora Update System 2010-02-05 01:40:32 UTC
nss-3.12.5-8.fc12 has been pushed to the Fedora 12 stable repository.  If problems still persist, please make note of it in this bug report.