Bug 472766 - SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save (var_lib_t).
Summary: SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/sav...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 9
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 472762
TreeView+ depends on / blocked
 
Reported: 2008-11-24 14:16 UTC by Jonathan Underwood
Modified: 2009-06-10 08:14 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-06-10 08:14:27 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jonathan Underwood 2008-11-24 14:16:44 UTC
Description of problem:
Running /sbin/shorewall calls iptables in order to create an iptables save file of the current netfilter table in /var/lib/shorewall/save. SElinux policy currently stops this from happening as described in the AVC below. I'm not too sure what needs to be added to the SElinux policy to make it work?


Summary:

SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save
(var_lib_t).

Detailed Description:

SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save
(var_lib_t). The SELinux type var_lib_t, is a generic type for all files in the
directory and very few processes (SELinux Domains) are allowed to write to this
SELinux type. This type of denial usual indicates a mislabeled file. By default
a file created in a directory has the gets the context of the parent directory,
but SELinux policy has rules about the creation of directories, that say if a
process running in one SELinux Domain (D1) creates a file in a directory with a
particular SELinux File Context (F1) the file gets a different File Context
(F2). The policy usually allows the SELinux Domain (D1) the ability to write,
unlink, and append on (F2). But if for some reason a file
(/var/lib/shorewall/save) was created with the wrong context, this domain will
be denied. The usual solution to this problem is to reset the file context on
the target file, restorecon -v '/var/lib/shorewall/save'. If the file context
does not change from var_lib_t, then this is probably a bug in policy. Please
file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against
the selinux-policy package. If it does change, you can try your application
again to see if it works. The file context could have been mislabeled by editing
the file or moving the file from a different directory, if the file keeps
getting mislabeled, check the init scripts to see if they are doing something to
mislabel the file.

Allowing Access:

You can attempt to fix file context by executing restorecon -v
'/var/lib/shorewall/save'

Fix Command:

restorecon '/var/lib/shorewall/save'

Additional Information:

Source Context                unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c102
                              3
Target Context                unconfined_u:object_r:var_lib_t:s0
Target Objects                /var/lib/shorewall/save [ file ]
Source                        iptables
Source Path                   /sbin/iptables
Port                          <Unknown>
Host                          withnail.phys.ucl.ac.uk
Source RPM Packages           iptables-1.4.1.1-2.fc9
Target RPM Packages           
Policy RPM                    selinux-policy-3.3.1-107.fc9
Selinux Enabled               True
Policy Type                   targeted
MLS Enabled                   True
Enforcing Mode                Enforcing
Plugin Name                   mislabeled_file
Host Name                     withnail.phys.ucl.ac.uk
Platform                      Linux withnail.phys.ucl.ac.uk
                              2.6.27.5-41.fc9.x86_64 #1 SMP Thu Nov 13 20:29:07
                              EST 2008 x86_64 x86_64
Alert Count                   1
First Seen                    Mon 24 Nov 2008 02:05:29 PM GMT
Last Seen                     Mon 24 Nov 2008 02:05:29 PM GMT
Local ID                      71ba3b4a-d9cd-4ca3-80fa-2bfff6179ec5
Line Numbers                  

Raw Audit Messages            

host=withnail.phys.ucl.ac.uk type=AVC msg=audit(1227535529.897:450): avc:  denied  { write } for  pid=5208 comm="iptables" path="/var/lib/shorewall/save" dev=dm-0 ino=157464 scontext=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:var_lib_t:s0 tclass=file

host=withnail.phys.ucl.ac.uk type=SYSCALL msg=audit(1227535529.897:450): arch=c000003e syscall=59 success=yes exit=0 a0=16c8e50 a1=15c6950 a2=16d0150 a3=0 items=0 ppid=5196 pid=5208 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=56 comm="iptables" exe="/sbin/iptables" subj=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 key=(null)




Version-Release number of selected component (if applicable):
shorewall-4.0.14-2.fc9.noarch
shorewall-common-4.0.14-2.fc9.noarch
shorewall-lite-4.0.14-2.fc9.noarch
shorewall-shell-4.0.14-2.fc9.noarch
shorewall-perl-4.0.14-2.fc9.noarch

selinux-policy-targeted-3.3.1-107.fc9.noarch
libselinux-2.0.67-4.fc9.x86_64
libselinux-2.0.67-4.fc9.i386
selinux-policy-devel-3.3.1-107.fc9.noarch
libselinux-python-2.0.67-4.fc9.x86_64
selinux-policy-3.3.1-107.fc9.noarch


How reproducible:


Steps to Reproduce:
1./sbin/shorewall save
2.
3.
  

Additional info:

Note, if the fix is to add policy for /sbin/shorewall, then the same fix needs to be applied for /sbin/shorewall-lite as well.

Comment 1 Daniel Walsh 2008-11-24 14:44:10 UTC
Yes writing policy for shorewall would be preferable.

For not the easiest thing for you do do is setup labeling on this directory that allows iptables to write to the directory

# semanage fcontext -a -t iptables_var_run_t '/var/lib/shorewall(/.*)?'
# restorecon -R -v /var/lib/shorewall

Comment 2 Jonathan Underwood 2008-11-24 15:08:23 UTC
(In reply to comment #1)
> Yes writing policy for shorewall would be preferable.
> 

Should this be done in the selinux-policy package, or the shorewall package? I presume the former, otherwise I would be creating an SElinux policy module for iptables in the shorewall package, which seems a bit odd.

> For not the easiest thing for you do do is setup labeling on this directory
> that allows iptables to write to the directory
> 
> # semanage fcontext -a -t iptables_var_run_t '/var/lib/shorewall(/.*)?'
> # restorecon -R -v /var/lib/shorewall

ok, thanks.

Comment 3 Jonathan Underwood 2008-11-24 15:27:53 UTC
(In reply to comment #1)
> For not the easiest thing for you do do is setup labeling on this directory
> that allows iptables to write to the directory
> 
> # semanage fcontext -a -t iptables_var_run_t '/var/lib/shorewall(/.*)?'
> # restorecon -R -v /var/lib/shorewall

Actually, even after doing that I still get AVC denial on running /sbin/shorewall save as seen below.


Summary:

SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save
(var_lib_t).

Detailed Description:

SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save
(var_lib_t). The SELinux type var_lib_t, is a generic type for all files in the
directory and very few processes (SELinux Domains) are allowed to write to this
SELinux type. This type of denial usual indicates a mislabeled file. By default
a file created in a directory has the gets the context of the parent directory,
but SELinux policy has rules about the creation of directories, that say if a
process running in one SELinux Domain (D1) creates a file in a directory with a
particular SELinux File Context (F1) the file gets a different File Context
(F2). The policy usually allows the SELinux Domain (D1) the ability to write,
unlink, and append on (F2). But if for some reason a file
(/var/lib/shorewall/save) was created with the wrong context, this domain will
be denied. The usual solution to this problem is to reset the file context on
the target file, restorecon -v '/var/lib/shorewall/save'. If the file context
does not change from var_lib_t, then this is probably a bug in policy. Please
file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against
the selinux-policy package. If it does change, you can try your application
again to see if it works. The file context could have been mislabeled by editing
the file or moving the file from a different directory, if the file keeps
getting mislabeled, check the init scripts to see if they are doing something to
mislabel the file.

Allowing Access:

You can attempt to fix file context by executing restorecon -v
'/var/lib/shorewall/save'

Fix Command:

restorecon '/var/lib/shorewall/save'

Additional Information:

Source Context                unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c102
                              3
Target Context                unconfined_u:object_r:var_lib_t:s0
Target Objects                /var/lib/shorewall/save [ file ]
Source                        iptables
Source Path                   /sbin/iptables
Port                          <Unknown>
Host                          withnail.phys.ucl.ac.uk
Source RPM Packages           iptables-1.4.1.1-2.fc9
Target RPM Packages           
Policy RPM                    selinux-policy-3.3.1-107.fc9
Selinux Enabled               True
Policy Type                   targeted
MLS Enabled                   True
Enforcing Mode                Enforcing
Plugin Name                   mislabeled_file
Host Name                     withnail.phys.ucl.ac.uk
Platform                      Linux withnail.phys.ucl.ac.uk
                              2.6.27.5-41.fc9.x86_64 #1 SMP Thu Nov 13 20:29:07
                              EST 2008 x86_64 x86_64
Alert Count                   1
First Seen                    Mon 24 Nov 2008 02:05:29 PM GMT
Last Seen                     Mon 24 Nov 2008 02:05:29 PM GMT
Local ID                      71ba3b4a-d9cd-4ca3-80fa-2bfff6179ec5
Line Numbers                  

Raw Audit Messages            

host=withnail.phys.ucl.ac.uk type=AVC msg=audit(1227535529.897:450): avc:  denied  { write } for  pid=5208 comm="iptables" path="/var/lib/shorewall/save" dev=dm-0 ino=157464 scontext=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:var_lib_t:s0 tclass=file

host=withnail.phys.ucl.ac.uk type=SYSCALL msg=audit(1227535529.897:450): arch=c000003e syscall=59 success=yes exit=0 a0=16c8e50 a1=15c6950 a2=16d0150 a3=0 items=0 ppid=5196 pid=5208 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=56 comm="iptables" exe="/sbin/iptables" subj=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 key=(null)

Comment 4 Jonathan Underwood 2008-11-24 15:42:35 UTC
Oops, I pasted the wrong AVC in comment #3. On running

# semanage fcontext -a -t iptables_var_run_t '/var/lib/shorewall(/.*)?'
# restorecon -R -v /var/lib/shorewall

and then doing /sbin/shorewall save I get:


Summary:

SELinux is preventing iptables (iptables_t) "write" to /var/lib/shorewall/save
(iptables_var_run_t).

Detailed Description:

SELinux denied access requested by iptables. It is not expected that this access
is required by iptables and this access may signal an intrusion attempt. It is
also possible that the specific version or configuration of the application is
causing it to require additional access.

Allowing Access:

Sometimes labeling problems can cause SELinux denials. You could try to restore
the default system file context for /var/lib/shorewall/save,

restorecon -v '/var/lib/shorewall/save'

If this does not work, there is currently no automatic way to allow this access.
Instead, you can generate a local policy module to allow this access - see FAQ
(http://fedora.redhat.com/docs/selinux-faq-fc5/#id2961385) Or you can disable
SELinux protection altogether. Disabling SELinux protection is not recommended.
Please file a bug report (http://bugzilla.redhat.com/bugzilla/enter_bug.cgi)
against this package.

Additional Information:

Source Context                unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c102
                              3
Target Context                system_u:object_r:iptables_var_run_t:s0
Target Objects                /var/lib/shorewall/save [ file ]
Source                        iptables
Source Path                   /sbin/iptables
Port                          <Unknown>
Host                          withnail.phys.ucl.ac.uk
Source RPM Packages           iptables-1.4.1.1-2.fc9
Target RPM Packages           
Policy RPM                    selinux-policy-3.3.1-107.fc9
Selinux Enabled               True
Policy Type                   targeted
MLS Enabled                   True
Enforcing Mode                Enforcing
Plugin Name                   catchall_file
Host Name                     withnail.phys.ucl.ac.uk
Platform                      Linux withnail.phys.ucl.ac.uk
                              2.6.27.5-41.fc9.x86_64 #1 SMP Thu Nov 13 20:29:07
                              EST 2008 x86_64 x86_64
Alert Count                   1
First Seen                    Mon 24 Nov 2008 03:25:49 PM GMT
Last Seen                     Mon 24 Nov 2008 03:25:49 PM GMT
Local ID                      5dd500f8-ce7e-46dc-958a-355279ccde15
Line Numbers                  

Raw Audit Messages            

host=withnail.phys.ucl.ac.uk type=AVC msg=audit(1227540349.434:474): avc:  denied  { write } for  pid=6831 comm="iptables" path="/var/lib/shorewall/save" dev=dm-0 ino=157464 scontext=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 tcontext=system_u:object_r:iptables_var_run_t:s0 tclass=file

host=withnail.phys.ucl.ac.uk type=SYSCALL msg=audit(1227540349.434:474): arch=c000003e syscall=59 success=yes exit=0 a0=1b1be50 a1=1a19950 a2=1b23150 a3=0 items=0 ppid=6819 pid=6831 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=56 comm="iptables" exe="/sbin/iptables" subj=unconfined_u:unconfined_r:iptables_t:s0-s0:c0.c1023 key=(null)

Comment 5 Daniel Walsh 2008-11-24 19:45:02 UTC
Well that is a bug.

You can add these rules for now using

# grep avc /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Fixed iptables being able to write iptables_var_run_t selinux-policy-3.3.1-114.fc9

Comment 6 Bug Zapper 2009-06-10 03:21:29 UTC
This message is a reminder that Fedora 9 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 9.  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 WONTFIX if it remains open with a Fedora 
'version' of '9'.

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 prior to Fedora 9's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 9 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 please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

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.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping


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