RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2144553 - annocheck reports that no compiled code found in /usr/lib64/libpython3.so
Summary: annocheck reports that no compiled code found in /usr/lib64/libpython3.so
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: annobin
Version: 9.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Nick Clifton
QA Contact: Václav Kadlčík
URL:
Whiteboard:
Depends On:
Blocks: 2188638
TreeView+ depends on / blocked
 
Reported: 2022-11-21 15:54 UTC by Jan Pazdziora (Red Hat)
Modified: 2023-11-07 09:53 UTC (History)
5 users (show)

Fixed In Version: gcc-toolset-13-annobin-12.14-1.el9
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 2188638 (view as bug list)
Environment:
Last Closed: 2023-11-07 08:33:57 UTC
Type: Bug
Target Upstream Version:
Embargoed:
mhroncok: needinfo+
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-140057 0 None None None 2022-11-21 16:01:09 UTC
Red Hat Product Errata RHBA-2023:6475 0 None None None 2023-11-07 08:34:07 UTC

Description Jan Pazdziora (Red Hat) 2022-11-21 15:54:24 UTC
Description of problem:

Attempting to test if python3.9's libraries were properly built with stack protection via -fstack-protector-strong yields skip: stack-prot test because no compiled code found.

Version-Release number of selected component (if applicable):

python3-libs-3.9.10-4.el9_0.x86_64
annobin-annocheck-10.54-2.el9.x86_64

How reproducible:

Deterministic.

Steps to Reproduce:
1. dnf install -y annobin-annocheck python3-libs
2. dnf debuginfo-install -y python3-libs
3. annocheck --verbose --skip-all --test-stack-prot /usr/lib64/libpython3.so

Actual results:

annocheck: Version 10.54.
Hardened: libpython3.so: warn: Failed to parse separate debug file '/usr/lib/debug/.build-id/79/5b90799cdb29f0cf57fe25a9265285c1e1fd78.debug', (no DWARF information).
Hardened: libpython3.so: warn: Failed to parse separate debug file '/usr/lib/debug/.build-id/79/5b90799cdb29f0cf57fe25a9265285c1e1fd78.debug', (no DWARF information).
Hardened: libpython3.so: warn: Failed to parse separate debug file '/usr/lib/debug/.build-id/79/5b90799cdb29f0cf57fe25a9265285c1e1fd78.debug', (no DWARF information).
Hardened: /usr/lib64/libpython3.so: skip: stack-prot test because no compiled code found 
Hardened: /usr/lib64/libpython3.so: Overall: PASS.

Expected results:

Assuming there is a compiled code in that library, annocheck should find it.

Additional info:

Adding Nick to Cc in case this turns out to be an issue in annocheck itself.

Comment 1 Nick Clifton 2022-11-21 16:36:21 UTC
Hi Jan,
 
> python3-libs-3.9.10-4.el9_0.x86_64

Please could you point me at this build.  I cannot seem to find it in brew. :-(

Cheers
  Nick

Comment 4 Nick Clifton 2022-11-21 17:53:03 UTC
Hi Jan,

  This is another case where annocheck is unable to determine how an executable
  was produced and so it defaults to assuming that it was not compiled from C
  and/or C++.

  It seems that the debuginfo file which should contain the needed information
  is instead empty.  (Empty of DWARF information and annobin data, that is).

  I am not sure if it is relevent, but I did notice these lines in the build.log
  file for python3-libs build:

    gdb-add-index: No index was created for /builddir/build/BUILDROOT/python3.9-3.9.10-4.el9_0.x86_64/usr/lib64/libpython3.so
    gdb-add-index: [Was there no debuginfo? Was there already an index?]

  Maybe this gdb-add-index program/script is having problems and accidentally
  removing the debug info ?

Cheers
  Nick

Comment 6 Jan Pazdziora (Red Hat) 2022-11-22 07:37:48 UTC
Thank you Nick for the analysis. That gdb-add-index seems to come from the gdb-headless package, from the gdb component. Do we suspect that to be the problematic part, or does it just point out the problem caused by something else in the build chain?

Comment 7 Nick Clifton 2022-11-22 12:17:46 UTC
(In reply to Jan Pazdziora from comment #6)
> Thank you Nick for the analysis. That gdb-add-index seems to come from the
> gdb-headless package, from the gdb component. Do we suspect that to be the
> problematic part, or does it just point out the problem caused by something
> else in the build chain?

Probably that the problem was caused earlier on.  Given the messages generated by gdb-add-index, the implication is that the debug information was already missing by the time that it ran.  But I suppose that there is also the possibility that there is a bug in gdb-add-index which causes it to think that the debug information is missing and then generate an empty(ish) output file.

To be sure we have to take off and nuke the place from orbit.  No, sorry, I meant, to be sure we are going to have to examine the file before it is processed by gdb-add-index.  Is this something that you can do ?  I can try, but I am assuming that you are the python library building expert and would better know how to intercept the build sequence.

Comment 8 Jan Pazdziora (Red Hat) 2022-11-22 12:37:21 UTC
I know nothing about how the python package is built, so we'd need Python maintainers' help here.

Comment 9 Miro Hrončok 2022-11-22 12:46:01 UTC
You should be able to add an exit 1 call to the end of the %install section and retrieve the files from mock. If you need more detail, let us know.

Comment 11 Nick Clifton 2022-11-22 15:08:22 UTC
I suspect that this issue is going to be similar to BZ 2144520.  Ie the %install stage is rebuilding the binaries without the security hardening options.  I am currently testing this theory out using scratch builds...

Comment 12 Nick Clifton 2022-11-22 16:27:27 UTC
Hmmm - it appears that there is something funny going on with the creation of the debuginfo file for the libpython3.so library.  But only this library, no others.  No idea why at the moment...

Comment 13 Miro Hrončok 2022-11-22 17:13:44 UTC
Is it possible that this is related? https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/GSSY4PVH2JOSSQJZHKOYFURO4BJT4ES4/

/usr/lib/debug/usr/lib64/libpython3.so-3.11.0-1.fc38.x86_64.debug in python3.11-debuginfo-3.11.0-1.fc38 on x86_64 is missing ELF sections 

(from Fedora)

Comment 14 Jan Pazdziora (Red Hat) 2022-11-22 18:43:27 UTC
Checking with

readelf -Ws /usr/lib64/libpython3.so | grep '__stack_chk_fail'

does not find anything, meaning the function to be called when the stack protection detects a corrupted stack is not referenced. So it seems to suggest -fstack-protector-strong was indeed not used.

Comment 16 Nick Clifton 2022-11-23 11:56:34 UTC
It appears that libpython3.so is a special case.  Basically is appears to exist so that applications that use the python3 library can have "-lpython3" on their final link command line, and this will work regardless of the version of python3 that is installed.

The libpython3.so library does not contain any real code of its own, (except for the C run time startup and termination files crti.o, crtbeginS.o, crtendS.o and crtn.o).  Instead it contains a dynamic tag indicating that the libpython3.9.so.1.0 shared library is needed.  This contains all of the real C-compiled python support code.

Hence it makes sense that libpython3.so does not contain any references to __stack_chk_fail and that annocheck is unable to determine that it contains compiled code - it does not.  It only contains assembler built code, which neither needs nor uses the stack checking functions.

So, in the short term, it looks like libpython3.so is a candidate for an exception to the annocheck tests.  In the long term it might be nice to find a way to replace libpython3.so.  Maybe with a symbolic link, or a linker script fragment.

Comment 17 Jan Pazdziora (Red Hat) 2022-11-23 12:10:17 UTC
So does it mean that in fact annocheck is correct with that

  "skip: stack-prot test because no compiled code found"

message here?

Annocheck emits the same message for iputils (bug 2144509) where it seems the proper compiler flags were missing. Could annocheck be able to distinguish those two cases and emit different messages?

Comment 18 Nick Clifton 2022-11-23 12:33:24 UTC
(In reply to Jan Pazdziora from comment #17)
> So does it mean that in fact annocheck is correct with that
> 
>   "skip: stack-prot test because no compiled code found"
> 
> message here?

Yes.  In the case of libpython3.so there is no compiled code,
so annocheck is correct in skipping the test and not flagging
it as a potential problem.

 
> Annocheck emits the same message for iputils (bug 2144509) where it seems
> the proper compiler flags were missing.  Could annocheck be able to
> distinguish those two cases and emit different messages?

It would be nice, but I am not sure how to do it.  The problem is that
there is no real difference between an executable that was built from
code that was not compiled and an executable that was built from compiled
code that has not had any annobin annotation or debug info generation.

Annocheck does use various heuristics, such as looking in the .comment
section (if present) and examining the DW_AT_producer tag (if DWARF debug
information is available).  But if these are missing, and there is no
annobin data either (the annobin data includes details of the compiler
used to create the binary) then annocheck is stuck.

I suppose that we could have a check that says something like "the .text
section in this file is larger than 1K - was it really all produced from
assembler sources ?" but that would probably trigger false positives for
some packages.

Not sure really.  Any suggestions or ideas are most welcome.

Comment 19 Miro Hrončok 2022-11-23 12:42:54 UTC
> In the long term it might be nice to find a way to replace libpython3.so.  Maybe with a symbolic link, or a linker script fragment.

Is there a (upstream) compelling reason to do so, other than this check?

Comment 20 Nick Clifton 2022-11-23 12:47:10 UTC
(In reply to Miro Hrončok from comment #19)
> > In the long term it might be nice to find a way to replace libpython3.so.  Maybe with a symbolic link, or a linker script fragment.
> 
> Is there a (upstream) compelling reason to do so, other than this check?

No. :-}

It would reduce the size of the python3-lib package slightly, but not by much.

In the end the current method works and the only reason for changing it would be for our own convenience.

Comment 21 Jan Pazdziora (Red Hat) 2022-11-23 12:50:19 UTC
(In reply to Nick Clifton from comment #18)
> 
> It would be nice, but I am not sure how to do it.  The problem is that
> there is no real difference between an executable that was built from
> code that was not compiled and an executable that was built from compiled
> code that has not had any annobin annotation or debug info generation.

Couldn't annobin help by adding an explicit annotation for the "no compiled code in here" situation?

Comment 22 Jan Pazdziora (Red Hat) 2022-11-23 12:52:50 UTC
(In reply to Nick Clifton from comment #20)
> 
> In the end the current method works and the only reason for changing it
> would be for our own convenience.

I wouldn't call it convenience. :-)

The reason I started digging into this is really a case of build process and result compliance with internal guidelines and external requirements, and our ability to prove that compliance.

Comment 23 Nick Clifton 2022-11-23 12:58:31 UTC
(In reply to Jan Pazdziora from comment #21)
> (In reply to Nick Clifton from comment #18)
> > 
> > It would be nice, but I am not sure how to do it.  The problem is that
> > there is no real difference between an executable that was built from
> > code that was not compiled and an executable that was built from compiled
> > code that has not had any annobin annotation or debug info generation.
> 
> Couldn't annobin help by adding an explicit annotation for the "no compiled
> code in here" situation?

Oh yes - that is something that I can (and will) do.

Comment 24 Nick Clifton 2022-11-23 13:59:43 UTC
FYI,  I am working on an update for annocheck which changes the skip message to:

  skip: stack-prot test because no compiled code found 
  WARNING: Absence of compiler code might indicate a lack of security annotation.
  WARNING: For more details see https://sourceware.org/annobin/annobin.html/Absence-of-compiled-code.html

I decided to put the description of the problem into a web page as it turned out to be more than just a few lines...

Comment 25 Nick Clifton 2023-04-28 12:03:02 UTC
Fixed in gcc-toolset-13-annobin-12.09-1.el9

Comment 30 Nick Clifton 2023-06-22 14:52:36 UTC
Changing back to ASSIGNED.

We have discovered a problem.  In RHEL-9 the annobin notes are stored in the separate debug info file, rather than the binary itself.  But if the separate debug info file does not contain any actual debug information, eg because the executable was compiled without debugging support, then annocheck thinks that the file is corrupt, and so it does not check it for annobin notes.  This means that annocheck does not see the notes for libython3.so (for RHEL-9) and so it generated a MAYB result.  On RHEL-8, where the notes are held in the actual binary, annocheck sees them and generates a PASS result.

Comment 31 Nick Clifton 2023-06-23 12:36:16 UTC
Fixed in gcc-toolset-13-annobin-12.14-1.el9

Comment 36 errata-xmlrpc 2023-11-07 08:33:57 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 (gcc-toolset-13-annobin 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-2023:6475


Note You need to log in before you can comment on or make changes to this bug.