Bug 1322220

Summary: systemd service denied SELinux type transition from init_t to unconfined_service_t
Product: [Fedora] Fedora Reporter: Michael Chapman <redhat-bugzilla>
Component: selinux-policy-targetedAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED EOL QA Contact: Ben Levenson <benl>
Severity: high Docs Contact:
Priority: high    
Version: 23CC: amessina, dwalsh, lvrabec, mgrepl, redhat-bugzilla
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-20 19:42:27 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:

Description Michael Chapman 2016-03-30 04:13:46 UTC
This bug is against selinux-policy-targeted-3.13.1-158.11.fc23.noarch .

I have a systemd service which executes the PHP interpreter, /usr/bin/php. When this service is started (and when it subsequently forks off other processes), SELinux logs that the "security_bounded_transition" operation failed. The execve(2) calls succeed, but the processes all remain in the init_t domain rather than unconfined_service_t.

From my logs:

  Mar 30 14:35:51 beren.home audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=tt-rss-updater comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
  Mar 30 14:35:51 beren.home audit: SELINUX_ERR op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:init_t:s0 newcontext=system_u:system_r:unconfined_service_t:s0
  Mar 30 14:35:51 beren.home audit[15830]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=7ffe69ad6ae9 a1=7ffe69ad6cb0 a2=7ffe69ad6cd8 a3=7faa772daba8 items=0 ppid=1 pid=15830 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="php" exe="/usr/bin/php" subj=system_u:system_r:init_t:s0 key=(null)
  Mar 30 14:35:51 beren.home audit: PROCTITLE proctitle=...
  Mar 30 14:35:51 beren.home audit: SELINUX_ERR op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:init_t:s0 newcontext=system_u:system_r:initrc_t:s0
  Mar 30 14:35:51 beren.home audit[15877]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=7fbc7d91f473 a1=7ffc3a579720 a2=55dd1e668c40 a3=7fbc7d2fc270 items=0 ppid=15830 pid=15877 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="sh" exe="/usr/bin/bash" subj=system_u:system_r:init_t:s0 key=(null)
  Mar 30 14:35:51 beren.home audit: PROCTITLE proctitle=...
  Mar 30 14:35:51 beren.home audit: SELINUX_ERR op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:init_t:s0 newcontext=system_u:system_r:unconfined_service_t:s0
  Mar 30 14:35:51 beren.home audit[15877]: SYSCALL arch=c000003e syscall=59 success=yes exit=0 a0=5603c8e4ad60 a1=5603c8e4ae20 a2=5603c8e49b60 a3=7f83e853bbb8 items=0 ppid=15830 pid=15877 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="php" exe="/usr/bin/php" subj=system_u:system_r:init_t:s0 key=(null)
  Mar 30 14:35:51 beren.home audit: PROCTITLE proctitle=...

The SELinux label for the PHP binary is just bin_t, which should cause a type transition to unconfined_service_t. As far as I can that is allowed in the SELinux policy:

  # ls -lZ /usr/bin/php
  -rwxr-xr-x. 1 root root system_u:object_r:bin_t:s0 4425064 Mar  3 17:37 /usr/bin/php
  
  # sesearch -T -s init_t -t bin_t
  Found 1 semantic te rules:
     type_transition init_t bin_t : process unconfined_service_t; 
  
  Found 1 named file transition filename_trans:
  type_transition init_t bin_t : dir cupsd_rw_etc_t "inf"; 
  
  # sesearch -A -s init_t -t unconfined_service_t -c process -p transition
  Found 1 semantic av rules:
     allow init_t unconfined_service_t : process transition ; 

Let me know if you need me to put together a minimal test case demonstrating the problem.

Comment 1 Miroslav Grepl 2016-03-31 12:36:43 UTC
How does your unit file look? Do you use NoNewPrivileges option?

Comment 2 Michael Chapman 2016-03-31 21:57:58 UTC
(In reply to Miroslav Grepl from comment #1)
> How does your unit file look? Do you use NoNewPrivileges option?

Yes, I do:

  [Service]
  Type=simple
  ExecStart=/.../app.php

  User=apache
  Group=apache
  WorkingDirectory=/...

  PrivateTmp=true
  NoNewPrivileges=true

So I've been using that option for some time now, but as far as I can tell the SELinux errors have only started since upgrading to Fedora 23.

Comment 3 Miroslav Grepl 2016-04-01 16:02:47 UTC
Yes, we added changes related to NO_NEW_PRIVS to enable transitions under NO_NEW_PRIVS. For now lets continue with the init_t context and we will have a discussion about this "issue" with upstream.

Comment 4 Fedora End Of Life 2016-11-24 16:17:38 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. 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 '23'.

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 23 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 5 Fedora End Of Life 2016-12-20 19:42:27 UTC
Fedora 23 changed to end-of-life (EOL) status on 2016-12-20. Fedora 23 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.