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 1822100 - semanage loses sys.stderr
Summary: semanage loses sys.stderr
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: policycoreutils
Version: 8.4
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 8.0
Assignee: Vit Mojzis
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-04-08 09:12 UTC by debugitu
Modified: 2021-05-18 15:09 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-18 15:09:18 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description debugitu 2020-04-08 09:12:08 UTC
Description of problem:
  semanage loses sys.stderr

Version-Release number of selected component (if applicable):
  In fact it is on CentOS 7, I believe that the issue is the same on EL 7.

How reproducible:
  reproducible

Steps to Reproduce:
1.
  The policycoreutils-python package must be installed.

2.
  Issue the command:
  semanage fcontext -a -t home_root_t /u

3.
  Issue the command:
  semanage fcontext -l | egrep -s -q -e '^/u .*home_root_t'

Actual results:
  The command outputs:

  close failed in file object destructor:
  sys.excepthook is missing
  lost sys.stderr

Expected results:
  No output, or
  IOError: [Errno 32] Broken pipe
  output

Additional info:
  If I just do:
  semanage fcontext -l | egrep -s -q -e ''

  I get the error message, which is normal:
  IOError: [Errno 32] Broken pipe

  So the bug is probably related to managing the local customization(s).

  There is no guarantee that there might not be more important error condition to output than simple 'Broken pipe' message.

Comment 2 debugitu 2020-04-08 09:21:46 UTC
Sorry, it is not local customization related.
If I simply do:

semanage fcontext -l | egrep -s -q -e '^/home '

I got the same error:

  close failed in file object destructor:
  sys.excepthook is missing
  lost sys.stderr

It is probably just a race condition on exit.

Comment 3 Milos Malik 2020-04-08 09:38:59 UTC
Isn't the error caused by the grep process which terminates sooner than the semanage process?

Comment 4 debugitu 2020-04-08 09:58:55 UTC
The kernel sends a 'SIGPIPE' (13) signal to the active semanage process.

The semanage process sometimes correctly gives the error message:
 IOError: [Errno 32] Broken pipe
Sometimes incorrectly outputs:
  close failed in file object destructor:
  sys.excepthook is missing
  lost sys.stderr

Comment 5 Lukas Vrabec 2020-04-23 14:56:07 UTC
This issue was not selected to be included in Red Hat Enterprise Linux 7 because it is seen either as low or moderate impact to a small number of use-cases. Current minor release will be in Maintenance Support 1 Phase, which means that qualified Critical and Important Security errata advisories (RHSAs) and Urgent Priority Bug Fix errata advisories (RHBAs) may be released as they become available.

Moving the request to Red Hat Enterprise Linux 8 product.

Comment 6 Petr Lautrbach 2020-05-06 11:46:09 UTC
The problem seems to be described in Python's documentation - https://docs.python.org/3/library/signal.html#note-on-sigpipe

Comment 11 Vit Mojzis 2021-01-05 16:14:03 UTC
I wasn't able to reproduce the issue on RHEL 7.8, RHEL 8.3 or Fedora 34. The only issue I'm seeing is occasional double reporting of the "BrokenPipeError" (and "Exception ignored" warning):

#semanage fcontext -l | egrep -q -e '^/home'
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

which is caused by python flushing output on exit (as described in Comment 6).
I submitted a patch to upstream fixing this.

Are you still able to reproduce the behaviour you originally reported? If so, please share your python and policycoreutils-python(-utils) package versions or any additional steps that may help reproduce it.

Comment 12 debugitu 2021-01-05 17:21:51 UTC
I do not have 7.8 release any more, all are upgraded to 7.9.
I cannot see the reported error on 7.9.
I never tried on major release 8.

Before, the specific error was very stable, it always came. It did not seem to be a race condition, however that cannot be excluded.

If the code of the policycoreutils-python kit did not change from 7.8 to 7.9, may be the code of some underlying python library?

Comment 13 Vit Mojzis 2021-01-11 10:31:55 UTC
(In reply to debugitu from comment #12)
> I do not have 7.8 release any more, all are upgraded to 7.9.
> I cannot see the reported error on 7.9.
> I never tried on major release 8.
> 
> Before, the specific error was very stable, it always came. It did not seem
> to be a race condition, however that cannot be excluded.
> 
> If the code of the policycoreutils-python kit did not change from 7.8 to
> 7.9, may be the code of some underlying python library?

Thank you. I was thinking the same thing (change in some python I/O library).
Anyway, this is the patch (I'll merge it as soon as upstream accepts it):
https://lore.kernel.org/selinux/CAJfZ7==efgpSLs-U81UEp-0ven0mr3WZMLpP1+1XC8a-ww0uSg@mail.gmail.com/T/#t

Comment 24 errata-xmlrpc 2021-05-18 15:09:18 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 (policycoreutils 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-2021:1715


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