Bug 1733542 - Incorrect context applied to /etc/sysconfig/iptables.save
Summary: Incorrect context applied to /etc/sysconfig/iptables.save
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy-targeted
Version: 31
Hardware: All
OS: Unspecified
Target Milestone: ---
Assignee: Lukas Vrabec
QA Contact: Ben Levenson
Depends On:
Blocks: 1776873
TreeView+ depends on / blocked
Reported: 2019-07-26 13:13 UTC by Kristofer Rye
Modified: 2020-03-27 09:17 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1776873 (view as bug list)
Last Closed: 2020-03-27 09:17:09 UTC
Type: Bug
fperalta: rhel-rawhide?

Attachments (Terms of Use)

Description Kristofer Rye 2019-07-26 13:13:12 UTC
Description of problem:

The provided copy of /etc/selinux/targeted/contexts/files/file_contexts gives conflicting contexts for the /etc/sysconfig/iptables and /etc/sysconfig/iptables.save files.

The iptables and iptables-services packages include a script (/usr/libexec/iptables/iptables.init) that, when configured to "save" before exiting, will first iptables-save into a temporary file created via mktemp, and upon success will _copy_ the file /etc/sysconfig/iptables into /etc/sysconfig/iptables.save.  However, because the selinux policy provided by this component for these files differs, the copy fails.  Subsequently, the return status is checked, and only if the copy was successful is the temporary file moved to overwrite /etc/sysconfig/iptables.

In short, the "save before exiting" feature is broken by the SELinux policy.

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

$ rpm -qa | grep selinux-policy-targeted

How reproducible:

Simply need a system with selinux-policy-targeted as well as the iptables-services package.

Steps to Reproduce:
1. Ensure that selinux is set to enforce.
2. Install the iptables and iptables-services packages.
3. In /etc/sysconfig/iptables-config, set IPTABLES_SAVE_ON_STOP and IPTABLES_SAVE_ON_RESTART to "yes".
4. Stop and start iptables.service a few times, and check "journalctl -u iptables" for an error like this:

     iptables: Saving firewall rules to /etc/sysconfig/iptables: chmod: changing permissions of '/etc/sysconfig/iptables.save': Permission denied

5. Temporarily suspend selinux's enforcement and try restarting iptables again.
6. Observe that the iptables-save succeeds without error.

Actual results:

With the IPTABLES_SAVE_{ON_STOP,ON_RESTART} variables set to "yes", /usr/libexec/iptables/iptables.init attempts to copy the file /etc/sysconfig/iptables (with security context system_u:object_r:system_conf_t:s0) to /etc/sysconfig/iptables.save. (with security context system_u:object_r:etc_runtime_t:s0)  This results in an error.

In other words, /etc/sysconfig/iptables and /etc/sysconfig/iptables.save should have the same selinux contexts, but they do not:

$ ls -lahZ /etc/sysconfig/iptables{,.save}
-rw-------. 1 root root system_u:object_r:system_conf_t:s0 16K Jan 01 13:37 /etc/sysconfig/iptables
-rw-r--r--. 1 root root system_u:object_r:etc_runtime_t:s0 16K Jan 02 13:03 /etc/sysconfig/iptables.save

Expected results:

The selinux policy permits the copy that /usr/libexec/iptables/iptables.init performs by applying the same context to all of the /etc/sysconfig/ip6?tables{,.save} files.

Additional info:

I noticed that file_contexts includes two different entries that are the source of the disparate policies:

$ cat /etc/selinux/targeted/contexts/files/file_contexts | grep '/etc/sysconfig/ip.*tables.*'
/etc/sysconfig/ip6?tables.*	--	system_u:object_r:system_conf_t:s0
/etc/sysconfig/iptables\.save	--	system_u:object_r:etc_runtime_t:s0

Couldn't one just remove the latter? I.e. remove the line:

    /etc/sysconfig/iptables\.save	--	system_u:object_r:etc_runtime_t:s0

from the policy?  I also note that there is an ip6tables.save counterpart to this file which is not mentioned here.

Comment 1 Lukas Vrabec 2019-07-29 12:20:55 UTC
commit fdd7a9170b6bfd535d6abab639e94c66a0035161 (HEAD -> rawhide)
Author: Lukas Vrabec <lvrabec>
Date:   Mon Jul 29 14:18:54 2019 +0200

    Label /etc/sysconfig/ip6?tables\.save as system_conf_t
    Resolves: rhbz#1733542

This change could be risky, so pushing the fix only to the rawhide.

Comment 2 Ben Cotton 2019-08-13 16:59:38 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 3 Ben Cotton 2019-08-13 18:53:15 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Comment 4 Fedora Update System 2019-10-04 13:35:17 UTC
FEDORA-2019-64732fd6a5 has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2019-64732fd6a5

Comment 5 Fedora Update System 2019-10-04 22:51:01 UTC
selinux-policy-3.14.4-36.fc31 has been pushed to the Fedora 31 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-64732fd6a5

Comment 12 Lukas Vrabec 2019-11-04 08:55:01 UTC
Hi All, 

Issue fixed in the latest version of selinux-policy rpm package: 

# matchpathcon /etc/sysconfig/iptables
/etc/sysconfig/iptables	system_u:object_r:system_conf_t:s0

# matchpathcon /etc/sysconfig/iptables.save
/etc/sysconfig/iptables.save	system_u:object_r:system_conf_t:s0

# matchpathcon /etc/sysconfig/ip6tables.save
/etc/sysconfig/ip6tables.save	system_u:object_r:system_conf_t:s0

# matchpathcon /etc/sysconfig/ip6tables
/etc/sysconfig/ip6tables	system_u:object_r:system_conf_t:s0

# rpm -q selinux-policy


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