Bug 1691442

Summary: test_ipaclient/test_csrgen.py fails with segmentation fault
Product: [Fedora] Fedora Reporter: Sergey Orlov <sorlov>
Component: freeipaAssignee: IPA Maintainers <ipa-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 29CC: abokovoy, contribs, frenaud, ipa-maint, jcholast, jhrozek, pvoborni, rcritten, ssorce, twoerner
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-10-31 20:09:11 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:

Description Sergey Orlov 2019-03-21 15:43:47 UTC
Description of problem:
ipaclient/csrgen_ffi.py is incompatible with openssl 1.1
Affected components: tests, ipaclient/plugins/csrgen.py

Version-Release number of selected component (if applicable):
Fedora 28, Fedora 29

How reproducible:
Always

Steps to Reproduce:
1. get a machine without compat-openssl10 installed
2. ipa-run-tests test_ipaclient/test_csrgen.py::test_CSRGenerator::test_works_with_lowercase_attr_type_shortname

Actual results:
test_csrgen.py Segmentation fault (core dumped)

Expected results:
Test pass

Additional info:
segfault occurs at line [1] when called from [2] because req.req_info is NULL. To prove it I wrote small reproducer:

from ipaclient import csrgen_ffi
req = csrgen_ffi.X509_REQ_new()
assert req != csrgen_ffi.NULL, "req is NULL"
assert req.req_info != csrgen_ffi.NULL, "req_info is NULL"

The result of executions is "req_info is NULL"

The problem is that on Fedora 28 and 29 installed version of openssl is openssl-1.1.0i and according to [3], "All structures in libssl public header files have been removed so that they are "opaque" to library users. You should use the provided accessor functions instead", but the code at [1] is trying to directly access member of structure X509_REQ.

With compat-openssl10 package installed the tests pass.

I see two possible solutions for the issue: 
1. add compat-openssl10 to dependencies
2. rewrite ipaclient/csrgen_ffi.py to support openssl 1.1: do not access structure members directly, only use accessor methods.

[1] https://github.com/freeipa/freeipa/blob/master/ipaclient/csrgen_ffi.py#L164
[2] https://github.com/freeipa/freeipa/blob/master/ipaclient/csrgen_ffi.py#L292 
[3] https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes

Comment 1 Sergey Orlov 2019-03-21 15:45:43 UTC
Stacktrace at segfault:

(gdb) py-bt
Traceback (most recent call first):
  File "/usr/lib/python3.6/site-packages/ipaclient/csrgen_ffi.py", line 164, in X509_REQ_get_subject_name
    return req.req_info.subject
  (frame information optimized out)
  <built-in method exec of module object at remote 0x7fa62dbf8638>
  File "/usr/lib64/python3.6/pdb.py", line 376, in default
    exec(code, globals, locals)
  File "/usr/lib64/python3.6/cmd.py", line 216, in onecmd
    return self.default(line)
  File "/usr/lib64/python3.6/pdb.py", line 418, in onecmd
    return cmd.Cmd.onecmd(self, line)
  File "/usr/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 99, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib64/python3.6/pdb.py", line 321, in _cmdloop
    self.cmdloop()
  File "/usr/lib64/python3.6/pdb.py", line 352, in interaction
    self._cmdloop()
  File "/usr/lib/python3.6/site-packages/IPython/core/debugger.py", line 297, in interaction
    OldPdb.interaction(self, frame, traceback)
  File "/usr/lib64/python3.6/pdb.py", line 261, in user_line
    self.interaction(frame, None)
  File "/usr/lib64/python3.6/bdb.py", line 69, in dispatch_line
    self.user_line(frame)
  File "/usr/lib64/python3.6/bdb.py", line 51, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python3.6/site-packages/ipaclient/csrgen_ffi.py", line 290, in build_requestinfo
    if req == NULL:
  File "/usr/lib/python3.6/site-packages/ipatests/test_ipaclient/test_csrgen.py", line 264, in test_unrecognised_attr_type_raises
    config.encode('utf-8'), adaptor.get_subject_public_key_info())

Comment 2 Rob Crittenden 2019-05-13 19:00:40 UTC
Upstream ticket:
https://pagure.io/freeipa/issue/7937

Comment 3 Rob Crittenden 2019-05-13 19:01:34 UTC
master:

    ac6568d Fix build_requestinfo in OpenSSL1.1.0+ environments

Comment 4 Florence Blanc-Renaud 2019-05-29 15:15:31 UTC
master:

    7b8a2af Fix build_requestinfo in LibreSSL environments

ipa-4-7:
https://pagure.io/freeipa/c/58b12ee63ab970b07f36119a5f2ee81e95d5972b
https://pagure.io/freeipa/c/e003b7669d445fe2a2addd1b36b56f67695a6bc7

Comment 5 Ben Cotton 2019-10-31 19:12:54 UTC
This message is a reminder that Fedora 29 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 29 on 2019-11-26.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '29'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 29 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 6 Rob Crittenden 2019-10-31 20:09:11 UTC
This was included in the 4.7.3 release.