Bug 1250842

Summary: firewall-cmd broken with setenforce 1
Product: [Fedora] Fedora Reporter: Marius Vollmer <mvollmer>
Component: selinux-policy-targetedAssignee: Miroslav Grepl <mgrepl>
Status: CLOSED EOL QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 27CC: alessandro.suardi, alexey.brodkin, andreas, aspurrie, benl, dwalsh, frederic.gai, jpopelka, strasharo2000, twoerner
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1304721 (view as bug list) Environment:
Last Closed: 2018-11-30 21:49:08 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:
Embargoed:
Bug Depends On:    
Bug Blocks: 1304721, 1332122    

Description Marius Vollmer 2015-08-06 06:51:40 UTC
Description of problem:

Running firewall.cmd to change the permanent config fails like this with setenforce 1:

# firewall-cmd --add-port 1234/tcp --permanent
Error: Backup of '/etc/firewalld/zones/public.xml' failed: [Errno 13] Permission denied: '/etc/firewalld/zones/public.xml.old'

It succeeds with setenforce 0.

Version-Release number of selected component (if applicable):

firewalld-0.3.14.2-4.fc23.noarch

Comment 1 Marius Vollmer 2015-08-06 07:03:34 UTC
Ahh, selinux version:

selinux-policy-targeted-3.13.1-138.fc23.noarch

Comment 2 Alessandro Suardi 2015-11-13 13:35:22 UTC
Just updated to F23, same issue:

[root@torrent ~]# firewall-cmd --runtime-to-permanent
Error: RT_TO_PERM_FAILED: zone 'public' : org.fedoraproject.FirewallD1.Exception: Backup of '/etc/firewalld/zones/public.xml' failed: [Errno 13] Permission denied: '/etc/firewalld/zones/public.xml.old'
[root@torrent ~]# rpm -q firewalld
firewalld-0.3.14.2-4.fc23.noarch
[root@torrent ~]# rpm -q selinux-policy-targeted
selinux-policy-targeted-3.13.1-152.fc23.noarch
[root@torrent ~]# setenforce 0
[root@torrent ~]# firewall-cmd --runtime-to-permanent
success

Comment 3 Alessandro Suardi 2015-11-13 13:42:35 UTC
[root@torrent audit]# grep firewalld audit.log|grep AVC | audit2why
type=AVC msg=audit(1447421196.268:487): avc:  denied  { relabelfrom } for  pid=812 comm="firewalld" name="public.xml.old" dev="dm-1" ino=395314 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0

	Was caused by:

#Constraint rule:

#	constrain file { create relabelfrom relabelto } ((u1 == u2 -Fail-)  or (t1 == can_change_object_identity -Fail-) ); Constraint DENIED

#	Possible cause is the source user (system_u) and target user (unconfined_u) are different.

Comment 4 Alessandro Suardi 2015-11-30 10:58:01 UTC
Good news - Firewall-cmd --permanent has started working for me even with setenforce 1 in recent FC23 updates...

I'm not setting this to CLOSED RESOLVED because I'm not the original bug filer and can't verify the issue on the machine it was originally reported on.

Comment 5 strasharo2000 2015-12-20 22:25:45 UTC
Same error here on up to date F23:

[root@T14 ~] # firewall-cmd --runtime-to-permanent
Error: RT_TO_PERM_FAILED: zone 'public' : org.fedoraproject.FirewallD1.Exception: Backup of '/etc/firewalld/zones/public.xml' failed: [Errno 13] Permission denied: '/etc/firewalld/zones/public.xml.old'
[root@T14 ~] # lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 23 (Twenty Three)
Release:	23
Codename:	TwentyThree
[root@T14 ~] # 


[root@T14 ~] # grep firewalld /var/log/audit/audit.log  | grep AVC
type=AVC msg=audit(1450649588.201:1178): avc:  denied  { relabelfrom } for  pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
type=AVC msg=audit(1450649602.675:1179): avc:  denied  { relabelfrom } for  pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
type=AVC msg=audit(1450649690.120:1183): avc:  denied  { relabelfrom } for  pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
type=AVC msg=audit(1450649722.071:1184): avc:  denied  { relabelfrom } for  pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
type=AVC msg=audit(1450649843.488:1192): avc:  denied  { relabelfrom } for  pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
[root@T14 ~] #

Comment 6 Thomas Woerner 2016-01-25 16:38:12 UTC
(In reply to strasharo2000 from comment #5)
> Same error here on up to date F23:
> 
> [root@T14 ~] # firewall-cmd --runtime-to-permanent
> Error: RT_TO_PERM_FAILED: zone 'public' :
> org.fedoraproject.FirewallD1.Exception: Backup of
> '/etc/firewalld/zones/public.xml' failed: [Errno 13] Permission denied:
> '/etc/firewalld/zones/public.xml.old'
> [root@T14 ~] # lsb_release -a
> LSB Version:
> :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-
> amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.
> 1-amd64:printing-4.1-noarch
> Distributor ID:	Fedora
> Description:	Fedora release 23 (Twenty Three)
> Release:	23
> Codename:	TwentyThree
> [root@T14 ~] # 
> 
> 
> [root@T14 ~] # grep firewalld /var/log/audit/audit.log  | grep AVC
> type=AVC msg=audit(1450649588.201:1178): avc:  denied  { relabelfrom } for 
> pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085
> scontext=system_u:system_r:firewalld_t:s0
> tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
> type=AVC msg=audit(1450649602.675:1179): avc:  denied  { relabelfrom } for 
> pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085
> scontext=system_u:system_r:firewalld_t:s0
> tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
> type=AVC msg=audit(1450649690.120:1183): avc:  denied  { relabelfrom } for 
> pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085
> scontext=system_u:system_r:firewalld_t:s0
> tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
> type=AVC msg=audit(1450649722.071:1184): avc:  denied  { relabelfrom } for 
> pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085
> scontext=system_u:system_r:firewalld_t:s0
> tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
> type=AVC msg=audit(1450649843.488:1192): avc:  denied  { relabelfrom } for 
> pid=2492 comm="firewalld" name="public.xml.old" dev="dm-1" ino=2365085
> scontext=system_u:system_r:firewalld_t:s0
> tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
> [root@T14 ~] #

Please add the output of "restorecon -rv /etc/firewalld"

Comment 7 strasharo2000 2016-01-27 07:37:23 UTC
[root@T14 ~] # restorecon -rv /etc/firewalld
[root@T14 ~] #

Comment 8 Thomas Woerner 2016-02-03 15:23:41 UTC
I also managed to run into this now. The backup files are not correctly labeled.

Assingning to selinux-policy-targetd-

Comment 9 Thomas Woerner 2016-02-04 12:57:59 UTC
This happens if the root user was running firewalld directly or if the user root copied a file into the firewalld configuration directory.

firewalld will create a backup of the old file by renaming it to <filename>.old

Here are steps to reproduce:
1) cp /usr/lib/firewalld/zones/public.xml /etc/firewalld/zones/foobar.xml
2) After 5 seconds when firewalld picked it up, do a change with firewalld: 
   firewall-cmd --permanent --zone=foobar --add-service=samba

Error: Backup of '/etc/firewalld/zones/foobar.xml' failed: [Errno 13] Permission denied: '/etc/firewalld/zones/foobar.xml.old'

# ls -Z /etc/firewalld/zones/foobar.xml*
unconfined_u:object_r:firewalld_etc_rw_t:s0 /etc/firewalld/zones/foobar.xml
    system_u:object_r:firewalld_etc_rw_t:s0 /etc/firewalld/zones/foobar.xml.old

Comment 10 strasharo2000 2016-02-06 15:46:37 UTC
[root@T14 zones] # ls -lZ
total 24
-rw-r--r--. 1 root root system_u:object_r:firewalld_etc_rw_t:s0     315 Dec 21 00:17 FedoraServer.xml
-rw-r--r--. 1 root root system_u:object_r:firewalld_etc_rw_t:s0     525 Dec 21 00:17 FedoraWorkstation.xml
-rw-r--r--. 1 root root system_u:object_r:firewalld_etc_rw_t:s0     369 Dec 21 00:17 home.xml
-rw-r--r--. 1 root root system_u:object_r:firewalld_etc_rw_t:s0     384 Dec 21 00:17 internal.xml
-rw-rw-r--. 1 root root system_u:object_r:firewalld_etc_rw_t:s0     340 Feb 15  2015 public.xml
-rw-rw-r--. 1 root root unconfined_u:object_r:firewalld_etc_rw_t:s0 340 Feb 15  2015 public.xml.old
[root@T14 zones] #

Comment 11 fredg_@_bdx 2016-03-09 05:47:33 UTC
Same error here on up to date F23, with firewall-config

Comment 12 Andrew Spurrier 2016-03-21 04:35:11 UTC
I ran into this today.  As per above the context is wrong on the public.xml file so I copied the context from one of the other correct xml files:

# chcon --reference=/etc/firewalld/zones/internal.xml /etc/firewalld/zones/public.xml
# firewall-cmd --runtime-to-permanent

All works and I did not have to drop SELinux Enforcing.
There is something wrong in the policy since the following does not correct the issue:
# restorecon -Rv /etc/firewalld/zones

Comment 13 Fedora End Of Life 2016-11-24 12:16:10 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 14 Fedora End Of Life 2016-12-20 14:20:38 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.

Comment 15 Andreas Thienemann 2017-09-05 19:45:55 UTC
Bug still exists with F26:

[root@index01 ~]# firewall-cmd --set-log-denied off
Error: Backup of '/etc/firewalld/firewalld.conf' failed: [Errno 13] Permission denied: '/etc/firewalld/firewalld.conf.old'
[root@index01 ~]#

[root@index01 ~]# ausearch -m avc -ts recent
----
time->Tue Sep  5 21:41:00 2017
type=AVC msg=audit(1504640460.494:11400): avc:  denied  { relabelto } for  pid=26293 comm="firewalld" name="firewalld.conf.old" dev="xvda3" ino=201898453 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0
[root@index01 ~]#

[root@index01 ~]# ausearch -m avc -ts recent | audit2why
type=AVC msg=audit(1504640460.494:11400): avc:  denied  { relabelto } for  pid=26293 comm="firewalld" name="firewalld.conf.old" dev="xvda3" ino=201898453 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0

	Was caused by:

#Constraint rule:

#	constrain file { create relabelfrom relabelto } ((u1 == u2 -Fail-)  or (t1 == can_change_object_identity -Fail-) ); Constraint DENIED

#	Possible cause is the source user (system_u) and target user (unconfined_u) are different.

type=AVC msg=audit(1504640517.161:11401): avc:  denied  { relabelto } for  pid=26293 comm="firewalld" name="firewalld.conf.old" dev="xvda3" ino=201898453 scontext=system_u:system_r:firewalld_t:s0 tcontext=unconfined_u:object_r:firewalld_etc_rw_t:s0 tclass=file permissive=0

	Was caused by:

#Constraint rule:

#	constrain file { create relabelfrom relabelto } ((u1 == u2 -Fail-)  or (t1 == can_change_object_identity -Fail-) ); Constraint DENIED

#	Possible cause is the source user (system_u) and target user (unconfined_u) are different.

[root@index01 ~]#

Comment 16 Jan Kurik 2018-05-31 09:08:23 UTC
This bug is currently reported against a Fedora version which is already unsuported.
I am changing the version to '27', the latest supported release.

Please check whether this bug is still an issue on the '27' release.
If you find this bug not being applicable on this release, please close it.

Comment 17 Ben Cotton 2018-11-27 15:21:10 UTC
This message is a reminder that Fedora 27 is nearing its end of life.
On 2018-Nov-30  Fedora will stop maintaining and issuing updates for
Fedora 27. 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 '27'.

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 27 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 18 Ben Cotton 2018-11-30 21:49:08 UTC
Fedora 27 changed to end-of-life (EOL) status on 2018-11-30. Fedora 27 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.