Bug 1401385

Summary: selinux problems with staff_t systemd --user
Product: [Fedora] Fedora Reporter: Robin Powell <rlpowell>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 25CC: dominick.grift, dwalsh, lvrabec, mgrepl, plautrba, pmoore, ssekidde
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: 2017-12-12 10:55:04 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 Robin Powell 2016-12-05 05:46:48 UTC
This may or may not be related to https://bugzilla.redhat.com/show_bug.cgi?id=1263350 and the comments I made there; I couldn't tell so it seemed worth making a new bug.

On a system with the unconfined module disabled, doing this:

```
rlpowell@stodi> sudo systemctl restart user
rlpowell@stodi> sudo systemctl status user
● user - User Manager for UID 1052
   Loaded: loaded (/usr/lib/systemd/system/user@.service; static; vendor preset: disabled)
   Active: active (running) since Sun 2016-12-04 21:32:29 PST; 7s ago
 Main PID: 20515 (systemd)
   Status: "Startup finished in 5ms."
    Tasks: 2
   Memory: 2.5M
      CPU: 102ms
   CGroup: /user.slice/user-1052.slice/user
           └─init.scope
             ├─20515 /usr/lib/systemd/systemd --user
             └─20517 (sd-pam)

Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Created slice -.slice.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: dbus.socket: Failed to listen on sockets: No such file or directory
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Failed to listen on D-Bus User Message Bus Socket.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: dbus.socket: Unit entered failed state.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Reached target Sockets.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Reached target Timers.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Reached target Basic System.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Reached target Default.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[20515]: Startup finished in 5ms.
Dec 04 21:32:29 stodi.digitalkingdom.org systemd[1]: Started User Manager for UID 1052.
```

for a staff_t user results in:

```

type=AVC msg=audit(1480915949.459:2945): avc:  denied  { write } for  pid=18800 comm="systemd" name="user" dev="cgroup" ino=835 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480915949.459:2946): avc:  denied  { remove_name } for  pid=18800 comm="systemd" name="init.scope" dev="cgroup" ino=840 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480915949.459:2947): avc:  denied  { rmdir } for  pid=18800 comm="systemd" name="init.scope" dev="cgroup" ino=840 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480915949.579:2953): avc:  denied  { ioctl } for  pid=20515 comm="systemd" path="socket:[312982]" dev="sockfs" ino=312982 ioctlcmd=0x5401 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:system_r:init_t:s0 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1480916032.710:2963): avc:  denied  { setpgid } for  pid=20750 comm="timeout" scontext=system_u:system_r:system_cronjob_t:s0-s0:c0.c1023 tcontext=system_u:system_r:system_cronjob_t:s0-s0:c0.c1023 tclass=process permissive=1
type=AVC msg=audit(1480916032.725:2964): avc:  denied  { connectto } for  pid=20751 comm="nc" path="/run/clamd.exim/clamd.sock" scontext=system_u:system_r:system_cronjob_t:s0-s0:c0.c1023 tcontext=system_u:system_r:antivirus_t:s0 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1480916036.248:2965): avc:  denied  { wake_alarm } for  pid=1016 comm="systemd-udevd" capability=35  scontext=system_u:system_r:udev_t:s0-s0:c0.c1023 tcontext=system_u:system_r:udev_t:s0-s0:c0.c1023 tclass=capability2 permissive=1
```

But for normal users it works fine.

(Some of those AVCs are probably something else; sorry)

Comment 1 Robin Powell 2016-12-05 05:49:09 UTC
What's interesting to me is that this failure occurs even when setenforce 0.  That is: with setenforce 0, systemd --user fails to actually work because it doesn't set up the dbus properly, and it appears to be selinux's fault.  Maybe something else is causing the failure, though?, hard to tell.

Comment 2 Robin Powell 2016-12-05 06:08:00 UTC
So I patched the above using audit2allow, and ran it again.  This time it actually *succeeded*, so here's the AVCs from that run (with dontaudit off, and setenforce 0):



type=AVC msg=audit(1480917931.883:3563): avc:  denied  { wake_alarm } for  pid=1016 comm="systemd-udevd" capability=35  scontext=system_u:system_r:udev_t:s0-s0:c0.c1023 tcont
ext=system_u:system_r:udev_t:s0-s0:c0.c1023 tclass=capability2 permissive=1
type=AVC msg=audit(1480917931.894:3564): avc:  denied  { rlimitinh } for  pid=31004 comm="unix_chkpwd" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:chkpwd_
t:s0 tclass=process permissive=1
type=AVC msg=audit(1480917931.894:3565): avc:  denied  { siginh } for  pid=31004 comm="unix_chkpwd" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:chkpwd_t:s
0 tclass=process permissive=1
type=AVC msg=audit(1480917931.894:3566): avc:  denied  { noatsecure } for  pid=31004 comm="unix_chkpwd" scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:chkpwd
_t:s0 tclass=process permissive=1
type=AVC msg=audit(1480917931.959:3571): avc:  denied  { wake_alarm } for  pid=1016 comm="systemd-udevd" capability=35  scontext=system_u:system_r:udev_t:s0-s0:c0.c1023 tcont
ext=system_u:system_r:udev_t:s0-s0:c0.c1023 tclass=capability2 permissive=1
type=AVC msg=audit(1480917931.960:3572): avc:  denied  { read write } for  pid=30998 comm="systemd" path="socket:[352447]" dev="sockfs" ino=352447 scontext=staff_u:staff_r:st
aff_t:s0-s0:c0.c1023 tcontext=system_u:system_r:init_t:s0 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1480917931.960:3573): avc:  denied  { rlimitinh } for  pid=30998 comm="systemd" scontext=system_u:system_r:init_t:s0 tcontext=staff_u:staff_r:staff_t:s0-s0
:c0.c1023 tclass=process permissive=1
type=AVC msg=audit(1480917931.960:3574): avc:  denied  { siginh } for  pid=30998 comm="systemd" scontext=system_u:system_r:init_t:s0 tcontext=staff_u:staff_r:staff_t:s0-s0:c0
.c1023 tclass=process permissive=1
type=AVC msg=audit(1480917931.960:3575): avc:  denied  { read execute } for  pid=30998 comm="systemd" path="/usr/lib/systemd/systemd" dev="vda2" ino=534955 scontext=staff_u:s
taff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:init_exec_t:s0 tclass=file permissive=1
type=AVC msg=audit(1480917931.968:3576): avc:  denied  { add_name } for  pid=30998 comm="systemd" name="init.scope" scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=s
ystem_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480917931.968:3577): avc:  denied  { create } for  pid=30998 comm="systemd" name="init.scope" scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=sta
ff_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480917931.968:3578): avc:  denied  { getattr } for  pid=30998 comm="systemd" path="/sys/fs/cgroup/cpu" dev="tmpfs" ino=9880 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:tmpfs_t:s0 tclass=lnk_file permissive=1
type=AVC msg=audit(1480917931.978:3579): avc:  denied  { read } for  pid=30998 comm="systemd" name="mount" dev="tmpfs" ino=12299 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:mount_var_run_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480917931.984:3580): avc:  denied  { read } for  pid=30998 comm="systemd" name="cpu" dev="tmpfs" ino=9880 scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:tmpfs_t:s0 tclass=lnk_file permissive=1
type=AVC msg=audit(1480917931.985:3581): avc:  denied  { add_name } for  pid=30998 comm="systemd" name="dbus.socket" scontext=staff_u:staff_r:staff_t:s0-s0:c0.c1023 tcontext=system_u:object_r:cgroup_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1480917933.711:3585): avc:  denied  { read write } for  pid=1 comm="systemd" path="socket:[350620]" dev="sockfs" ino=350620 scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:kernel_t:s0 tclass=unix_stream_socket permissive=1
type=AVC msg=audit(1480917933.792:3586): avc:  denied  { read write } for  pid=1 comm="systemd" path="socket:[350622]" dev="sockfs" ino=350622 scontext=system_u:system_r:init_t:s0 tcontext=system_u:system_r:kernel_t:s0-s0:c0.c1023 tclass=unix_stream_socket permissive=1

The module I added has this:

fs_delete_cgroup_dirs(staff_t)
init_ioctl_stream_sockets(staff_t)

Comment 3 Robin Powell 2016-12-05 07:10:11 UTC
FWIW, here's the full working module; I've not confirmed that everything in here is necessary, but the mount_var_run_t bit definitely is:

policy_module(MYLOCAL_systemdbugs1401385,1.0.0)

require {
        type staff_t;
        type mount_var_run_t;
        class dir { read };
}                                                                                                                                                                             
                                                                                                                                                                              # systemd + staff_t -- https://bugzilla.redhat.com/show_bug.cgi?id=1401385
fs_delete_cgroup_dirs(staff_t)
init_ioctl_stream_sockets(staff_t)
fs_manage_cgroup_dirs(staff_t)                                                                                                                                                fs_read_tmpfs_symlinks(staff_t)
init_exec(staff_t)
init_rw_stream_sockets(staff_t)
allow staff_t mount_var_run_t:dir read;

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

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 25 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 2017-12-12 10:55:04 UTC
Fedora 25 changed to end-of-life (EOL) status on 2017-12-12. Fedora 25 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.