Description of problem: I have uncommented the line "IPTABLES = /sbin/iptables" in /etc/denyhosts.conf and this happens sometimes (probably when denyhosts detects an attack). There are two alerts, one about "execute" and another for "getattr" permission. Source RPM should probably be denyhosts-2.9-4.fc21.noarch, not bash. SELinux is preventing /usr/bin/bash from 'execute' accesses on the file /usr/sbin/xtables-multi. ***** Plugin catchall (100. confidence) suggests ************************** If aby bash powinno mieć domyślnie execute dostęp do xtables-multi file. Then proszę to zgłosić jako błąd. Można utworzyć lokalny moduł polityki, aby umożliwić ten dostęp. Do można tymczasowo zezwolić na ten dostęp wykonując polecenia: # grep sh /var/log/audit/audit.log | audit2allow -M mojapolityka # semodule -i mojapolityka.pp Additional Information: Source Context system_u:system_r:denyhosts_t:s0 Target Context system_u:object_r:iptables_exec_t:s0 Target Objects /usr/sbin/xtables-multi [ file ] Source sh Source Path /usr/bin/bash Port <Unknown> Host (removed) Source RPM Packages bash-4.3.33-1.fc21.x86_64 Target RPM Packages iptables-1.4.21-13.fc21.x86_64 Policy RPM selinux-policy-3.13.1-105.3.fc21.noarch Selinux Enabled True Policy Type targeted Enforcing Mode Enforcing Host Name (removed) Platform Linux (removed) 3.18.7-200.fc21.x86_64 #1 SMP Wed Feb 11 21:53:17 UTC 2015 x86_64 x86_64 Alert Count 1 First Seen 2015-02-28 21:14:46 CET Last Seen 2015-02-28 21:14:46 CET Local ID 18960692-fb85-4c4f-bd84-f8979367dbcf Raw Audit Messages type=AVC msg=audit(1425154486.859:408665): avc: denied { execute } for pid=3276 comm="sh" name="xtables-multi" dev="md127" ino=20448678 scontext=system_u:system_r:denyhosts_t:s0 tcontext=system_u:object_r:iptables_exec_t:s0 tclass=file permissive=0 type=SYSCALL msg=audit(1425154486.859:408665): arch=x86_64 syscall=execve success=no exit=EACCES a0=1155ed0 a1=1155fb0 a2=1154b20 a3=51 items=0 ppid=989 pid=3276 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=sh exe=/usr/bin/bash subj=system_u:system_r:denyhosts_t:s0 key=(null) Hash: sh,denyhosts_t,iptables_exec_t,file,execute Version-Release number of selected component: selinux-policy-3.13.1-105.3.fc21.noarch Additional info: reporter: libreport-2.3.0 hashmarkername: setroubleshoot kernel: 3.18.7-200.fc21.x86_64 type: libreport
commit 50934a243e4986c2d7f31dc85b24ae73d4e94db0 Author: Lukas Vrabec <lvrabec> Date: Sun Mar 1 13:08:42 2015 +0100 Allow denyhosts execute iptables. BZ(1197371)
selinux-policy-3.13.1-105.6.fc21 has been submitted as an update for Fedora 21. https://admin.fedoraproject.org/updates/selinux-policy-3.13.1-105.6.fc21
Package selinux-policy-3.13.1-105.6.fc21: * should fix your issue, * was pushed to the Fedora 21 testing repository, * should be available at your local mirror within two days. Update it with: # su -c 'yum update --enablerepo=updates-testing selinux-policy-3.13.1-105.6.fc21' as soon as you are able to. Please go to the following url: https://admin.fedoraproject.org/updates/FEDORA-2015-3476/selinux-policy-3.13.1-105.6.fc21 then log in and leave karma (feedback).
Looks like it helped with the main problem (I'm getting new entries in iptables now), but there's a new alert with several audit messages. I don't get why iptables would want to write to denyhosts' files but there you go: SELinux is preventing /usr/sbin/xtables-multi from 'write' accesses on the file /run/lock/subsys/denyhosts. Additional Information: Source Context system_u:system_r:iptables_t:s0 Target Context system_u:object_r:denyhosts_var_lock_t:s0 Target Objects /run/lock/subsys/denyhosts [ file ] Source iptables Source Path /usr/sbin/xtables-multi Port <Unknown> Host (removed) Source RPM Packages iptables-1.4.21-13.fc21.x86_64 Target RPM Packages Policy RPM selinux-policy-3.13.1-105.6.fc21.noarch Selinux Enabled True Policy Type targeted Enforcing Mode Enforcing Host Name (removed) Platform Linux (removed) 3.18.8-201.fc21.x86_64 #1 SMP Fri Feb 27 18:18:27 UTC 2015 x86_64 x86_64 Alert Count 1 First Seen 2015-03-10 14:00:56 CET Last Seen 2015-03-10 14:00:56 CET Local ID 2b946b32-cbff-4359-b926-4e89128d0709 Raw Audit Messages type=AVC msg=audit(1425992456.826:3216): avc: denied { write } for pid=9310 comm="iptables" path="/run/lock/subsys/denyhosts" dev="tmpfs" ino=18514 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:object_r:denyhosts_var_lock_t:s0 tclass=file permissive=0 type=AVC msg=audit(1425992456.826:3216): avc: denied { append } for pid=9310 comm="iptables" path="/etc/hosts.deny" dev="md127" ino=27788257 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:object_r:net_conf_t:s0 tclass=file permissive=0 type=SYSCALL msg=audit(1425992456.826:3216): arch=x86_64 syscall=execve success=yes exit=0 a0=a9ced0 a1=a9cfb0 a2=a9bb20 a3=51 items=0 ppid=780 pid=9310 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=iptables exe=/usr/sbin/xtables-multi subj=system_u:system_r:iptables_t:s0 key=(null) Hash: iptables,iptables_t,denyhosts_var_lock_t,file,write
Is this expected behavior?
No, iptables itself does not contain any code that touches /run/lock/subsys/denyhosts. There is a Python daemon, that seems to use it: /usr/bin/denyhosts.py from the denyhosts package. It seems that denyhosts is passing an open file descriptor to iptables by using os.system calls. Reassigning to denyhosts.
This is a leak from denyhosts or fail2ban, and should probably just be dontaudited.
Denyhosts (the newer versions) will shell out to iptables. I have an open ticket for allowing this access but (sadly) I haven't provided the necessary AVCs yet because I'm working on some other part of denyhosts at the moment. (Reading from the journal, if anyone cares.) Now, I'd like to fix this properly. Can anyone give me a hint as to how I'd prevent denyhosts from leaking open FDs to iptables? Will the current policy even allow denyhosts to shell out to iptables at all?
With using os.open you could also set os.O_CLOEXEC. With open you have to do it by hand with a fcntl call, that sets FD_CLOEXEC: fcntl.fcntl(fd, fcntl.F_SETFD, fcntl.FD_CLOEXEC) Or you can use a more secure way than os.system to run processes, like for example something like the runProg code in firewalld.
Thanks for that; I may lift runProg since it's license-compatible, or just use Popen with close_fds=True.
runProg does not do the trick alone - the "Or" above should have been "And". But Popen with close_fds does the trick.
selinux-policy-3.13.1-105.6.fc21 has been pushed to the Fedora 21 stable repository. If problems still persist, please make note of it in this bug report.
So what happened here? The AVCs were marked dontaudit? If so, that's unfortunate; we should fix bugs in the programs instead of hiding them under more dontaudit rules, as dontaudit rules are simply horrible for discovery and far too often something important is silently denied because of them. I'm fixing denyhosts so this won't be an issue. I don't know if any other code is triggering this (fail2ban, maybe) but it should be properly fixed as well.
Guess the problem I've reported originally was fixed (denyhosts can run iptables now and it works - I see drop rules in iptables -L for each host it adds to hosts.deny which doesn't apply for sshd). Now I get alerts about the leaked file descriptors but for that we can open a new bug, or at least update the title of this one.
OK, so what is state of this issue? SELinux issue is fixed, right? If yes, I suggest close this and open new bug with leaked fd.
I believe this bug is opened correctly. denyhosts needs to fix leaked file descriptors and we can remove dontaudit rules which have been added.
This message is a reminder that Fedora 21 is nearing its end of life. Approximately 4 (four) weeks from now Fedora will stop maintaining and issuing updates for Fedora 21. 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 '21'. 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 21 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.
Fedora 21 changed to end-of-life (EOL) status on 2015-12-01. Fedora 21 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.
I'm sorry to post to this relatively "ancient" bug, however, this doesn't seem to have been addressed at all. For example, there are a number of more recent bugs, e.g. Bug 1259178 . This behaviour is also observed on a RHEL7.3 system with `denyhosts-2.9-4.el7.noarch`, `selinux-policy-3.13.1-102.el7_3.4.noarch`, and `policycoreutils-2.5-8.el7.x86_64`. Where would the bugs for packages from EPEL, such as denyhosts, be reported/tracked? Is this bug tracked/relevant to bugzilla.redhat.com? The previous comments here seemed promising, though, it's strange that this is still unresolved years later.
It's unresolved because it's rather bizarre and not something I can personally repeat. EPEL bugs are tracked in this bugzilla just as Fedora bugs are.
All right, let's see if I can help you reproduce it, then. The following shows the configuration file for denyhosts. Can you match that and try to repeat it with an SELinux "targeted" policy in place? sed -n '/^[a-zA-Z]/p' /etc/denyhosts.conf SECURE_LOG = /var/log/secure HOSTS_DENY = /etc/hosts.deny PURGE_DENY = 4w BLOCK_SERVICE = sshd DENY_THRESHOLD_INVALID = 4 DENY_THRESHOLD_VALID = 8 DENY_THRESHOLD_ROOT = 1 DENY_THRESHOLD_RESTRICTED = 1 WORK_DIR = /var/lib/denyhosts ETC_DIR = /etc SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES HOSTNAME_LOOKUP=NO LOCK_FILE = /var/lock/subsys/denyhosts IPTABLES = /sbin/iptables ADMIN_EMAIL = root@localhost SMTP_HOST = localhost SMTP_PORT = 25 SMTP_FROM = DenyHosts <nobody@localhost> SMTP_SUBJECT = DenyHosts Report from $[HOSTNAME] ALLOWED_HOSTS_HOSTNAME_LOOKUP=NO AGE_RESET_VALID=8d AGE_RESET_ROOT=35d AGE_RESET_RESTRICTED=35d AGE_RESET_INVALID=15d RESET_ON_SUCCESS = yes DAEMON_LOG = /var/log/denyhosts DAEMON_SLEEP = 30s DAEMON_PURGE = 1h SYNC_UPLOAD = no SYNC_DOWNLOAD = yes
Here's an example sealert denial message: SELinux is preventing /usr/sbin/xtables-multi from write access on the file /run/lock/subsys/denyhosts. ***** Plugin leaks (86.2 confidence) suggests ***************************** If you want to ignore xtables-multi trying to write access the denyhosts file, because you believe it should not need this access. Then you should report this as a bug. You can generate a local policy module to dontaudit this access. Do # ausearch -x /usr/sbin/xtables-multi --raw | audit2allow -D -M my-iptables # semodule -i my-iptables.pp ***** Plugin catchall (14.7 confidence) suggests ************************** If you believe that xtables-multi should be allowed write access on the denyhosts file 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: # ausearch -c 'iptables' --raw | audit2allow -M my-iptables # semodule -i my-iptables.pp Additional Information: Source Context system_u:system_r:iptables_t:s0 Target Context system_u:object_r:denyhosts_var_lock_t:s0 Target Objects /run/lock/subsys/denyhosts [ file ] Source iptables Source Path /usr/sbin/xtables-multi Port <Unknown> Host hostname Source RPM Packages iptables-1.4.21-17.el7.x86_64 Target RPM Packages Policy RPM selinux-policy-3.13.1-102.el7_3.4.noarch Selinux Enabled True Policy Type targeted Enforcing Mode Enforcing Host Name hostname Platform Linux hostname 3.10.0-514.el7.x86_64 #1 SMP Wed Oct 19 11:24:13 EDT 2016 x86_64 x86_64 Alert Count 2 First Seen 2016-11-03 14:36:00 CDT Last Seen 2016-11-03 20:58:46 CDT Local ID a52db65d-1d78-4910-aa97-0de9d3a8744f Raw Audit Messages type=AVC msg=audit(1478224726.951:8128): avc: denied { write } for pid=26043 comm="iptables" path="/run/lock/subsys/denyhosts" dev="tmpfs" ino=20416 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:object_r:denyhosts_var_lock_t:s0 tclass=file type=AVC msg=audit(1478224726.951:8128): avc: denied { append } for pid=26043 comm="iptables" path="/etc/hosts.deny" dev="dm-1" ino=134438954 scontext=system_u:system_r:iptables_t:s0 tcontext=system_u:object_r:net_conf_t:s0 tclass=file type=SYSCALL msg=audit(1478224726.951:8128): arch=x86_64 syscall=execve success=yes exit=0 a0=16fc030 a1=16fc110 a2=16fac30 a3=7ffcc5863890 items=2 ppid=1159 pid=26043 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=iptables exe=/usr/sbin/xtables-multi subj=system_u:system_r:iptables_t:s0 key=(null) type=CWD msg=audit(1478224726.951:8128): cwd=/ type=PATH msg=audit(1478224726.951:8128): item=0 name=/sbin/iptables inode=201742887 dev=fd:01 mode=0100755 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:iptables_exec_t:s0 objtype=NORMAL type=PATH msg=audit(1478224726.951:8128): item=1 name=/lib64/ld-linux-x86-64.so.2 inode=201329202 dev=fd:01 mode=0100755 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:ld_so_t:s0 objtype=NORMAL Hash: iptables,iptables_t,denyhosts_var_lock_t,file,write