2008-10-26 18:43:44

by konrad.azzopardi

[permalink] [raw]
Subject: [refpolicy] Help with policy writing

Dear all,

To gain an understanding of SELinux I am trying to write a policy in
Fedora 9 and try to understand as I go along. I need to write a policy
for "samhain" , an integrity checker. I looked for tripwire refpolicy
to get some inspiration. {attached pls find policy files that I wrote}

I ran in permissive mode and although I am getting a lot of errors,
what is worrying me is the first error I am getting {see below}, am I
missing some trivial definition ? samhain is pretty standard, an init
file, a config file, a pid file, and library files.

Thanks


Summary:

SELinux is preventing samhain (samhain_t) "execute_no_trans" to
/usr/local/sbin/samhain (samhain_exec_t).

Detailed Description:

[SELinux is in permissive mode, the operation would have been denied but was
permitted due to permissive mode.]

SELinux denied access requested by samhain. It is not expected that this access
is required by samhain 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 /usr/local/sbin/samhain,

restorecon -v '/usr/local/sbin/samhain'

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:system_r:samhain_t:s0
Target Context system_u:object_r:samhain_exec_t:s0
Target Objects /usr/local/sbin/samhain [ file ]
Source samhain
Source Path /usr/local/sbin/samhain
Port <Unknown>
Host MALTA
Source RPM Packages
Target RPM Packages
Policy RPM selinux-policy-3.3.1-99.fc9
Selinux Enabled True
Policy Type targeted
MLS Enabled True
Enforcing Mode Permissive
Plugin Name catchall_file
Host Name MALTA
Platform Linux MALTA 2.6.26.5-45.fc9.i686 #1 SMP Sat Sep 20
03:45:00 EDT 2008 i686 i686
Alert Count 1
First Seen Sun 26 Oct 2008 07:19:12 PM CET
Last Seen Sun 26 Oct 2008 07:19:12 PM CET
Local ID 4b802823-267f-4b94-bafc-c8050310203b
Line Numbers

Raw Audit Messages

host=MALTA type=AVC msg=audit(1225045152.583:1290): avc: denied {
execute_no_trans } for pid=7159 comm="samhain"
path="/usr/local/sbin/samhain" dev=dm-0 ino=7552222
scontext=unconfined_u:system_r:samhain_t:s0
tcontext=system_u:object_r:samhain_exec_t:s0 tclass=file

host=MALTA type=SYSCALL msg=audit(1225045152.583:1290): arch=40000003
syscall=11 success=yes exit=0 a0=b8f57000 a1=bfc3cc48 a2=bfc3cfa0
a3=bfc3cd4c items=0 ppid=7158 pid=7159 auid=500 uid=0 gid=0 euid=0
suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="samhain"
exe="/usr/local/sbin/samhain" subj=unconfined_u:system_r:samhain_t:s0
key=(null)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samhain.fc
Type: application/octet-stream
Size: 547 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20081026/c1d65872/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samhain.if
Type: application/octet-stream
Size: 48 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20081026/c1d65872/attachment-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: samhain.te
Type: application/octet-stream
Size: 1773 bytes
Desc: not available
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20081026/c1d65872/attachment-0002.obj


2008-10-26 18:58:59

by domg472

[permalink] [raw]
Subject: [refpolicy] Help with policy writing

On Sun, 2008-10-26 at 19:43 +0100, Konrad Azzopardi wrote:

>
> Raw Audit Messages
>
> host=MALTA type=AVC msg=audit(1225045152.583:1290): avc: denied {
> execute_no_trans } for pid=7159 comm="samhain"
> path="/usr/local/sbin/samhain" dev=dm-0 ino=7552222
> scontext=unconfined_u:system_r:samhain_t:s0
> tcontext=system_u:object_r:samhain_exec_t:s0 tclass=file
>
> host=MALTA type=SYSCALL msg=audit(1225045152.583:1290): arch=40000003
> syscall=11 success=yes exit=0 a0=b8f57000 a1=bfc3cc48 a2=bfc3cfa0
> a3=bfc3cd4c items=0 ppid=7158 pid=7159 auid=500 uid=0 gid=0 euid=0
> suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="samhain"
> exe="/usr/local/sbin/samhain" subj=unconfined_u:system_r:samhain_t:s0
> key=(null)
samhain_t is trying to execute samhain executable file:

can_exec(samhain_t, samhain_exec_t)

might solve this. refer to this interface call in reference policy.

> _______________________________________________
> refpolicy mailing list
> refpolicy at oss.tresys.com
> http://oss.tresys.com/mailman/listinfo/refpolicy
--
Dominick Grift <[email protected]>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://oss.tresys.com/pipermail/refpolicy/attachments/20081026/c6ce8ed8/attachment.bin

2008-10-27 13:22:00

by bwhalen

[permalink] [raw]
Subject: [refpolicy] Help with policy writing

On 10/26/08 2:58 PM, "Dominick Grift" <[email protected]> wrote:

> On Sun, 2008-10-26 at 19:43 +0100, Konrad Azzopardi wrote:
>
>>
>> Raw Audit Messages
>>
>> host=MALTA type=AVC msg=audit(1225045152.583:1290): avc: denied {
>> execute_no_trans } for pid=7159 comm="samhain"
>> path="/usr/local/sbin/samhain" dev=dm-0 ino=7552222
>> scontext=unconfined_u:system_r:samhain_t:s0
>> tcontext=system_u:object_r:samhain_exec_t:s0 tclass=file
>>
>> host=MALTA type=SYSCALL msg=audit(1225045152.583:1290): arch=40000003
>> syscall=11 success=yes exit=0 a0=b8f57000 a1=bfc3cc48 a2=bfc3cfa0
>> a3=bfc3cd4c items=0 ppid=7158 pid=7159 auid=500 uid=0 gid=0 euid=0
>> suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="samhain"
>> exe="/usr/local/sbin/samhain" subj=unconfined_u:system_r:samhain_t:s0
>> key=(null)
> samhain_t is trying to execute samhain executable file:
>
> can_exec(samhain_t, samhain_exec_t)
>
> might solve this. refer to this interface call in reference policy.
>
This looks like you are transitioning to the samhain domain when the initrc
script is run and then that script is calling the actual executable. I would
suggest creating an init domain specific to samhain for the init script, but
you could just let it run as initrc_t and force the transition when the
samhain executable is run.

Not sure how far you are on this, but if you are going to submit this
upstream for a process like samhain which is going to vary based upon the
user you're probably going to want to give it something generic like
files_getattr_all_files, so that it can check every file on the system and
not just the specific ones you've listed in your database. Also, make sure
you limit what it can write to so you limit any potential exploits.


>> _______________________________________________
>> refpolicy mailing list
>> refpolicy at oss.tresys.com
>> http://oss.tresys.com/mailman/listinfo/refpolicy

2008-10-27 15:30:44

by konrad.azzopardi

[permalink] [raw]
Subject: [refpolicy] Help with policy writing

thanks for your help, I did use the can_exec and I also created a
domain samhain_script_exec_t for the init script. Now I will refine
the policy cause I think I may have used macros that are supersets of
other macros {still learning here}. Tnx for your help

konrad

On Mon, Oct 27, 2008 at 2:22 PM, Brandon Whalen <[email protected]> wrote:
> On 10/26/08 2:58 PM, "Dominick Grift" <[email protected]> wrote:
>
>> On Sun, 2008-10-26 at 19:43 +0100, Konrad Azzopardi wrote:
>>
>>>
>>> Raw Audit Messages
>>>
>>> host=MALTA type=AVC msg=audit(1225045152.583:1290): avc: denied {
>>> execute_no_trans } for pid=7159 comm="samhain"
>>> path="/usr/local/sbin/samhain" dev=dm-0 ino=7552222
>>> scontext=unconfined_u:system_r:samhain_t:s0
>>> tcontext=system_u:object_r:samhain_exec_t:s0 tclass=file
>>>
>>> host=MALTA type=SYSCALL msg=audit(1225045152.583:1290): arch=40000003
>>> syscall=11 success=yes exit=0 a0=b8f57000 a1=bfc3cc48 a2=bfc3cfa0
>>> a3=bfc3cd4c items=0 ppid=7158 pid=7159 auid=500 uid=0 gid=0 euid=0
>>> suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="samhain"
>>> exe="/usr/local/sbin/samhain" subj=unconfined_u:system_r:samhain_t:s0
>>> key=(null)
>> samhain_t is trying to execute samhain executable file:
>>
>> can_exec(samhain_t, samhain_exec_t)
>>
>> might solve this. refer to this interface call in reference policy.
>>
> This looks like you are transitioning to the samhain domain when the initrc
> script is run and then that script is calling the actual executable. I would
> suggest creating an init domain specific to samhain for the init script, but
> you could just let it run as initrc_t and force the transition when the
> samhain executable is run.
>
> Not sure how far you are on this, but if you are going to submit this
> upstream for a process like samhain which is going to vary based upon the
> user you're probably going to want to give it something generic like
> files_getattr_all_files, so that it can check every file on the system and
> not just the specific ones you've listed in your database. Also, make sure
> you limit what it can write to so you limit any potential exploits.
>
>
>>> _______________________________________________
>>> refpolicy mailing list
>>> refpolicy at oss.tresys.com
>>> http://oss.tresys.com/mailman/listinfo/refpolicy
>
>
>

2008-10-29 12:37:52

by Daniel Walsh

[permalink] [raw]
Subject: [refpolicy] Help with policy writing

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


/usr/local/sbin/samhain --
gen_context(system_u:object_r:samhain_exec_t,s0)

DAN> I would make this more generic maybe make the local optional

/usr/(local/)?sbin/samhain --
gen_context(system_u:object_r:samhain_exec_t,s0)


/etc/samhainrc -- gen_context(system_u:object_r:samhain_config_t,s0)


/var/run/samhain.pid --
gen_context(system_u:object_r:samhain_pid_t,s0)
/var/run/samhain_log.lock
gen_context(system_u:object_r:samhain_lock_t,s0)

I think these should be treated the same and labeled samhain_var_run_t

Unless there are different security properties between the pid file and
the lock file, no reason to label them differently.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkIWR8ACgkQrlYvE4MpobP0OQCeNtwQ9LuZ8IpLMFerpJH9HjAq
V2gAoJOT3Gu+ZPLvkBaEWyMYoJ96O8uo
=zb5o
-----END PGP SIGNATURE-----