Bug 2066439

Summary: certmonger SEGV during rekey in FIPS mode
Product: Red Hat Enterprise Linux 9 Reporter: Rob Crittenden <rcritten>
Component: certmongerAssignee: Rob Crittenden <rcritten>
Status: CLOSED ERRATA QA Contact: ipa-qe <ipa-qe>
Severity: high Docs Contact:
Priority: medium    
Version: 9.0CC: gkaihoro, myusuf
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: certmonger-0.79.14-7.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2150070 (view as bug list) Environment:
Last Closed: 2022-11-15 10:14:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2150070    

Description Rob Crittenden 2022-03-21 19:00:28 UTC
Description of problem:

Segmentation fault trying to rekey a request while in FIPS mode.

#0  util_NETSCAPE_SPKI_set_sig_alg (sig_alg=<optimized out>, 
    spki=<optimized out>)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/util-o.c:184
#1  cm_csrgen_o_main (fd=<optimized out>, ca=<optimized out>, 
    entry=<optimized out>, userdata=<optimized out>)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/csrgen-o.c:362
#2  0x0000563ab5ef05e1 in cm_subproc_start (
    cb=0x563ab5f1a660 <cm_csrgen_o_main>, parent=<optimized out>, ca=0x0, 
    entry=0x563ab7bae6e0, data=0x0)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/subproc.c:190
#3  0x0000563ab5f25599 in cm_csrgen_o_start (entry=0x563ab7bae6e0)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/csrgen-o.c:589
#4  cm_csrgen_start (entry=0x563ab7bae6e0)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/csrgen.c:106
#5  cm_iterate_entry (get_ca_by_index=<optimized out>, 
    get_n_cas=<optimized out>, get_entry_by_index=<optimized out>, 
    get_n_entries=<optimized out>, emit_entry_saved_cert=<optimized out>, 
    emit_entry_changes=<optimized out>, readfd=<synthetic pointer>, 
    delay=<synthetic pointer>, when=<synthetic pointer>, 
    cm_iterate_state=<optimized out>, context=0x563ab7b78000, 
    ca=<optimized out>, entry=0x563ab7bae6e0)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/iterate.c:815
#6  cm_service_entry.constprop.0 (context=0x563ab7b78000, i=<optimized out>, 
    current_time=0x0)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/cm.c:434
#7  0x0000563ab5ee25e6 in cm_timer_h (ec=<optimized out>, te=0x563ab7bd2430, 
    current_time=..., pvt=0x563ab7b78000)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/cm.c:208
#8  0x00007f572361664e in tevent_common_invoke_timer_handler ()
   from /lib64/libtevent.so.0
#9  0x00007f5723616810 in tevent_common_loop_timer_delay ()
   from /lib64/libtevent.so.0
#10 0x00007f57236172e9 in epoll_event_loop_once () from /lib64/libtevent.so.0
#11 0x00007f572360f69b in std_event_loop_once () from /lib64/libtevent.so.0
#12 0x00007f5723611da8 in _tevent_loop_once () from /lib64/libtevent.so.0
#13 0x0000563ab5edfc93 in main (argc=<optimized out>, argv=<optimized out>)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/main.c:413

The trace points to util_NETSCAPE_SPKI_set_sig_alg but the gdb output is

#0  util_NETSCAPE_SPKI_set_sig_alg (sig_alg=<optimized out>, 
    spki=<optimized out>)
    at /usr/src/debug/certmonger-0.79.14-5.el9.x86_64/src/util-o.c:184
184             return ASN1_BIT_STRING_new();

Version-Release number of selected component (if applicable):
certmonger-0.79.14-5.el9.x86_64

How reproducible:

Every time

Steps to Reproduce:
0. install IPA server
1. kinit admin
2. ipa service-add test/master.testrealm.test
3. getcert request -f /etc/pki/tls/certs/test.pem -k /etc/pki/tls/private/test.key -K test/master.testrealm.test -I test
4. getcert rekey -i test -g 3072 -G DSA

Note that changing the key type to DSA appears to be unrelated.

Comment 1 Rob Crittenden 2022-03-21 19:25:50 UTC
valgrind is detecting a couple of errors. The return value of malloc() is checked but it isn't enforced and a variable may be re-used later. It doesn't seem entirely related.

==19083== Invalid read of size 1
==19083==    at 0x1268C0: cm_store_hex_from_bin (store-gen.c:498)
==19083==    by 0x144D3E: cm_keyiread_o_main.lto_priv.0 (keyiread-o.c:190)
==19083==    by 0x12A5E0: cm_subproc_start (subproc.c:190)
==19083==    by 0x11D58C: UnknownInlinedFun (keyiread-o.c:341)
==19083==    by 0x11D58C: cm_keyiread_start (keyiread.c:41)
==19083==    by 0x11D61E: cm_iterate_entry_init (iterate.c:479)
==19083==    by 0x119247: UnknownInlinedFun (cm.c:146)
==19083==    by 0x119247: main (main.c:286)
==19083==  Address 0x6a71a8e is 0 bytes after a block of size 270 alloc'd
==19083==    at 0x484486F: malloc (vg_replace_malloc.c:381)
==19083==    by 0x144D17: cm_keyiread_o_main.lto_priv.0 (keyiread-o.c:187)
==19083==    by 0x12A5E0: cm_subproc_start (subproc.c:190)
==19083==    by 0x11D58C: UnknownInlinedFun (keyiread-o.c:341)
==19083==    by 0x11D58C: cm_keyiread_start (keyiread.c:41)
==19083==    by 0x11D61E: cm_iterate_entry_init (iterate.c:479)
==19083==    by 0x119247: UnknownInlinedFun (cm.c:146)
==19083==    by 0x119247: main (main.c:286)
==19083== 
==19083== Invalid read of size 1
==19083==    at 0x1268D4: cm_store_hex_from_bin (store-gen.c:499)
==19083==    by 0x144D3E: cm_keyiread_o_main.lto_priv.0 (keyiread-o.c:190)
==19083==    by 0x12A5E0: cm_subproc_start (subproc.c:190)
==19083==    by 0x11D58C: UnknownInlinedFun (keyiread-o.c:341)
==19083==    by 0x11D58C: cm_keyiread_start (keyiread.c:41)
==19083==    by 0x11D61E: cm_iterate_entry_init (iterate.c:479)
==19083==    by 0x119247: UnknownInlinedFun (cm.c:146)
==19083==    by 0x119247: main (main.c:286)
==19083==  Address 0x6a71a8e is 0 bytes after a block of size 270 alloc'd
==19083==    at 0x484486F: malloc (vg_replace_malloc.c:381)
==19083==    by 0x144D17: cm_keyiread_o_main.lto_priv.0 (keyiread-o.c:187)
==19083==    by 0x12A5E0: cm_subproc_start (subproc.c:190)
==19083==    by 0x11D58C: UnknownInlinedFun (keyiread-o.c:341)
==19083==    by 0x11D58C: cm_keyiread_start (keyiread.c:41)
==19083==    by 0x11D61E: cm_iterate_entry_init (iterate.c:479)
==19083==    by 0x119247: UnknownInlinedFun (cm.c:146)
==19083==    by 0x119247: main (main.c:286)

Comment 2 Rob Crittenden 2022-03-21 21:42:05 UTC
This isn't related to rekeying. It is failing trying to generate a DSA CSR whether a new or rekey.

The key is generating ok, it seems only related to the CSR. The key file exists, contains a DSA key of the right size and openssl dsa can parse it without complaint (other than not being able to write PEM files on output).

certmonger-0.79.9 removed the test csrgen-003-dsa with the message:

    Remove DSA testing for NSS which disables it in crypto policy
    
    DSA is disabled in DEFAULT crypto policy in F30+

Simo tells me that DSA is forcibly disabled in FIPS and not relying on policy. That explains why I didn't see a policy to kill it.

I'll investigate further to see if I should disable DSA key type by passing --disable-dsa to configure in the build.

Comment 3 Rob Crittenden 2022-03-28 18:48:37 UTC
Note that when not in FIPS mode a DSA key can be generated but the CA will not issue a certificate for it, logging:

SEVERE: Unable to create enrollment request: Invalid Request
Invalid Request
[ snip backtrace ]
Caused by: java.security.NoSuchAlgorithmException: no such algorithm: OID.2.16.840.1.101.3.4.3.2 for provider Mozilla-JSS

So completely disabling DSA is not a reduction in functionality, more of an acceptance of reality.

Comment 9 errata-xmlrpc 2022-11-15 10:14:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (certmonger bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:8059