Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1253926 - SELinux is preventing /usr/lib/systemd/systemd-sysctl from using the 'sys_ptrace' capabilities.
Summary: SELinux is preventing /usr/lib/systemd/systemd-sysctl from using the 'sys_ptr...
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 22
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Lukas Vrabec
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: abrt_hash:d75ba7b4dc0ac5defdcd6c8774d...
: 1255980 1256334 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-08-15 18:05 UTC by Mark Wielaard
Modified: 2018-09-06 21:32 UTC (History)
23 users (show)

Fixed In Version: 3.13.1-128.12.fc22
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-08-27 18:25:05 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Mark Wielaard 2015-08-15 18:05:55 UTC
Description of problem:
When putting a ptrace related sysctl into a file under /etc/sysctl.d/ systemd-sysctld gets blocked by selinux.

$ echo "kernel.yama.ptrace_scope = 0" | sudo tee /etc/sysctl.d/yama_scope.conf
kernel.yama.ptrace_scope = 0

$ sudo systemctl restart systemd-sysctl.service
Job for systemd-sysctl.service failed. See "systemctl status systemd-sysctl.service" and "journalctl -xe" for details.
SELinux is preventing /usr/lib/systemd/systemd-sysctl from using the 'sys_ptrace' capabilities.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that systemd-sysctl should have the sys_ptrace capability by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep systemd-sysctl /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Additional Information:
Source Context                system_u:system_r:systemd_sysctl_t:s0
Target Context                system_u:system_r:systemd_sysctl_t:s0
Target Objects                Unknown [ capability ]
Source                        systemd-sysctl
Source Path                   /usr/lib/systemd/systemd-sysctl
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           systemd-219-18.fc22.x86_64
Target RPM Packages           
Policy RPM                    selinux-policy-3.13.1-128.4.fc22.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     (removed)
Platform                      Linux (removed) 4.0.8-300.fc22.x86_64 #1 SMP Fri
                              Jul 10 21:04:56 UTC 2015 x86_64 x86_64
Alert Count                   11
First Seen                    2015-08-15 16:36:10 CEST
Last Seen                     2015-08-15 19:57:57 CEST
Local ID                      8076a322-c75c-4b63-8e5d-14ecb6d6522d

Raw Audit Messages
type=AVC msg=audit(1439661477.273:552): avc:  denied  { sys_ptrace } for  pid=2666 comm="systemd-sysctl" capability=19  scontext=system_u:system_r:systemd_sysctl_t:s0 tcontext=system_u:system_r:systemd_sysctl_t:s0 tclass=capability permissive=0


type=SYSCALL msg=audit(1439661477.273:552): arch=x86_64 syscall=write success=no exit=EPERM a0=4 a1=7f47eb4d2000 a2=2 a3=22 items=0 ppid=1 pid=2666 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=systemd-sysctl exe=/usr/lib/systemd/systemd-sysctl subj=system_u:system_r:systemd_sysctl_t:s0 key=(null)

Hash: systemd-sysctl,systemd_sysctl_t,systemd_sysctl_t,capability,sys_ptrace

Version-Release number of selected component:
selinux-policy-3.13.1-128.4.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.0.8-300.fc22.x86_64
type:           libreport

Comment 1 Sergio Durigan Junior 2015-08-16 03:13:15 UTC
I found some interesting things about this bug.

In my machine, with SELinux fully enabled (and without any modifications), I can manually execute /usr/lib/systemd/systemd-sysctl (i.e., not restart the service, but call the program directly from the command line), and it *successfully* does its job.  No SELinux errors, nothing.  However, I can reproduce the bug reported by Mark when I issue a "systemctl restart systemd-sysctl.service" (i.e., SELinux gives me a no-no and systemd-sysctl does not update the ptrace_scope file under /proc).

FWIW, this is the reason why the %sysctl_apply macro works fine when you install a RPM which performs this modification on ptrace_scope: the macro actually executes /usr/lib/systemd/systemd-sysctl directly, and don't restart the service.  However, the user will be affected in the next reboot because the service will be started on the boot, leading to the SELinux error.

Comment 2 Mark Wielaard 2015-08-16 10:27:28 UTC
(In reply to Sergio Durigan Junior from comment #1)
> I found some interesting things about this bug.

Nice find! Indeed just running:
$ sudo /usr/lib/systemd/systemd-sysct
works fine, without selinux errors and sets the sysctl value as expected.
But running:
$ sudo systemctl restart systemd-sysctl.service
gives selinux errors and doesn't set the sysctl value.

That is strange, The /usr/lib/systemd/system/systemd-sysctl.service file looks very simple:

[Unit]
Description=Apply Kernel Variables
Documentation=man:systemd-sysctl.service(8) man:sysctl.d(5)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-modules-load.service
Before=sysinit.target shutdown.target
ConditionPathIsReadWrite=/proc/sys/

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/systemd/systemd-sysctl

What is also strange is that for me it depends on which kernel I boot into whether or not the sysctl value is set. With 4.1.4-200 the value isn't set. But when I boot into 4.1.5-200 the value is set. Even though in both cases systemctl status systemd-sysctl shows the service failed.... strange.

Comment 3 Mark Wielaard 2015-08-16 10:36:16 UTC
BTW. The workaround suggested in the selinux alert message:
# grep systemd-sysctl /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
Works fine in all cases. No more errors are generated and the sysctl value is always set correctly.

Comment 4 Mark Wielaard 2015-08-16 18:31:47 UTC
The following explains why systemd-sysctl seems to just work fine when run by hand or through rpm, dnf, etc. but not when run through systemctrl. In the first case it runs unconfined, but in the second case it transitions to systemd_sysctl_t and so gets blocked by selinux when it is missing a permission to set a sysctl value:
http://danwalsh.livejournal.com/23944.html
https://fedoraproject.org/wiki/Features/SELinuxSystemdAccessControl

Comment 5 Devon Smith 2015-08-16 18:45:09 UTC
This is also occurring in F23a. Manually calling the command works as well. The Selinux workaround generated in the alert message fixes the issue.

Comment 6 Robert Hancock 2015-08-17 15:39:55 UTC
Description of problem:
Just booted up the system

Version-Release number of selected component:
selinux-policy-3.13.1-128.8.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.1.5-200.fc22.x86_64
type:           libreport

Comment 7 Daniel Walsh 2015-08-18 13:26:54 UTC
Could you attach all AVC's. sys_ptrace capability is usually not needed.  It can be caused just by lookin in /proc.  Want to make sure that is the only breakage.

Comment 8 Mark Wielaard 2015-08-18 14:23:17 UTC
(In reply to Daniel Walsh from comment #7)
> Could you attach all AVC's.

There is only one:

$ sudo grep -i avc /var/log/audit/audit.log
type=AVC msg=audit(1439907280.909:528): avc:  denied  { sys_ptrace } for  pid=3407 comm="systemd-sysctl" capability=19  scontext=system_u:system_r:systemd_sysctl_t:s0 tcontext=system_u:system_r:systemd_sysctl_t:s0 tclass=capability permissive=0

Comment 9 Vladislav Grigoryev 2015-08-18 19:25:29 UTC
# rpm -q systemd elfutils-default-yama-scope; uname -r
systemd-219-21.fc22.x86_64
elfutils-default-yama-scope-0.163-3.fc22.noarch
4.1.4-200.fc22.x86_64

# systemctl restart systemd-sysctl.service
Job for systemd-sysctl.service failed. See "systemctl status systemd-sysctl.service" and "journalctl -xe" for details.

# journalctl --since "1m ago"
systemd[1]: Starting Apply Kernel Variables...
audit[4591]: <audit-1400> avc:  denied  { sys_ptrace } for  pid=4591 comm="systemd-sysctl" capability=19  scontext=system_u:system_r:systemd_sysctl_t:s0 tcontext=system_u:system_r:systemd_sysctl_t:s0 tclass=capability permissive=0
systemd-sysctl[4591]: Failed to write '0' to '/proc/sys/kernel/yama/ptrace_scope': Operation not permitted
systemd[1]: systemd-sysctl.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Failed to start Apply Kernel Variables.
systemd[1]: Unit systemd-sysctl.service entered failed state.
systemd[1]: systemd-sysctl.service failed.
audit[1]: <audit-1130> pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=systemd-sysctl comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
setroubleshoot[4528]: SELinux is preventing systemd-sysctl from using the sys_ptrace capability. For complete SELinux messages. run sealert -l 85f55b09-c67c-4a3e-beda-36b467349d1b

Comment 10 Strahil Nikolov 2015-08-20 08:21:22 UTC
Description of problem:
I noticed that kernel variables were not loaded during boot. I've checked "systemctl status systemd-sysctl" and it had failed.When I tried "systemctl start systemd-sysctl" an AVC denial warning showed up.

Version-Release number of selected component:
selinux-policy-3.13.1-128.10.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.1.5-200.fc22.x86_64
type:           libreport

Comment 11 Daniel Walsh 2015-08-20 23:25:21 UTC
Ok I guess we need to add it. Could you build a custom policy and see if this fixes the problem.


# ausearch -m avc -ts today | audit2allow -M mypol
# semodule -i mypol.pp

Comment 12 Mark Wielaard 2015-08-20 23:50:29 UTC
(In reply to Daniel Walsh from comment #11)
> Ok I guess we need to add it. Could you build a custom policy and see if
> this fixes the problem.
> 
> # ausearch -m avc -ts today | audit2allow -M mypol
> # semodule -i mypol.pp

Yes, that fixes the issue.

For the record the generated policy was:

#============= systemd_sysctl_t ==============
allow systemd_sysctl_t self:capability sys_ptrace;

Comment 13 poma 2015-08-22 10:21:08 UTC
*** Bug 1253969 has been marked as a duplicate of this bug. ***

Comment 14 Ting-Wei Lan 2015-08-23 04:05:54 UTC
Description of problem:
# systemctl start systemd-sysctl
Job for systemd-sysctl.service failed. See "systemctl status systemd-sysctl.service" and "journalctl -xe" for details.

Version-Release number of selected component:
selinux-policy-3.13.1-128.10.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.1.5-200.fc22.x86_64
type:           libreport

Comment 15 Heldwin 2015-08-23 13:09:48 UTC
Description of problem:
Started with kernel update 4.1.5

Version-Release number of selected component:
selinux-policy-3.13.1-128.10.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.1.6-200.fc22.x86_64
type:           libreport

Comment 16 Lukas Vrabec 2015-08-23 16:16:45 UTC
Dan, I agree.

Service with this rule started normally.

commit c2c8beb2ab81529612bafac5d4e65ecfbe70068d
Author: Lukas Vrabec <lvrabec>
Date:   Sun Aug 23 18:12:17 2015 +0200

    Allow systemd-sysctl cap. sys_ptrace  BZ(1253926)

Comment 17 Lukas Vrabec 2015-08-23 17:45:12 UTC
*** Bug 1255980 has been marked as a duplicate of this bug. ***

Comment 18 Fedora Update System 2015-08-24 11:45:55 UTC
selinux-policy-3.13.1-128.12.fc22 has been submitted as an update to Fedora 22. https://bugzilla.redhat.com/show_bug.cgi?id=1253926

Comment 19 Lukas Vrabec 2015-08-24 14:30:28 UTC
*** Bug 1256334 has been marked as a duplicate of this bug. ***

Comment 20 Göran Uddeborg 2015-08-24 16:55:06 UTC
The same problem appears in F23, selinux-policy-3.13.1-141.fc23.  Will that also get fixed as part of this, or do you want a separate Bugzilla about that?

Comment 21 Fedora Update System 2015-08-24 21:54:38 UTC
selinux-policy-3.13.1-128.12.fc22 has been pushed to the Fedora 22 testing repository. If problems still persist, please make note of it in this bug report.\nIf you want to test the update, you can install it with \n su -c 'yum --enablerepo=updates-testing update selinux-policy'. You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-14076

Comment 22 Lukas Vrabec 2015-08-25 08:24:51 UTC
Hi Göran,
This will be fixed in selinux-policy-3.13.1-144.fc23

Comment 23 Jeremy Christian 2015-08-25 14:36:58 UTC
Description of problem:
On a default Fedora 22 installation, I get an error on boot "Failed to start Apply Kernel Variables. See 'sysctl status systemd-sysctl.service' for details". 

When I tried manually starting the service with "systemctl start systemd-sysctl.service", the SELinux Troubleshooter app appeared saying the service did not have permissions for 'sys_ptrace' capability. I ran the recommended fix of "grep systemd-sysctl /var/log/audit/audit.log | audit2allow -M mypol && semodule -i mypol.pp" and was able to successfully start the service. I believe this permission should be part of the default SELinux policy.

Version-Release number of selected component:
selinux-policy-3.13.1-128.10.fc22.noarch

Additional info:
reporter:       libreport-2.6.2
hashmarkername: setroubleshoot
kernel:         4.1.3-201.fc22.x86_64
type:           libreport

Comment 24 Andrew 2015-08-25 14:42:45 UTC
Hi Lukas,
I am wondering if the update selinux-policy-3.13.1-144.fc23 will be made available for F22?

Comment 25 Devon Smith 2015-08-25 14:44:18 UTC
selinux-policy-3.13.1-128.12.fc22 has been released, once you get the update, it should fix the issue. You can also go here to download the RPM and install the update manually and give it a test or you can download it from the updates-testing repo. http://koji.fedoraproject.org/koji/buildinfo?buildID=679465

Comment 26 Andrew 2015-08-25 17:29:33 UTC
Since there is no update offered at this moment, I downloaded selinux-policy-3.13.1-128.12.fc22.noarch.rpm and updated from the RPM. Immediately got in trouble at the next boot: Failed to load SELinux policy, freezing. Maybe I was doing something wrong, but at this time it is a headache: after downgrading back to selinux-policy-3.13.1-128.10.fc22.noarch, only setting selinux=0 in the kernel allows to boot without problems.

Comment 27 Devon Smith 2015-08-25 17:39:23 UTC
That patch is for F22 (the fc22 in the rpm name denotes that, make sure that number matches the release you are using). Here is the policy for F23 http://koji.fedoraproject.org/koji/buildinfo?buildID=679463

Remove the f22 rpm and install this one

Comment 28 Andrew 2015-08-25 17:43:58 UTC
I am using F22 (not F23) as you can see from my comment above and below:

LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 22 (Twenty Two)
Release:	22
Codename:	TwentyTwo

Comment 29 Devon Smith 2015-08-25 17:54:14 UTC
Ah, sorry about that. I misread your first statement up there concerning the F23 update for F22. If you get a chance click on my username and send me an email, I will reach out and find some help with this.

Comment 30 Gerard Ryan 2015-08-25 18:16:45 UTC
@Andrew: If you just manually downloaded the rpm from koji, there might be other packages from that build that you have installed and would likely be expected to install alongside the selinux-policy one. I know on my system I also had selinux-policy-targeted, so I updated both of them at the same time. No idea if that could be related to your issue or not.

Comment 31 Andrew 2015-08-25 18:41:01 UTC
Thanks Gerard and Devon! 

After downloading and changing all 3 components that were installed on my system (not just one), I am all set now.

selinux-policy-devel-3.13.1-128.12.fc22.noarch
selinux-policy-targeted-3.13.1-128.12.fc22.noarch
selinux-policy-3.13.1-128.12.fc22.noarch

Comment 32 Heldwin 2015-08-25 21:02:45 UTC
Thanks, selinux-policy-3.13.1-128.12.fc22 fixes it for me too

Comment 33 Fedora Update System 2015-08-27 18:24:41 UTC
selinux-policy-3.13.1-128.12.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.


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