<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss version="2.0">

<channel>
	<title>Planet Larry</title>
	<link>http://larrythecow.org/</link>
	<language>en</language>
	<description>Planet Larry - http://larrythecow.org/</description>

<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/planet_larry" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="planet_larry" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
	<title>Sven Vermeulen: A SELinux policy for incron: basic set for incrontab</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1200</guid>
	<link>http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-basic-set-for-incrontab/</link>

	<description>&lt;p&gt;
Now that our &lt;a href="http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-our-first-interface/"&gt;regular user is allowed&lt;/a&gt; to execute &lt;b&gt;incrontab&lt;/b&gt;, let’s fire it up and look at the denials to build up the policy.
&lt;/p&gt;
&lt;pre&gt;$ incrontab --help
&lt;/pre&gt;
&lt;p&gt;
That doesn’t show much does it? Well, if you look into the &lt;tt&gt;audit.log&lt;/tt&gt; (or &lt;tt&gt;avc.log&lt;/tt&gt;) file, you’ll notice a lot of denials. If you are developing a policy, it is wise to clear the entire log and reproduce the “situation” so you get a proper idea of the scope.
&lt;/p&gt;
&lt;pre&gt;# cd /var/log/audit
# &amp;gt; audit.log
# tail -f audit.log | grep AVC
&lt;/pre&gt;
&lt;p&gt;
Now let’s run &lt;b&gt;incrontab –help&lt;/b&gt; again and look at the denials:
&lt;/p&gt;
&lt;pre&gt;type=AVC msg=audit(1368707274.429:28180): avc:  denied  { read write } for  pid=7742 comm="incrontab" path="/dev/tty2" dev="devtmpfs" ino=1042 scontext=user_u:user_r:incrontab_t tcontext=user_u:object_r:user_tty_device_t tclass=chr_file
type=AVC msg=audit(1368707274.429:28180): avc:  denied  { use } for  pid=7742 comm="incrontab" path="/dev/tty2" dev="devtmpfs" ino=1042 scontext=user_u:user_r:incrontab_t tcontext=system_u:system_r:getty_t tclass=fd
type=AVC msg=audit(1368707274.429:28180): avc:  denied  { use } for  pid=7742 comm="incrontab" path="/dev/tty2" dev="devtmpfs" ino=1042 scontext=user_u:user_r:incrontab_t tcontext=system_u:system_r:getty_t tclass=fd
type=AVC msg=audit(1368707274.429:28180): avc:  denied  { use } for  pid=7742 comm="incrontab" path="/dev/tty2" dev="devtmpfs" ino=1042 scontext=user_u:user_r:incrontab_t tcontext=system_u:system_r:getty_t tclass=fd
&lt;/pre&gt;
&lt;p&gt;
You can start piping this information into &lt;b&gt;audit2allow&lt;/b&gt; to generate policy statements, but I personally prefer not to use &lt;b&gt;audit2allow&lt;/b&gt; for building new policies. For one, it is not intelligent enough to deduce if a denial should be fixed by allowing it, or by relabeling or even by creating a new type. Instead, it always grants it. Second, it does not know if a denial is cosmetic (and thus can be ignored) or not.
&lt;/p&gt;
&lt;p&gt;
This latter is also why I don’t run domains in permissive mode to see the majority of denials first and to build from those: you might see denials that are actually never triggered when running in enforcing mode. So let’s look at the access to &lt;tt&gt;/dev/tty2&lt;/tt&gt;. Given that this is a user application where we expect output to the screen, we want to grant it the proper access. With &lt;b&gt;sefindif&lt;/b&gt; as &lt;a href="http://blog.siphos.be/2013/05/commandline-selinux-policy-helper-functions/"&gt;documented&lt;/a&gt; before, we can look for the proper interfaces we need. I look for &lt;tt&gt;user_tty_device_t&lt;/tt&gt; with &lt;tt&gt;rw&lt;/tt&gt; (commonly used for read-write):
&lt;/p&gt;
&lt;pre&gt;$ sefindif user_tty_device_t.*rw
system/userdomain.if: template(`userdom_base_user_template',`
system/userdomain.if:   allow $1_t user_tty_device_t:chr_file { setattr rw_chr_file_perms };
system/userdomain.if: interface(`userdom_use_user_ttys',`
system/userdomain.if:   allow $1 user_tty_device_t:chr_file rw_term_perms;
system/userdomain.if: interface(`userdom_use_user_terminals',`
system/userdomain.if:   allow $1 user_tty_device_t:chr_file rw_term_perms;
system/userdomain.if: interface(`userdom_dontaudit_use_user_terminals',`
system/userdomain.if:   dontaudit $1 user_tty_device_t:chr_file rw_term_perms;
system/userdomain.if: interface(`userdom_dontaudit_use_user_ttys',`
system/userdomain.if:   dontaudit $1 user_tty_device_t:chr_file rw_file_perms;
&lt;/pre&gt;
&lt;p&gt;
Two of these look interesting: &lt;em&gt;userdom_use_user_ttys&lt;/em&gt; and &lt;em&gt;userdom_use_user_terminals&lt;/em&gt;. Looking at the API documentation (or the rules defined therein using &lt;b&gt;seshowif&lt;/b&gt;) reveals that &lt;em&gt;userdom_use_user_terminals&lt;/em&gt; is needed if you also want the application to work when invoked through a devpts terminal, which is probably also something our user(s) want to do, so we’ll add that. The second one – using the file descriptor that has the &lt;tt&gt;getty_t&lt;/tt&gt; context – is related to this, but not granted through the &lt;em&gt;userdom_use_user_ttys&lt;/em&gt;. We could grant &lt;em&gt;getty_use_fds&lt;/em&gt; but my experience tells me that &lt;em&gt;domain_use_interactive_fds&lt;/em&gt; is more likely to be needed: the application inherits and uses a file descriptor currently owned by &lt;tt&gt;getty_t&lt;/tt&gt; but it could be from any of the other domains that has such file descriptors. For instance, if you grant the &lt;em&gt;incron_role&lt;/em&gt; to &lt;tt&gt;sysadm_r&lt;/tt&gt;, then a user that switched roles through &lt;b&gt;newrole&lt;/b&gt; will see denials for using a file descriptor owned by &lt;tt&gt;newrole_t&lt;/tt&gt;.
&lt;/p&gt;
&lt;p&gt;
Experience is an important aspect in developing policies. If you would go through with &lt;em&gt;getty_use_fds&lt;/em&gt; it would work as well, and you’ll probably hit the above mentioned experience later when you try the application through a few different paths (such as within a screen session or so). When you &lt;em&gt;think&lt;/em&gt; that the target context (in this case &lt;tt&gt;getty_t&lt;/tt&gt;) could be a placeholder (so other types are likely to be needed as well), make sure you check which attributes are assigned to the type:
&lt;/p&gt;
&lt;pre&gt;# seinfo -tgetty_t -x
   getty_t
      privfd
      mcssetcats
      mlsfileread
      mlsfilewrite
      application_domain_type
      domain
&lt;/pre&gt;
&lt;p&gt;
Of the above ones, &lt;tt&gt;privfd&lt;/tt&gt; is the important one:
&lt;/p&gt;
&lt;pre&gt;$ sefindif privfd.*use
kernel/domain.if: interface(`domain_use_interactive_fds',`
kernel/domain.if:       allow $1 privfd:fd use;
kernel/domain.if: interface(`domain_dontaudit_use_interactive_fds',`
kernel/domain.if:       dontaudit $1 privfd:fd use;
&lt;/pre&gt;
&lt;p&gt;
So let’s update &lt;tt&gt;incron.te&lt;/tt&gt; accordingly:
&lt;/p&gt;
&lt;pre&gt;...
type incron_spool_t;
files_type(incron_spool_t)

###########################################
#
# incrontab policy
#

userdom_use_user_terminals(incrontab_t)
domain_use_interactive_fds(incrontab_t)
&lt;/pre&gt;
&lt;p&gt;
Rebuild the policy and load it in memory.
&lt;/p&gt;
&lt;p&gt;
If we now run &lt;b&gt;incrontab&lt;/b&gt; we get the online help as we expected. Let’s now look at the currently installed incrontabs (there shouldn’t be any of course):
&lt;/p&gt;
&lt;pre&gt;$ incrontab -l
cannot determine current user
&lt;/pre&gt;
&lt;p&gt;
In the denials, we notice:
&lt;/p&gt;
&lt;pre&gt;type=AVC msg=audit(1368708632.060:28192): avc:  denied  { create } for  pid=7968 comm="incrontab" scontext=user_u:user_r:incrontab_t tcontext=user_u:user_r:incrontab_t tclass=unix_stream_socket
type=AVC msg=audit(1368708632.060:28194): avc:  denied  { read } for  pid=7968 comm="incrontab" name="nsswitch.conf" dev="dm-2" ino=393768 scontext=user_u:user_r:incrontab_t tcontext=system_u:object_r:etc_t tclass=file
type=AVC msg=audit(1368708632.062:28196): avc:  denied  { read } for  pid=7968 comm="incrontab" name="passwd" dev="dm-2" ino=394223 scontext=user_u:user_r:incrontab_t tcontext=system_u:object_r:etc_t tclass=file
&lt;/pre&gt;
&lt;p&gt;
Let’s first focus on &lt;tt&gt;nsswitch.conf&lt;/tt&gt; and &lt;tt&gt;passwd&lt;/tt&gt;. Although both require read access to &lt;tt&gt;etc_t&lt;/tt&gt; files, it might be wrong to just add in &lt;em&gt;files_read_etc&lt;/em&gt; (which is what &lt;b&gt;audit2allow&lt;/b&gt; is probably going to suggest). For nsswitch, there is a special interface available: &lt;em&gt;auth_use_nsswitch&lt;/em&gt;. It is very, very likely that you’ll need this one, especially if you want to share the policy with others who might not have all of the system databases in local files (as &lt;tt&gt;etc_t&lt;/tt&gt; files).
&lt;/p&gt;
&lt;pre&gt;...
domain_use_interactive_fds(incrontab_t)
auth_use_nsswitch(incrontab_t)
&lt;/pre&gt;
&lt;p&gt;
Let’s retry:
&lt;/p&gt;
&lt;pre&gt;$ incrontab -l
cannot read table for 'user': Permission denied

# tail audit.log
type=AVC msg=audit(1368708893.260:28199): avc:  denied  { search } for  pid=7997 comm="incrontab" name="spool" dev="dm-4" ino=20 scontext=user_u:user_r:incrontab_t tcontext=system_u:object_r:var_spool_t tclass=dir
&lt;/pre&gt;
&lt;p&gt;
So we need to grant search privileges on &lt;tt&gt;var_spool_t&lt;/tt&gt;. This is offered through &lt;em&gt;files_search_spool&lt;/em&gt;. Add it to the policy, rebuild and retry.
&lt;/p&gt;
&lt;pre&gt;$ incrontab -l
cannot read table for 'user': Permission denied

# tail audit.log
type=AVC msg=audit(1368709146.426:28201): avc:  denied  { search } for  pid=8046 comm="incrontab" name="incron" dev="dm-4" ino=19725 scontext=user_u:user_r:incrontab_t tcontext=root:object_r:incron_spool_t tclass=dir
&lt;/pre&gt;
&lt;p&gt;
For this one, no interface exists yet. We might be able to create one for ourselves, but as long as other domains don’t need it, we can just add it locally in our policy:
&lt;/p&gt;
&lt;pre&gt;allow incrontab_t incron_spool_t:dir search_dir_perms;
&lt;/pre&gt;
&lt;p&gt;
Adding raw allow rules in a policy is, according to the &lt;a href="http://oss.tresys.com/projects/refpolicy/wiki/StyleGuide"&gt;refpolicy styleguide&lt;/a&gt;, only allowed if the policy module defines both the source and the destination type of the rule. If you look into other policies you might also find that you can use the &lt;em&gt;search_dirs_patter&lt;/em&gt; call. However, that one only makes sense if you need to do this on top of another directory – just look at the definition of &lt;em&gt;search_dirs_pattern&lt;/em&gt;. So with this permission set, let’s retry.
&lt;/p&gt;
&lt;pre&gt;$ incrontab -l
no table for user
&lt;/pre&gt;
&lt;p&gt;
Great, we have successfully updated the policy until the commands worked. In the next post, we’ll enhance it even further while creating new incrontabs.&lt;/p&gt;</description>
	<pubDate>Sat, 25 May 2013 01:50:54 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: A SELinux policy for incron: our first interface</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1196</guid>
	<link>http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-our-first-interface/</link>

	<description>&lt;p&gt;
The next step after having &lt;a href="http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-the-basic-skeleton/"&gt;a basic skeleton&lt;/a&gt; is to get &lt;b&gt;incrontab&lt;/b&gt; running. We know however that everything invoked from the main daemon will be running with the rights of the daemon context (unless we would patch the source code, but that is beyond the scope of this set of posts). As a result, we probably do not want everyone to be able to launch commands through this application.
&lt;/p&gt;
&lt;p&gt;
What we want to do is to limit who can invoke &lt;b&gt;incrontab&lt;/b&gt; and, as such, limit who can decide what is invoked through &lt;b&gt;incrond&lt;/b&gt;. First of all, we define a &lt;em&gt;role attribute&lt;/em&gt; called &lt;tt&gt;incrontab_roles&lt;/tt&gt;. Every role that gets this attribute assigned will be able to transition to the &lt;tt&gt;incrontab_t&lt;/tt&gt; domain.
&lt;/p&gt;
&lt;p&gt;
We can accomplish this by editing the &lt;tt&gt;incron.te&lt;/tt&gt; file:
&lt;/p&gt;
&lt;pre&gt;policy_module(incron, 0.2)

# Declare the incrontab_roles attribute
attribute_role incrontab_roles;

...
type incrontab_t;
type incrontab_exec_t;
application_domain(incrontab_t, incrontab_exec_t)
# Allow incrontab_t for all incrontab_roles 
role incrontab_roles types incrontab_t;
&lt;/pre&gt;
&lt;p&gt;
Next, we need something where we can allow user domains to call incrontab. This will be done through an interface. Let’s look at &lt;tt&gt;incron.if&lt;/tt&gt; with one such interface in it: the &lt;em&gt;incron_role&lt;/em&gt; interface.
&lt;/p&gt;
&lt;pre&gt;## &amp;lt;summary&amp;gt;inotify-based cron-like daemon&amp;lt;/summary&amp;gt;

#########################################
## &amp;lt;summary&amp;gt;
##      Role access for incrontab
## &amp;lt;/summary&amp;gt;
## &amp;lt;param name="role"&amp;gt;
##      &amp;lt;summary&amp;gt;
##      Role allowed access.
##      &amp;lt;/summary&amp;gt;
## &amp;lt;/param&amp;gt;
## &amp;lt;param name="domain"&amp;gt;
##      &amp;lt;summary&amp;gt;
##      User domain for the role.
##      &amp;lt;/summary&amp;gt;
## &amp;lt;/param&amp;gt;
#
interface(`incron_role',`
        gen_require(`
                attribute_role incrontab_roles;
                type incrontab_exec_t, incrontab_t;
        ')

        roleattribute $1 incrontab_roles;

        domtrans_pattern($2, incrontab_exec_t, incrontab_t)

        ps_process_pattern($2, incrontab_t)
        allow $2 incrontab_t:process signal;
')
&lt;/pre&gt;
&lt;p&gt;
The comments in the file are somewhat special: if the comments start with two hashes (&lt;tt&gt;##&lt;/tt&gt;) then it is taken into account while building the policy documentation in &lt;tt&gt;/usr/share/doc/selinux-base-*&lt;/tt&gt;. The interface itself, &lt;em&gt;incron_role&lt;/em&gt;, grants a user role and domain the necessary privileges to transition to the &lt;tt&gt;incrontab_t&lt;/tt&gt; domain as well as read process information (as used through &lt;b&gt;ps&lt;/b&gt;, hence the name of the pattern being &lt;tt&gt;ps_process_pattern&lt;/tt&gt;) and send a standard signal to it. Most of the time, you can use &lt;tt&gt;signal_perms&lt;/tt&gt; here but from looking at the application we see that the application is setuid root, so we don’t want to grant too many privileges by default if they are not needed.
&lt;/p&gt;
&lt;p&gt;
With this interface file created, we can rebuild the module and load it.
&lt;/p&gt;
&lt;pre&gt;# make -f /usr/share/selinux/strict/include/Makefile incron.pp
# semodule -i incron.pp
&lt;/pre&gt;
&lt;p&gt;
But how to assign this interface to users? Well, what we want to do is something like the following:
&lt;/p&gt;
&lt;pre&gt;incron_role(user_r, user_t)
&lt;/pre&gt;
&lt;p&gt;
When interfaces are part of the policy provided by the distribution, the definitions of it are stored in the proper location and you can easily add it. For instance, in Gentoo, if you want to allow the &lt;tt&gt;user_r&lt;/tt&gt; role and &lt;tt&gt;user_t&lt;/tt&gt; domain the &lt;em&gt;cron_role&lt;/em&gt; access (and assuming it doesn’t have so already), then you can call &lt;b&gt;selocal&lt;/b&gt; as follows:
&lt;/p&gt;
&lt;pre&gt;# selocal -a "cron_role(user_r, user_t)" -c "Granting user_t cron access" -Lb
&lt;/pre&gt;
&lt;p&gt;
However, because the interface is currently not known yet, we need to create a second small policy that does this. Create a file (called &lt;tt&gt;localuser.te&lt;/tt&gt; or so) with the following content:
&lt;/p&gt;
&lt;pre&gt;policy_module(localuser, 0.1)

gen_require(`
        type user_t;
        role user_r;
')

incron_role(user_r, user_t)
&lt;/pre&gt;
&lt;p&gt;
Now build the policies and load them. We’ll now just build and load all the policies in the current directory (which will be the incron and localuser ones):
&lt;/p&gt;
&lt;pre&gt;# make -f /usr/share/selinux/strict/include/Makefile
# semodule -i *.pp
&lt;/pre&gt;
&lt;p&gt;
You can now verify that the user is allowed to transition to the &lt;tt&gt;incrontab_t&lt;/tt&gt; domain:
&lt;/p&gt;
&lt;pre&gt;# seinfo -ruser_r -x | grep incron
         incrontab_t
# sesearch -s user_t -t incrontab_exec_t -AdCTS
Found 1 semantic av rules:
   allow user_t incrontab_exec_t : file { read getattr execute open } ; 

Found 1 semantic te rules:
   type_transition user_t incrontab_exec_t : process incrontab_t; 
&lt;/pre&gt;
&lt;p&gt;
Great, let’s get to our first failure to resolve… in the next post ;-)&lt;/p&gt;</description>
	<pubDate>Fri, 24 May 2013 01:50:08 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: A SELinux policy for incron: the basic skeleton</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1188</guid>
	<link>http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-the-basic-skeleton/</link>

	<description>&lt;p&gt;
So, in the &lt;a href="http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-what-does-it-do/"&gt;previous post&lt;/a&gt; I talked about &lt;em&gt;incron&lt;/em&gt; and why I think moving it into the existing cron policy would not be a good idea. It works, somewhat, but is probably not that future-proof. So we’re going to create our own policy for it.
&lt;/p&gt;
&lt;p&gt;
In SELinux, policies are generally written through 3 files:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a &lt;em&gt;type enforcement&lt;/em&gt; file that contains the SELinux rules applicable to the domain(s) related to the application (in our example, &lt;em&gt;incron&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;a &lt;em&gt;file context&lt;/em&gt; file that tells the SELinux utilities how the files and directories offered by the application should be labeled&lt;/li&gt;
&lt;li&gt;an &lt;em&gt;interface definition&lt;/em&gt; file that allows other SELinux policy modules to gain rights offered through the (to be written) &lt;em&gt;incron&lt;/em&gt; policy&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
We now need to create a skeleton for the policy. This skeleton will define the types related to the application. Such types can be the domains for the processes (the context of the &lt;b&gt;incrond&lt;/b&gt; and perhaps also &lt;b&gt;incrontab&lt;/b&gt; applications), the contexts for the directories (if any) and files, etc.
&lt;/p&gt;
&lt;p&gt;
So let’s take a look at the content of the &lt;em&gt;incron&lt;/em&gt; package. On Gentoo, we can use &lt;b&gt;qlist incron&lt;/b&gt; for this. In the output of &lt;b&gt;qlist&lt;/b&gt;, I added comments to show you how contexts can be (easily) deduced.
&lt;/p&gt;
&lt;pre&gt;# Application binary for managing user crontabs. We want to give this a specific
# context because we want the application (which will manage the incrontabs in
# /var/spool/incron) in a specific domain
/usr/bin/incrontab  ## incrontab_exec_t

# General application information files, do not need specific attention
# (the default context is fine)
/usr/share/doc/incron-0.5.10/README.bz2
/usr/share/doc/incron-0.5.10/TODO.bz2
/usr/share/doc/incron-0.5.10/incron.conf.example.bz2
/usr/share/doc/incron-0.5.10/CHANGELOG.bz2
/usr/share/man/man8/incrond.8.bz2
/usr/share/man/man5/incron.conf.5.bz2
/usr/share/man/man5/incrontab.5.bz2
/usr/share/man/man1/incrontab.1.bz2

# Binary for the incrond daemon. This definitely needs its own context, since
# it will be launched from an init script and we do not want it to run in the
# initrc_t domain.
/usr/sbin/incrond ## incrond_exec_t

# This is the init script for the incrond daemon. If we want to allow 
# some users the rights to administer incrond without needing to grant
# those users the sysadm_r role, we need to give this file a different
# context as well.
/etc/init.d/incrond ## incrond_initrc_exec_t
&lt;/pre&gt;
&lt;p&gt;
With this information at hand, and the behavior of the application we know from the previous post, can lead to the following &lt;tt&gt;incron.fc&lt;/tt&gt; file, which defines the file contexts for the application.
&lt;/p&gt;
&lt;pre&gt;/etc/incron.d(/.*)?     gen_context(system_u:object_r:incron_spool_t,s0)

/etc/rc\.d/init\.d/incrond      --      gen_context(system_u:object_r:incrond_initrc_exec_t,s0)

/usr/bin/incrontab      --      gen_context(system_u:object_r:incrontab_exec_t,s0)

/usr/sbin/incrond       --      gen_context(system_u:object_r:incrond_exec_t,s0)

/var/spool/incron(/.*)?         gen_context(system_u:object_r:incron_spool_t,s0)
&lt;/pre&gt;
&lt;p&gt;
The syntax of this file closely follows the syntax that &lt;b&gt;semanage fcontext&lt;/b&gt; takes – at least for the regular expressions in the beginning. The last column is specifically for policy development to generate a context based on the policies’ requirements: an MCS/MLS enabled policy will get the trailing sensitivity with it, but when MCS/MLS is disabled then it is dropped. The middle column is to specify if the label should only be set on regular files (&lt;tt&gt;--&lt;/tt&gt;), directories (&lt;tt&gt;-d&lt;/tt&gt;), sockets (&lt;tt&gt;-s&lt;/tt&gt;), symlinks (&lt;tt&gt;-l&lt;/tt&gt;), etc. If it is omitted, it matches whatever class the path matches.
&lt;/p&gt;
&lt;p&gt;
The second file needed for the skeleton is the &lt;tt&gt;incron.te&lt;/tt&gt; file, which would look like so. I added in inline comments here to explain why certain lines are prepared, but generally this is omitted when the policy is &lt;a href="http://oss.tresys.com/projects/refpolicy/"&gt;upstreamed&lt;/a&gt;.
&lt;/p&gt;
&lt;pre&gt;policy_module(incron, 0.1)
# The above line declares that this file is a SELinux policy file. Its name
# is incron, so the file should saved as incron.te

# First, we declare the incrond_t domain, used for the "incrond" process.
# Because it is launched from an init script, we tell the policy that
# incrond_exec_t (the context of incrond), when launched from init, should
# transition to incrond_t.
#
# Basically, the syntax here is:
# type &amp;lt;domain&amp;gt;
# type &amp;lt;file context="context"&amp;gt;
# &amp;lt;interface call="call" linking="linking" the="the" two="two"&amp;gt;
type incrond_t;
type incrond_exec_t;
init_daemon_domain(incrond_t, incrond_exec_t)

# Next we declare that the incrond_initrc_exec_t is an init script context
# so that init can execute it (remember, SELinux is a mandatory access control
# system, so if we do not tell that init can execute it, it won't).
type incrond_initrc_exec_t;
init_script_file(incrond_initrc_exec_t)

# We also create the incrontab_t domain (for the "incrontab" application), which
# is triggered through the incrontab_exec_t labeled file. This again follows a bit
# the syntax as we used above, but now the interface call is "application_domain".
type incrontab_t;
type incrontab_exec_t;
application_domain(incrontab_t, incrontab_exec_t)

# Finally we declare the spool type as well (incron_spool_t) and tell SELinux that
# it will be used for regular files.
type incron_spool_t;
files_type(incron_spool_t)
&lt;/pre&gt;
&lt;p&gt;
Knowing which interface calls, like &lt;em&gt;init_daemon_domain&lt;/em&gt; and &lt;em&gt;application_domain&lt;/em&gt;, we should use is not obvious at first. Most of this can be gathered from existing policies. Other frequently occurring interfaces to be used immediately at the skeleton side are (examples for a &lt;tt&gt;foo_t&lt;/tt&gt; domain):
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;logging_log_file(foo_log_t)&lt;/em&gt; to inform SELinux that the context is used for logging purposes. This allows generic log-related daemons to do “their thing” with the file.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;files_tmp_file(foo_tmp_t)&lt;/em&gt; to identify the context as being used for temporary files&lt;/li&gt;
&lt;li&gt;&lt;em&gt;files_tmpfs_file(foo_tmpfs_t)&lt;/em&gt; for tmpfs files (which could be shared memory)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;files_pid_file(foo_var_run_t)&lt;/em&gt; for PID files (and other run metadata files)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;files_config_file(foo_conf_t)&lt;/em&gt; for configuration files (often within &lt;tt&gt;/etc&lt;/tt&gt;)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;files_lock_file(foo_lock_t)&lt;/em&gt; for lock files (often within &lt;tt&gt;/run/lock&lt;/tt&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We might be using these later as we progress with the policy (for instance, the PID file is a very high candidate for needing to be included). However, with the information currently at hand, we have our first policy module ready for building. Save the type enforcement rules in &lt;tt&gt;incron.te&lt;/tt&gt; and the file contexts in &lt;tt&gt;incron.fc&lt;/tt&gt; and you can then build the SELinux policy:
&lt;/p&gt;
&lt;pre&gt;# make -f /usr/share/selinux/strict/include/Makefile incron.pp
# semodule -i incron.pp
&lt;/pre&gt;
&lt;p&gt;
On Gentoo, you can then relabel the files and directories offered through the package using &lt;b&gt;rlpkg&lt;/b&gt;:
&lt;/p&gt;
&lt;pre&gt;# rlpkg incron
&lt;/pre&gt;
&lt;p&gt;
Next is to start looking at the &lt;b&gt;incrontab&lt;/b&gt; application.&lt;/p&gt;</description>
	<pubDate>Thu, 23 May 2013 01:50:36 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: A SELinux policy for incron: what does it do?</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1180</guid>
	<link>http://blog.siphos.be/2013/05/a-selinux-policy-for-incron-what-does-it-do/</link>

	<description>&lt;p&gt;
In this series of posts, we’ll go through the creation of a SELinux policy for &lt;a href="http://inotify.aiken.cz/?section=incron&amp;amp;page=doc&amp;amp;lang=en"&gt;incron&lt;/a&gt;, a simple inotify based cron-like application. I will talk about the various steps that I would take in the creation of this policy, and give feedback when certain decisions are taken and why. At the end of the series, we’ll have a hopefully well working policy.
&lt;/p&gt;
&lt;p&gt;
The first step in developing a policy is to know what the application does and how/where it works. This allows us to check if its behavior matches an existing policy (and as such might be best just added to this policy) or if a new policy needs to be written. So, what does incron do?
&lt;/p&gt;
&lt;p&gt;
From the documentation, we know that &lt;em&gt;incron&lt;/em&gt; is a cron-like application that, unlike cron, works with file system notification events instead of time-related events. Other than that, it uses a similar way of working:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A daemon called &lt;b&gt;incrond&lt;/b&gt; is the run-time application that reads in the &lt;em&gt;incrontab&lt;/em&gt; files and creates the proper inotify watches. When a watch is triggered, it will execute the matching rule.&lt;/li&gt;
&lt;li&gt;The daemon looks at two definitions (incrontabs): one system-wide (in &lt;tt&gt;/etc/incron.d&lt;/tt&gt;) and one for users (in &lt;tt&gt;/var/spool/incron&lt;/tt&gt;).&lt;/li&gt;
&lt;li&gt;The user tabfiles are managed through &lt;b&gt;incrontab&lt;/b&gt; (the command)&lt;/li&gt;
&lt;li&gt;Logging is done through syslog&lt;/li&gt;
&lt;li&gt;User commands are executed with the users’ privileges (so the application calls &lt;em&gt;setuid()&lt;/em&gt; and &lt;em&gt;setgid()&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
With this, one can create a script to be executed when a file is uploaded (or deleted) to/from a file server, or when a process coredump occurred, or whatever automation you want to trigger when some file system event occurred. Events are plenty and can be found in &lt;tt&gt;/usr/include/sys/inotify.h&lt;/tt&gt;.
&lt;/p&gt;
&lt;p&gt;
So, with this information, it is safe to assume that we might be able to push incron in the existing &lt;em&gt;cron&lt;/em&gt; policy. After all, it defines the contexts for all these and probably doesn’t need any additional tweaking. And this seems to work at first, but a few tests reveal that the behavior is not that optimal.
&lt;/p&gt;
&lt;pre&gt;# chcon -t crond_exec_t /usr/sbin/incrond
# chcon -t crontab_exec_t /usr/bin/incrontab
# chcon -R -t system_cron_spool_t /etc/incron.d
# chcon -t cron_log_t /var/log/cron.log
# chcon -R -t cron_spool_t /var/spool/incron
&lt;/pre&gt;
&lt;p&gt;
System tables work somewhat, but all commands are executed in the &lt;tt&gt;crond_t&lt;/tt&gt; domain, not in a &lt;tt&gt;system_cronjob_t&lt;/tt&gt; or related domain.&lt;br /&gt;
User tables fail when dealing with files in the users directories, since these too run in &lt;tt&gt;crond_t&lt;/tt&gt; and thus have no read access to the user home directories.
&lt;/p&gt;
&lt;p&gt;
The problems we notice come from the fact that the application is very simple in its code: it is not SELinux-aware (so it doesn’t change the runtime context) as most cron daemons are, and when it changes the user id it does not call PAM, so we cannot trigger &lt;tt&gt;pam_selinux.so&lt;/tt&gt; to handle context changes either. As a result, the entire daemon keeps running in &lt;tt&gt;crond_t&lt;/tt&gt;.
&lt;/p&gt;
&lt;p&gt;
This is one reason why a separate domain could be interesting: we might want to extend the rights of the daemon domain a bit, but don’t want to extend these rights to the other cron daemons (who also run in &lt;tt&gt;crond_t&lt;/tt&gt;). Another reason is that the cron policy has a few booleans that would not affect the behavior at all, making it less obvious for users to troubleshoot. As a result, we’ll go for the separate policy instead – which will be for the next post.&lt;/p&gt;</description>
	<pubDate>Wed, 22 May 2013 01:50:33 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Why oh why does a process run in unlabeled_t?</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1177</guid>
	<link>http://blog.siphos.be/2013/05/why-oh-why-does-a-process-run-in-unlabeled_t/</link>

	<description>&lt;p&gt;
If you notice that a process is running in the &lt;tt&gt;unlabeled_t&lt;/tt&gt; domain, the first question to ask is how it got there.
&lt;/p&gt;
&lt;p&gt;
Well, one way is to have a process running in a known domain, like &lt;tt&gt;screen_t&lt;/tt&gt;, after which the SELinux policy module that provides this domain is removed from the system (or updated and the update does not contain the &lt;tt&gt;screen_t&lt;/tt&gt; definition anymore):
&lt;/p&gt;
&lt;pre&gt;test ~ # ps -eZ | grep screen
root:sysadm_r:sysadm_screen_t    5047 ?        00:00:00 screen
test ~ # semodule -r screen
test ~ # ps -eZ | grep screen
system_u:object_r:unlabeled_t    5047 ?        00:00:00 screen
&lt;/pre&gt;
&lt;p&gt;
In permissive mode, this will be visible easily; in enforcing mode, the domains you are running in might not be allowed to do anything with &lt;tt&gt;unlabeled_t&lt;/tt&gt; files, directories and processes, so &lt;b&gt;ps&lt;/b&gt; might not show it even though it still exists:
&lt;/p&gt;
&lt;pre&gt;test audit # ps -eZ | grep 5047
test audit # ls -dZ /proc/5047
ls: cannot access /proc/5047: Permission denied
test audit # tail audit.log | grep unlabeled
type=AVC msg=audit(1368698097.494:27806): avc:  denied  { getattr } for  pid=4137 comm="bash" path="/proc/5047" dev="proc" ino=6677 scontext=root:sysadm_r:sysadm_t tcontext=system_u:object_r:unlabeled_t tclass=dir
&lt;/pre&gt;
&lt;p&gt;
Notice that, if you reload the module, the process becomes visible again. That is because the process context itself (&lt;tt&gt;screen_t&lt;/tt&gt;) is retained, but because the policy doesn’t know it anymore, it shows it as &lt;tt&gt;unlabeled_t&lt;/tt&gt;.
&lt;/p&gt;
&lt;p&gt;
Basically, the moment the policy doesn’t know how a label would be (should be), it uses &lt;tt&gt;unlabeled_t&lt;/tt&gt;. The SELinux policy then defines how this &lt;tt&gt;unlabeled_t&lt;/tt&gt; domain is handled. Processes getting into &lt;tt&gt;unlabeled_t&lt;/tt&gt; is not that common though as there is no supported transition to it. The above one is one way that this still can occur.&lt;/p&gt;</description>
	<pubDate>Tue, 21 May 2013 01:50:50 +0000</pubDate>
</item>
<item>
	<title>Jürgen Geuter: “Host your own” is cynical</title>
	<guid isPermalink="false">http://tante.cc/?p=1642</guid>
	<link>http://tante.cc/2013/05/20/host-your-own-is-cynical/</link>

	<description>&lt;img src="http://planet.larrythecow.org/images/j_rgen_geuter.jpg" alt="" align="right" style="float: right;"&gt;&lt;p&gt;It seems as if Yahoo will soon be the proud owner of the Tumbleblogging platform Tumblr (they paid a whopping 1.1 Billion USD for it). We’ve seen many of those acquisitions in the last years, Facebook bought Instagram, Google bought Youtube, Microsoft bought Skype, AOL bought ICQ (yeah this one is for the old farts like me). You could go on just summarizing those deals for quite a while.&lt;/p&gt;
&lt;p&gt;The reaction throughout the community always tends to be the same:&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;a href="http://tante.cc/wp-content/uploads/2013/05/367312_original.jpg"&gt;&lt;img src="http://tante.cc/wp-content/uploads/2013/05/367312_original-300x292.jpg" title="Host your own is cynical" height="292" width="300" alt="367312 original 300x292 Host your own is cynical" class="size-medium wp-image-1645 aligncenter" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Apart from a general preference for the small companies, the cool startups, the underdogs, every big company has screwed almost everyone in some way. They killed some service, they changed the TOS or something else about the service&lt;sup&gt;&lt;a title="and change is almost generally considered to be bad, until people get used to it " href="http://tante.cc/2013/05/20/host-your-own-is-cynical/#footnote_0_1642" id="identifier_0_1642" class="footnote-link footnote-identifier-link"&gt;1&lt;/a&gt;&lt;/sup&gt;. But to be fair: The track record of big companies buying smaller ones is horrible. The once cool and/or edgy services we love get reamed between corporate interests and strategies until the  thing we liked no longer exists. So a good deal of skepticism seems to be in order.&lt;/p&gt;
&lt;p&gt;After the first wave of “NOOOOOOO” we tend to get the usual blog posts about “hosting stuff yourself”.  I’ll try to summarize all of those blogposts words in a few words:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Relying on someone else to host your content? You are stupid. Just buy your own server, set up a web and a database server  and just run it all yourself. Here’s some code (which you cannot reasonably discern from a prayer to Cthulhu) .  It will  download some beatific package  onto your box and after incanting the following 37 other commands on your machine and investing about a week diving through howtos an manuals (each with at least one typo or mistake in them for fun and education) you might get your blog up and running to post something. Then you are self reliant and a useful citizen of the Internet. Running a mail server comes next.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Of course my description is highly biased and a little bit unfair (but where would be the fun in doing it otherwise). No wait, we call it &lt;em&gt;‘slightly exaggerated to make a point’&lt;/em&gt;. That sounds better.&lt;/p&gt;
&lt;p&gt;Hosting your infrastructure seems to resonate well with the whole DIY/maker movement we’ve been seeing lately: You can get all the tools and information to build basically everything online. So learn to sow, learn to solder, learn to tame a mountain lion!&lt;/p&gt;
&lt;p&gt;But there’s one thing people proposing this solution tend to forget: You are not the baseline. With the Internet having become mainstream most users don’t actually know how it works. Many don’t even know what “hosting” means, what a server is and why “The thingy that looks like a red furry thingy flying around the earth” is actually called “browser” and not “the Internet”. We ridicule them, refer to their problems as PEBKAC (Problem exists between keyboard and chair). We laugh at their incompetence, their blogs with flashy animated GIFs hosted on some ridiculously bad platform. And then we talk to our friends, all skilled and informed enough to run their own server, with enough time and money to keep in running, about how important running your own crap is. And they nod knowingly. Splendid strategy.&lt;/p&gt;
&lt;p&gt;We live in a society based in the so-called &lt;a href="http://en.wikipedia.org/wiki/Division_of_labour"&gt;division of labor&lt;/a&gt;: We are all specialists in something and completely clueless in other areas that still affect our lives in a big way. I for example know a lot about computers and software but I have no idea about cars and how to fix them. I don’t know gardening. I can cook but I can’t make my own clothes. Sure, if I stop doing the things I like (like writing this or building software) I could learn how to make my own shirts. But why? Others do it better and me buying their product offers them a chance to make a living (I tend to buy the majority of my clothes from fair trade companies). So why would I settle with shitty shirts I made myself?&lt;/p&gt;
&lt;p&gt;Making things easier to self-host is great and while it has had (and still has) its problems, Software like WordPress has made it a lot easier for many to self host. But that’s still far away from it being mainstream. And do we really want the world back where only the few people with the resources and skills can publish? I don’t think so.&lt;/p&gt;
&lt;p&gt;Telling people to “host your own” when some big company closes or buys a service is very similar to the princess who, when learning that the peasants had no bread, said: “Let them eat cake.”&lt;/p&gt;
&lt;p&gt;Hosting your own is a solution for the gifted and wealthy few, for many it’s blatant cynicism. You want to help people who have to rely on the big providers to host their posts, on some startup that is just waiting to be bought by one of the big players?&lt;/p&gt;
&lt;p&gt;Don’t tell them to host their own, find ways to get their stuff hosted aside from economical interests. Form collectives that host people’s blogs, find new ways to break the dependency of the general public on very few corporations. Everything else is just you telling the world how great you are and that your own skill set is the one skill set everybody needs.&lt;/p&gt;
&lt;ol class="footnotes"&gt;&lt;li id="footnote_0_1642" class="footnote"&gt;and change is almost generally considered to be bad, until people get used to it &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The post &lt;a href="http://tante.cc/2013/05/20/host-your-own-is-cynical/"&gt;“Host your own” is cynical&lt;/a&gt; appeared first on &lt;a href="http://tante.cc"&gt;tante.blog&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;a href="http://tante.cc/?flattrss_redirect&amp;amp;id=1642&amp;amp;md5=199716260e9717d4e01bded85785d664" target="_blank" title="Flattr"&gt;&lt;img src="http://the-gay-bar.com/wp-content/plugins/flattrss/img/flattr-badge-large.png" alt="flattr this!" /&gt;&lt;/a&gt;&lt;/p&gt;</description>
	<pubDate>Mon, 20 May 2013 12:46:13 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: A simple IPv6 setup</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1163</guid>
	<link>http://blog.siphos.be/2013/05/a-simple-ipv6-setup/</link>

	<description>&lt;p&gt;
For internal communication between guests on my workstation, I use IPv6 which is set up using the &lt;em&gt;Router Advertisement&lt;/em&gt; “feature” of IPv6. The tools I use are &lt;a href="http://www.thekelleys.org.uk/dnsmasq/doc.html"&gt;dnsmasq&lt;/a&gt; for DNS/DHCP and router advertisement support, and &lt;a href="http://roy.marples.name/projects/dhcpcd"&gt;dhcpcd&lt;/a&gt; as client. It might be a total mess (grew almost organically until it worked), but as far as I’m concerned, it is working… and that is all that matters (for now). I’ll have to look deeper into the IPv6 stuff to understand it all better though.
&lt;/p&gt;
&lt;p&gt;
On the client side, &lt;b&gt;dhcpcd&lt;/b&gt; is ran with the following options:
&lt;/p&gt;
&lt;pre&gt;dhcpcd_eth0="-t 5 -L --ipv6ra_own"
&lt;/pre&gt;
&lt;p&gt;
I had to enable &lt;tt&gt;--ipv6ra_own&lt;/tt&gt; to get it to obtain its global address, otherwise it only got its link local one (&lt;tt&gt;fe80::&lt;/tt&gt; something). I also added a hook into &lt;tt&gt;/lib/dhcpcd/dhcpcd-hooks&lt;/tt&gt; to get it to trigger a hostname update for IPv6.
&lt;/p&gt;
&lt;pre&gt;$ cat 28-set-ip6-address 
if $ifup; then export new_ip_address=${ra1_prefix%%/64}; fi
&lt;/pre&gt;
&lt;p&gt;
SELinux-policy wise, I had to enable &lt;tt&gt;dhcpc_t&lt;/tt&gt; to write to the hostname proc file and set the system hostname. The first one (21) is needed because of the &lt;tt&gt;--ipv6ra_own&lt;/tt&gt; parameter.
&lt;/p&gt;
&lt;pre&gt;# selocal -l | grep dhcpc_t
21: allow dhcpc_t self:rawip_socket create_socket_perms; # dhcpclient
22: kernel_rw_kernel_sysctl(dhcpc_t) # set hostname
23: allow dhcpc_t self:capability sys_admin; # set hostname
&lt;/pre&gt;
&lt;p&gt;
Finally, in &lt;tt&gt;/etc/dhcpcd.conf&lt;/tt&gt;, I removed the &lt;em&gt;nohook lookup-hostname&lt;/em&gt; and set the &lt;em&gt;force_hostname&lt;/em&gt; one:
&lt;/p&gt;
&lt;pre&gt;#nohook lookup-hostname
env force_hostname=YES
&lt;/pre&gt;
&lt;p&gt;
On the server side, I use the following configuration of dnsmasq (snippet):
&lt;/p&gt;
&lt;pre&gt;dhcp-range=2001:db8:81:e2::,ra-only
enable-ra
dhcp-option=option6:dns-server,[2001:db8:81:e2::26b5:365b:5072]
&lt;/pre&gt;
&lt;p&gt;
As you can see, I use the documentation prefix for now (since it is meant for internal communication only, and makes it easier to copy/paste into documentation ;-) but when I am going to use full IPv6 access to the Internet, this prefix will of course change.
&lt;/p&gt;
&lt;p&gt;
Finally, I enabled IPv6 forwarding on the &lt;tt&gt;tap0&lt;/tt&gt; interface because otherwise I continuously got the following messages on the clients:
&lt;/p&gt;
&lt;pre&gt;May 12 18:43:07 test dhcpcd[3869]: eth0: adding default route via fe80::d848:19ff:fe0d:55c2
May 12 18:43:07 test dhcpcd[3869]: eth0: fe80::d848:19ff:fe0d:55c2 is no longer a router
May 12 18:43:07 test dhcpcd[3869]: eth0: deleting default route via fe80::d848:19ff:fe0d:55c2
May 12 18:43:13 test dhcpcd[3869]: eth0: fe80::d848:19ff:fe0d:55c2 is unreachable, expiring it
&lt;/pre&gt;
&lt;p&gt;
To enable IPv6 forwarding, you can use sysctl but I added it in the script that sets up the tap0 interface:
&lt;/p&gt;
&lt;pre&gt;tunctl -b -u swift -t tap0
ifconfig tap0 add 2001:db8:81:e2::26b5:365b:5072/64
vde_switch --numports 16 --mod 777 --group users --tap tap0 -d
echo 1 &amp;gt; /proc/sys/net/ipv6/conf/tap0/forwarding
&lt;/pre&gt;</description>
	<pubDate>Mon, 20 May 2013 01:50:30 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: The weird “audit_access” permission</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1080</guid>
	<link>http://blog.siphos.be/2013/05/the-weird-audit_access-permission/</link>

	<description>&lt;p&gt;
While writing up the posts on capabilities, one thing I had in my mind was to give some additional information on frequently occurring denials, such as the &lt;em&gt;dac_override&lt;/em&gt; and &lt;em&gt;dac_read_search&lt;/em&gt; capabilities, and when they are triggered. For the DAC-related capabilities, policy developers often notice that these capabilities are triggered without a real need for them. So in the majority of cases, the policy developer wants to disable auditing of this:
&lt;/p&gt;
&lt;pre&gt;dontaudit &amp;lt;somedomain&amp;gt; self:capability { dac_read_search dac_override };
&lt;/pre&gt;
&lt;p&gt;
When applications wants to search through directories not owned by the user as which the application runs, &lt;em&gt;both&lt;/em&gt; capabilities will be checked – first the &lt;em&gt;dac_read_search&lt;/em&gt; one and, if that is denied (it will be audited though) then &lt;em&gt;dac_override&lt;/em&gt; is checked. If that one is denied as well, it too will be audited. That is why many developers automatically &lt;em&gt;dontaudit&lt;/em&gt; both capability calls if the application itself doesn’t really need the permission.
&lt;/p&gt;
&lt;p&gt;
Let’s say you allow this because the application needs it. But then another issue comes up when the application checks file attributes or access permissions (which is a second occurring denial that developers come across with). Such applications use &lt;em&gt;access()&lt;/em&gt; or &lt;em&gt;faccessat()&lt;/em&gt; to get information about files, but other than that don’t do anything with the files. When this occurs and the domain does not have read, write or execute permissions on the target, then the denial is shown even when the application doesn’t really read, write or execute the file.
&lt;/p&gt;
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;

int main(int argc, char ** argv) {
  printf("%s: Exists (%d), Readable (%d), Writeable (%d), Executable (%d)\n", argv[1],
    access(argv[1], F_OK), access(argv[1], R_OK),
    access(argv[1], W_OK), access(argv[1], X_OK));
}
&lt;/pre&gt;
&lt;pre&gt;$ check /var/lib/logrotate.status
/var/lib/logrotate.status: Exists (0), Readable (-1), Writeable (-1), Executable (-1)

$ tail -1 /var/log/audit.log
...
type=AVC msg=audit(1367400559.273:5224): avc:  denied  { read } for  pid=12270 comm="test" name="logrotate.status" dev="dm-3" ino=2849 scontext=staff_u:staff_r:staff_t tcontext=system_u:object_r:logrotate_var_lib_t tclass=file
&lt;/pre&gt;
&lt;p&gt;
This gives the impression that the application is doing nasty stuff, even when it is merely checking permissions. One way would be to dontaudit read as well, but if the application does the check against several files of various types, that might mean you need to include dontaudit statements for various domains. That by itself isn’t wrong, but perhaps you do not want to audit such checks but do want to audit real read attempts. This is what the &lt;em&gt;audit_access&lt;/em&gt; permission is for.
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://marc.info/?l=selinux&amp;amp;m=125349740623497&amp;amp;w=2"&gt;audit_access&lt;/a&gt; &lt;a href="http://marc.info/?l=selinux&amp;amp;m=127239846604513"&gt;permission&lt;/a&gt; is meant to be used only for &lt;em&gt;dontaudit&lt;/em&gt; statements: it has no effect on the security of the system itself, so using it in &lt;em&gt;allow&lt;/em&gt; statements has no effect. The purpose of the permission is to allow policy developers to not audit access checks without really dontauditing other, possibly malicious, attempts. In other words, checking the access can be dontaudited while actually attempting to use the access (reading, writing or executing the file) will still result in the proper denial.&lt;/p&gt;</description>
	<pubDate>Sun, 19 May 2013 01:50:01 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Commandline SELinux policy helper functions</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1147</guid>
	<link>http://blog.siphos.be/2013/05/commandline-selinux-policy-helper-functions/</link>

	<description>&lt;p&gt;
To work on SELinux policies, I use a couple of functions that I can call on the shell (command line): &lt;b&gt;seshowif&lt;/b&gt;, &lt;b&gt;sefindif&lt;/b&gt;, &lt;b&gt;seshowdef&lt;/b&gt; and &lt;b&gt;sefinddef&lt;/b&gt;. The idea behind the methods is that I want to search (&lt;em&gt;find&lt;/em&gt;) for an interface (&lt;em&gt;if&lt;/em&gt;) or definition (&lt;em&gt;def&lt;/em&gt;) that contains a particular method or call. Or, if I know what the interface or definition is, I want to see it (&lt;em&gt;show&lt;/em&gt;).
&lt;/p&gt;
&lt;p&gt;
For instance, to find the name of the interface that allows us to define file transitions from the &lt;tt&gt;postfix_etc_t&lt;/tt&gt; label:
&lt;/p&gt;
&lt;pre&gt;$ sefindif filetrans.*postfix_etc
contrib/postfix.if: interface(`postfix_config_filetrans',`
contrib/postfix.if:     filetrans_pattern($1, postfix_etc_t, $2, $3, $4)
&lt;/pre&gt;
&lt;p&gt;
Or to show the content of the &lt;em&gt;corenet_tcp_bind_http_port&lt;/em&gt; interface:
&lt;/p&gt;
&lt;pre&gt;$ seshowif corenet_tcp_bind_http_port
interface(`corenet_tcp_bind_http_port',`
        gen_require(`
                type http_port_t;
        ')

        allow $1 http_port_t:tcp_socket name_bind;
        allow $1 self:capability net_bind_service;
')
&lt;/pre&gt;
&lt;p&gt;
For the definitions, this is quite similar:
&lt;/p&gt;
&lt;pre&gt;$ sefinddef socket.*create
obj_perm_sets.spt:define(`create_socket_perms', `{ create rw_socket_perms }')
obj_perm_sets.spt:define(`create_stream_socket_perms', `{ create_socket_perms listen accept }')
obj_perm_sets.spt:define(`connected_socket_perms', `{ create ioctl read getattr write setattr append bind getopt setopt shutdown }')
obj_perm_sets.spt:define(`create_netlink_socket_perms', `{ create_socket_perms nlmsg_read nlmsg_write }')
obj_perm_sets.spt:define(`rw_netlink_socket_perms', `{ create_socket_perms nlmsg_read nlmsg_write }')
obj_perm_sets.spt:define(`r_netlink_socket_perms', `{ create_socket_perms nlmsg_read }')
obj_perm_sets.spt:define(`client_stream_socket_perms', `{ create ioctl read getattr write setattr append bind getopt setopt shutdown }')

$ seshowdef manage_files_pattern
define(`manage_files_pattern',`
        allow $1 $2:dir rw_dir_perms;
        allow $1 $3:file manage_file_perms;
')
&lt;/pre&gt;
&lt;p&gt;
I have these defined in my &lt;tt&gt;~/.bashrc&lt;/tt&gt; (they are simple &lt;a href="http://dev.gentoo.org/~swift/blog/01/selinux-funcs.txt"&gt;functions&lt;/a&gt;) and are used on a daily basis here ;-) If you want to learn a bit more on developing SELinux policies for Gentoo, make sure you read the &lt;a href="http://www.gentoo.org/proj/en/hardened/selinux-development.xml"&gt;Gentoo Hardened SELinux Development&lt;/a&gt; guide.&lt;/p&gt;</description>
	<pubDate>Sat, 18 May 2013 01:50:39 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Looking at the local Linux kernel privilege escalation</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1169</guid>
	<link>http://blog.siphos.be/2013/05/looking-at-the-local-linux-kernel-privilege-escalation/</link>

	<description>&lt;p&gt;
There has been a few posts already on the local Linux kernel privilege escalation, which has received the &lt;a href="https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-2094"&gt;CVE-2013-2094&lt;/a&gt; ID. &lt;a href="http://arstechnica.com/security/2013/05/critical-linux-vulnerability-imperils-users-even-after-silent-fix/"&gt;arstechnica&lt;/a&gt; has a write-up with links to good resources on the Internet, but I definitely want to point readers to the &lt;a href="http://www.reddit.com/r/netsec/comments/1eb9iw/sdfucksheeporgs_semtexc_local_linux_root_exploit/c9ykrck"&gt;explanation&lt;/a&gt; that Brad Spengler made on the vulnerability.
&lt;/p&gt;
&lt;p&gt;
In short, the vulnerability is an &lt;em&gt;out-of-bound&lt;/em&gt; access to an array within the Linux perf code (which is a performance measuring subsystem enabled when &lt;tt&gt;CONFIG_PERF_EVENTS&lt;/tt&gt; is enabled). This subsystem is often enabled as it offers a wide range of performance measurement techniques (see &lt;a href="https://perf.wiki.kernel.org/index.php/Main_Page"&gt;its wiki&lt;/a&gt; for more information). You can check on your own system through the kernel configuration (&lt;b&gt;zgrep CONFIG_PERF_EVENTS /proc/config.gz&lt;/b&gt; if you have the latter pseudo-file available – it is made available through &lt;tt&gt;CONFIG_IKCONFIG_PROC&lt;/tt&gt;).
&lt;/p&gt;
&lt;p&gt;
The public exploit maps memory in userland, fills it with known data, then triggers an out-of-bound decrement that tricks the kernel into decrementing this data (mapped in userland). By looking at where the decrement occurred, the exploit now knows the base address of the array. Next, it targets (through the same vulnerability) the IDT base (Interrupt Descriptor Table) and targets the overflow interrupt vector. It increments the top part of the address that the vector points to (which is 0xffffffff, becoming 0×00000000 thus pointing to the userland), maps this memory region itself with shellcode, and then triggers the overflow. The shell code used in the public exploit modifies the credentials of the current task, sets uid/gid with root and gives full capabilities, and then executes a shell.
&lt;/p&gt;
&lt;p&gt;
As Brad mentions, &lt;a href="https://grsecurity.net/~spender/uderef.txt"&gt;UDEREF&lt;/a&gt; (an option in a grSecurity enabled kernel) should mitigate the attempt to get to the userland. On my system, the exploit fails with the following (start of) oops (without affecting the system further) when it tries to close the file descriptor returned from the syscall that invokes the decrement:
&lt;/p&gt;
&lt;pre&gt;[ 1926.226678] PAX: please report this to pageexec@freemail.hu
[ 1926.227019] BUG: unable to handle kernel paging request at 0000000381f5815c
[ 1926.227019] IP: [&amp;lt;ffffffff811016ba&amp;gt;] sw_perf_event_destroy+0x1a/0xa0
[ 1926.227019] PGD 58a7c000 
[ 1926.227019] Thread overran stack, or stack corrupted
[ 1926.227019] Oops: 0002 [#4] PREEMPT SMP 
[ 1926.227019] Modules linked in: libcrc32c
[ 1926.227019] CPU 0 
[ 1926.227019] Pid: 4267, comm: test Tainted: G      D      3.8.7-hardened #1 Bochs Bochs
[ 1926.227019] RIP: 0010:[&amp;lt;ffffffff811016ba&amp;gt;]  [&amp;lt;ffffffff811016ba&amp;gt;] sw_perf_event_destroy+0x1a/0xa0
[ 1926.227019] RSP: 0018:ffff880058a03e08  EFLAGS: 00010246
...
&lt;/pre&gt;
&lt;p&gt;
The exploit also finds that the decrement didn’t succeed:
&lt;/p&gt;
&lt;pre&gt;test: semtex.c:76: main: Assertion 'i&amp;lt;0x0100000000/4' failed.
&lt;/pre&gt;
&lt;p&gt;
A second mitigation is that &lt;a href="http://pax.grsecurity.net/docs/PaXTeam-H2HC12-PaX-kernel-self-protection.pdf"&gt;KERNEXEC&lt;/a&gt; (also offered through grSecurity) which prevents the kernel from executing data that is writable (including userland data). So modifying the IDT would be mitigated as well.
&lt;/p&gt;
&lt;p&gt;
Another important mitigation is TPE – &lt;em&gt;Trusted Path Execution&lt;/em&gt;. This feature prevents the execution of binaries that are not located in a root-owned directory and owned by a trusted group (which on my system is 10 = wheel). So users attempting to execute such code will fail with a &lt;em&gt;Permission denied&lt;/em&gt; error, and the following is shown in the logs:
&lt;/p&gt;
&lt;pre&gt;[ 3152.165780] grsec: denied untrusted exec (due to not being in trusted group and file in non-root-owned directory) of /home/user/test by /home/user/test[bash:4382] uid/euid:1000/1000 gid/egid:100/100, parent /bin/bash[bash:4352] uid/euid:1000/1000 gid/egid:100/100
&lt;/pre&gt;
&lt;p&gt;
However, even though a nicely hardened system should be fairly immune against the currently circling public exploit, it should be noted that it is not immune against the vulnerability itself. The methods above mentioned make it so that that particular way of gaining root access is not possible, but it still allows an attacker to decrement and increment memory in specific locations so other exploits might be found to modify the system.
&lt;/p&gt;
&lt;p&gt;
Now out-of-bound vulnerabilities are not new. Recently (february this year), a &lt;a href="http://www.phoronix.com/scan.php?page=news_item&amp;amp;px=MTMxMTg"&gt;vulnerability&lt;/a&gt; in the networking code also provided an attack vector to get a local privilege escalation. A mandatory access control system like SELinux has little impact on such vulnerabilities if you allow users to execute their own code. Even confined users can modify the exploit to disable SELinux (since the shell code is ran with ring0 privileges it can access and modify the SELinux state information in the kernel).
&lt;/p&gt;
&lt;p&gt;
Many thanks to Brad for the excellent write-up, and to the &lt;a href="http://www.gentoo.org/proj/en/hardened"&gt;Gentoo Hardened&lt;/a&gt; team for providing the grSecurity PaX/TPE protections in its &lt;tt&gt;hardened-sources&lt;/tt&gt; kernel.&lt;/p&gt;</description>
	<pubDate>Fri, 17 May 2013 01:50:12 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Gentoo Hardened spring notes</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1220</guid>
	<link>http://blog.siphos.be/2013/05/gentoo-hardened-spring-notes/</link>

	<description>&lt;p&gt;
We got back together on the &lt;tt&gt;#gentoo-hardened&lt;/tt&gt; chat channel to discuss the progress of &lt;a href="http://www.gentoo.org/proj/en/hardened"&gt;Gentoo Hardened&lt;/a&gt;, so it’s time for another write-up of what was said.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Toolchain&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
GCC 4.8.1 will be out soon, although nothing major has occurred with it since the last meeting. There is a plugin header install problem in 4.8 and its not certain that the (trivial) fix is in 4.8.1, but it certainly is inside Gentoo’s release.
&lt;/p&gt;
&lt;p&gt;
Blueness is also (still, and hopefully for a long time ;-) maintaining the uclibc hardened related toolchain aspects.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Kernel and grSecurity/PaX&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
The further progress on the XATTR_PAX migration was put on a lower level the past few weeks due to busy, busy… very busy weeks (but this was announced and known in advance). We still need to do XATTR copying in &lt;em&gt;install&lt;/em&gt; for packages that do pax markings before &lt;em&gt;src_install()&lt;/em&gt; and include the &lt;tt&gt;user.pax&lt;/tt&gt; XATTR patch in the gentoo-sources kernel. This will silence the errors for non-hardened users and fix the loss of XATTR markings for those packages that do pax-mark before install.
&lt;/p&gt;
&lt;p&gt;
The set then needs to be documented further and tested on vanilla and hardened systems.
&lt;/p&gt;
&lt;p&gt;
Zorry asked if a separate script can be provided for those ebuilds that directly call &lt;b&gt;paxctl&lt;/b&gt;. These ebuilds might want to switch to the eclass, but if they need to call &lt;b&gt;paxctl&lt;/b&gt; or similar directly (for instance because the result is immediately used for further building), a separate script or tool should be made available. Blueness will look into this.
&lt;/p&gt;
&lt;p&gt;
On &lt;tt&gt;hardened-sources&lt;/tt&gt;, we are now with stable  2.6.32-r160, 3.2.42-r1 and 3.8.6 due to some vulnerabilities in earlier versions (in networking code). There is still some bug (nfs-related) that is fixed in 3.2.44 so that part might need a bump as well soon.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;SELinux&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://blog.siphos.be/2013/04/introducing-selocal-for-small-selinux-policy-enhancements/"&gt;selocal&lt;/a&gt; command is now available for Gentoo SELinux users, allowing them to easily enhance the policy without having to maintain their own SELinux policy modules (the script is a wrapper that does all that).
&lt;/p&gt;
&lt;p&gt;
The setools package now also uses the &lt;a href="http://blog.siphos.be/2013/04/sloting-the-old-swig-1/"&gt;SLOT’ed swig&lt;/a&gt;, so no more dependency breakage.
&lt;/p&gt;
&lt;p&gt;
On SELinux userspace and policy, both have seen a new release last month, and both are already in the Gentoo portage tree.
&lt;/p&gt;
&lt;p&gt;
Finally, the SELinux policy ebuilds now also call &lt;a href="http://blog.siphos.be/2013/05/overriding-the-default-selinux-policies/"&gt;epatch_user&lt;/a&gt; so users can customize the policies even further without having to copy ebuilds to their overlay.
&lt;/p&gt;
&lt;p&gt;
Now that &lt;b&gt;tar&lt;/b&gt; supports XATTR well, we might want to look into SELinux stages again. Jmbsvicetto did some work on that, but the builds failed during stage1. We’ll look into that later.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Integrity&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
Nothing much to say, we’re waiting a bit until the patches proposed by the IMA team are merged in the main kernel.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Profiles&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
Two no-multilib fixes have been applied to the &lt;tt&gt;hardened/amd64/no-multilib&lt;/tt&gt; profiles. One was a QA issue and quickly resolved, the other is due to the profile stacking within Gentoo profiles, where we missed a profile and thus were missing a few masks defined in that (missed) profile. But including the profile creates a lot of duplicates again, so we are going to copy the masks across until the duplicates are resolved in the other profiles.
&lt;/p&gt;
&lt;p&gt;
Blueness will also clean up the experimental &lt;tt&gt;13.0&lt;/tt&gt; directory since all hardened profiles now follow 13.0.
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Docs&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
The latest changes on SELinux have been added to the Gentoo SELinux handbook. Also, I’ve been slowly (but surely) adding topics to the &lt;a href="https://wiki.gentoo.org/wiki/SELinux/Tutorials"&gt;SELinux tutorials listing&lt;/a&gt; on the Gentoo wiki.
&lt;/p&gt;
&lt;p&gt;
The grSecurity 2 document is very much out of date, blueness hopes to put some time in fixing that soon.
&lt;/p&gt;
&lt;p&gt;
So that’s about it for the short write-up. Zorry will surely post the log later on the appropriate channels. Good work done (again) by all team members!&lt;/p&gt;</description>
	<pubDate>Thu, 16 May 2013 20:54:08 +0000</pubDate>
</item>
<item>
	<title>Steven Oliver: Programming is Terrible</title>
	<guid isPermalink="false">http://steveno.wordpress.com/2013/05/16/programming-is-terrible/</guid>
	<link>http://steveno.wordpress.com/2013/05/16/programming-is-terrible/</link>

	<description>&lt;img src="http://planet.larrythecow.org/images/StevenOliver3.png" alt="" align="right" style="float: right;"&gt;&lt;p&gt;&lt;span style="text-align: center; display: block;" class="embed-youtube"&gt;&amp;lt;iframe class="youtube-player" frameborder="0" height="390" src="http://www.youtube.com/embed/csyL9EC0S0c?version=3&amp;amp;amp;rel=1&amp;amp;amp;fs=1&amp;amp;amp;showsearch=0&amp;amp;amp;showinfo=1&amp;amp;amp;iv_load_policy=1&amp;amp;amp;wmode=transparent" type="text/html" width="640"&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/steveno.wordpress.com/1128/" rel="nofollow"&gt;&lt;img src="http://feeds.wordpress.com/1.0/comments/steveno.wordpress.com/1128/" alt="" border="0" /&gt;&lt;/a&gt; &lt;img width="1" alt="" src="http://stats.wordpress.com/b.gif?host=steveno.wordpress.com&amp;amp;blog=1231018&amp;amp;post=1128&amp;amp;subd=steveno&amp;amp;ref=&amp;amp;feed=1" border="0" height="1" /&gt;</description>
	<pubDate>Thu, 16 May 2013 17:42:25 +0000</pubDate>
</item>
<item>
	<title>Steven Oliver: Video on GObject bindings and Vala</title>
	<guid isPermalink="false">http://steveno.wordpress.com/2013/05/16/video-on-gobject-bindings-and-vala/</guid>
	<link>http://steveno.wordpress.com/2013/05/16/video-on-gobject-bindings-and-vala/</link>

	<description>&lt;img src="http://planet.larrythecow.org/images/StevenOliver3.png" alt="" align="right" style="float: right;"&gt;&lt;p&gt;&lt;span style="text-align: center; display: block;" class="embed-youtube"&gt;&amp;lt;iframe class="youtube-player" frameborder="0" height="390" src="http://www.youtube.com/embed/6QrGmA_RR4E?version=3&amp;amp;amp;rel=1&amp;amp;amp;fs=1&amp;amp;amp;showsearch=0&amp;amp;amp;showinfo=1&amp;amp;amp;iv_load_policy=1&amp;amp;amp;wmode=transparent" type="text/html" width="640"&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Tal Liron explaining how to generate&lt;br /&gt;
bindings (GObjectInstrospection bindings) for Vala&lt;/p&gt;
&lt;br /&gt;  &lt;a href="http://feeds.wordpress.com/1.0/gocomments/steveno.wordpress.com/1126/" rel="nofollow"&gt;&lt;img src="http://feeds.wordpress.com/1.0/comments/steveno.wordpress.com/1126/" alt="" border="0" /&gt;&lt;/a&gt; &lt;img width="1" alt="" src="http://stats.wordpress.com/b.gif?host=steveno.wordpress.com&amp;amp;blog=1231018&amp;amp;post=1126&amp;amp;subd=steveno&amp;amp;ref=&amp;amp;feed=1" border="0" height="1" /&gt;</description>
	<pubDate>Thu, 16 May 2013 14:00:54 +0000</pubDate>
</item>
<item>
	<title>Ciaran McCreesh: Paludis 1.4.0 Released</title>
	<guid isPermalink="false">http://ciaranm.wordpress.com/?p=1189</guid>
	<link>http://ciaranm.wordpress.com/2013/05/16/paludis-1-4-0-released/</link>

	<description>&lt;img src="http://planet.larrythecow.org/images/ciaranm.png" alt="" align="right" style="float: right;"&gt;&lt;p&gt;&lt;a href="http://paludis.exherbo.org/"&gt;Paludis&lt;/a&gt; 1.4.0 has been released:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tweaked ‘cave resolve’ output to add blank lines.&lt;/li&gt;
&lt;li&gt;Support for libarchive 3.1.2.&lt;/li&gt;
&lt;li&gt;Compatibility fixes for GCC 4.8.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;Filed under: &lt;a href="http://ciaranm.wordpress.com/category/paludis/paludis-releases/"&gt;paludis releases&lt;/a&gt; Tagged: &lt;a href="http://ciaranm.wordpress.com/tag/paludis/"&gt;paludis&lt;/a&gt; &lt;a href="http://feeds.wordpress.com/1.0/gocomments/ciaranm.wordpress.com/1189/" rel="nofollow"&gt;&lt;img src="http://feeds.wordpress.com/1.0/comments/ciaranm.wordpress.com/1189/" alt="" border="0" /&gt;&lt;/a&gt; &lt;img width="1" alt="" src="http://stats.wordpress.com/b.gif?host=ciaranm.wordpress.com&amp;amp;blog=3715284&amp;amp;post=1189&amp;amp;subd=ciaranm&amp;amp;ref=&amp;amp;feed=1" border="0" height="1" /&gt;</description>
	<pubDate>Thu, 16 May 2013 13:29:08 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Public support channels: irc</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1141</guid>
	<link>http://blog.siphos.be/2013/05/public-support-channels-irc/</link>

	<description>&lt;p&gt;
I’ve &lt;a href="http://blog.siphos.be/2012/12/why-would-paid-for-support-be-better/"&gt;said it&lt;/a&gt; before – support channels for free software are often (imo) superior to the commercial support that you might get with vendors. And although those vendors often try to use “modern” techniques, I fail to see why the old, but proven/stable methods would be wrong.
&lt;/p&gt;
&lt;p&gt;
Consider the “Chat with Support” feature that many vendors have on their site. Often, these services use a webbrowser, AJAX-driven method for talking with support engineers. The problem with this that I see is that it is difficult to keep track of the feedback you got over time (unless you manually copy/paste the information), and again that it isn’t public. With free software communities, we still often redirect such “online” support requests to IRC.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Internet Relay Chat&lt;/em&gt; has been around for ages (&lt;a href="https://en.wikipedia.org/wiki/IRC"&gt;1988&lt;/a&gt; according to wikipedia) and still quite active. Gentoo has all of its support channels on the &lt;a href="http://www.freenode.net"&gt;freenode&lt;/a&gt; IRC network: a community-driven, active &lt;tt&gt;#gentoo&lt;/tt&gt; channel with often crosses the 1000 users, a &lt;tt&gt;#gentoo-dev&lt;/tt&gt; development-related channel where many developers communicate, the &lt;tt&gt;#gentoo-hardened&lt;/tt&gt; channel for all questions and support regarding Gentoo Hardened specifics, etc.
&lt;/p&gt;
&lt;p&gt;
Using IRC has many advantages. One is that logs can be kept (either individually or by the project itself) that can be queried later by the people who want to provide support (to see if questions have already been popping up, see what the common questions are for the last few days, etc.) or get support (to see if their question was already answered in the past). Of course, these logs can be made public through web interfaces quite easily. For users, such log functionality is offered through the IRC client. Another very simple, yet interesting feature is &lt;em&gt;highlighting&lt;/em&gt;: give the set of terms for which you want to be notified (usually through a highlight and a specific notification in the client), making it easier to be on multiple channels without having to constantly follow-up on all discussions.
&lt;/p&gt;
&lt;p&gt;
Another advantage is that there is such a thing like “bots”. Most Gentoo related channels do not allow active bots on the channels except for the project-approved ones (such as &lt;em&gt;willikens&lt;/em&gt;). These bots can provide project-specific help to users and developers alike:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Give one-line information about bugs reported on bugzilla (id, assignee, status, but also the URL where the user/developer can view the bug etc.) &lt;/li&gt;
&lt;li&gt;Give meta information about a package (maintainer, herd, etc.), herd (members), GLSA details, dependency information, etc.
&lt;/li&gt;&lt;li&gt;
&lt;/li&gt;&lt;li&gt;Allow users to query if a developer is &lt;a href="https://dev.gentoo.org/devaway/"&gt;away&lt;/a&gt; or not&lt;/li&gt;
&lt;li&gt;Create notes (messages) for users that are not online yet but for which you know they come online later (and know their nickname or registered username)&lt;/li&gt;
&lt;li&gt;Notify when commits are made, or when tweets are sent that match a particular expression, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Furthermore, the IRC protocol has many features that are very interesting to use in free software communities as well. You can still do private chats (when potentially confidential data is exchanged) for instance, or even exchange files (although that is less common to use in free software communities). There is also still some hierarchy in case of abuse (channel operators can remove users from the chat or even ban them for a while) and one can even quiet a channel when for instance online team meetings are held (although using a different channel for that might be an alternative).
&lt;/p&gt;
&lt;p&gt;
IRC also has the advantage that connecting to the IRC channels has a very low requirement (software-wise): one can use console-only chat clients (in case users cannot get their graphical environment to work – example is irssi) or even &lt;a href="http://webchat.freenode.net/"&gt;webbrowser&lt;/a&gt; based ones (if one wants to chat from other systems). Even smartphones have good IRC applications, like &lt;a href="http://www.andchat.net/"&gt;AndChat&lt;/a&gt; for Android.
&lt;/p&gt;
&lt;p&gt;
IRC is also distributed: an IRC network consists of many interconnected servers who pass on all IRC traffic. If one node goes down, users can access a different node and continue. That makes IRC quite high-available. IRC network operators do need to try and keep the network from splitting (“netsplit”) which occurs when one part of the distributed network gets segregated from the other part and thus two “independent” IRC networks are formed. When that occurs, IRC operators will try to join them back as fast as possible. I’m not going to explain the details on this – it suffices to understand that IRC is a distributed manner and thus often much more available than the “support chat” sites that vendors provide.
&lt;/p&gt;
&lt;p&gt;
So although IRC looks archaic, it is a very good match for support channel requirements.&lt;/p&gt;</description>
	<pubDate>Thu, 16 May 2013 01:50:49 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Overriding the default SELinux policies</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1134</guid>
	<link>http://blog.siphos.be/2013/05/overriding-the-default-selinux-policies/</link>

	<description>&lt;p&gt;
Extending SELinux policies with additional rules is easy. As SELinux uses a &lt;em&gt;deny by default&lt;/em&gt; approach, all you need to do is to &lt;a href="https://wiki.gentoo.org/wiki/SELinux/Tutorials/Creating_your_own_policy_module_file"&gt;create a policy module&lt;/a&gt; that contains the additional (allow) rules, load that and you’re all set. But what if you want to remove some rules?
&lt;/p&gt;
&lt;p&gt;
Well, sadly, SELinux does not support deny rules. Once an allow rule is loaded in memory, it cannot be overturned anymore. Yes, you can disable the module itself that provides the rules, but you cannot selectively disable rules. So what to do?
&lt;/p&gt;
&lt;p&gt;
Generally, you can disable the module that contains the rules you want to disable, and load a custom module that defines everything the original module did, except for those rules you don’t like. For instance, if you do not want the &lt;tt&gt;skype_t&lt;/tt&gt; domain to be able to read/write to the video device, create your own skype-providing module (&lt;em&gt;myskype&lt;/em&gt;) with the exact same content (except for the module name at the first line) as the original skype module, except for the video device:
&lt;/p&gt;
&lt;pre&gt;dev_read_sound(skype_t)
# dev_read_video_dev(skype_t)
dev_write_sound(skype_t)
# dev_write_video_dev(skype_t)
&lt;/pre&gt;
&lt;p&gt;
Load in this policy, and you now have the &lt;tt&gt;skype_t&lt;/tt&gt; domain without the video access. You will get post-install failures when Gentoo pushes out an update to the policy though, since it will attempt to reload the &lt;tt&gt;skype.pp&lt;/tt&gt; file (through the &lt;tt&gt;selinux-skype&lt;/tt&gt; package) and fail because it declares types and attributes already provided (by &lt;em&gt;myskype&lt;/em&gt;). You can &lt;a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=3&amp;amp;chap=5#doc_chap1"&gt;exclude the package&lt;/a&gt; from being updated, which works as long as no packages depend on it. Or live with the post-install failure ;-) But there might be a simpler approach: &lt;em&gt;epatch_user&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
Recently, I added in support for &lt;em&gt;epatch_user&lt;/em&gt; in the policy ebuilds. This allows users to create patches against the policy source code that we use and put them in &lt;tt&gt;/etc/portage/patches&lt;/tt&gt; in the directory of the right category/package. For module patches, the working directory used is within the &lt;tt&gt;policy/modules&lt;/tt&gt; directory of the policy checkout. For base, it is below the policy checkout (in other words, the patch will need to use the &lt;tt&gt;refpolicy/&lt;/tt&gt; directory base). But because of how &lt;em&gt;epatch_user&lt;/em&gt; works, any patch taken from the base will work as it will start stripping directories up to the fourth one.
&lt;/p&gt;
&lt;p&gt;
This approach is also needed if you want to exclude rules from interfaces rather than from the &lt;tt&gt;.te&lt;/tt&gt; file: create a small patch and put it in &lt;tt&gt;/etc/portage/patches&lt;/tt&gt; for the &lt;tt&gt;sec-policy/selinux-base&lt;/tt&gt; package (as this provides the interfaces).&lt;/p&gt;</description>
	<pubDate>Wed, 15 May 2013 01:50:42 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Highlevel assessment of Cdorked and Gentoo Hardened/SELinux</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1152</guid>
	<link>http://blog.siphos.be/2013/05/highlevel-assessment-of-cdorked-and-gentoo-hardenedselinux/</link>

	<description>&lt;p&gt;
With all the &lt;a href="http://www.welivesecurity.com/2013/05/07/linuxcdorked-malware-lighttpd-and-nginx-web-servers-also-affected/"&gt;reports&lt;/a&gt; surrounding &lt;a href="https://threatpost.com/attack-using-backdoored-apache-binaries-to-lead-to-blackhole-kit/"&gt;Cdorked&lt;/a&gt;, I took a look at if SELinux and/or other Gentoo Hardened technologies could reduce the likelihood that this infection occurs on your system.
&lt;/p&gt;
&lt;p&gt;
First of all, we don’t know yet how the malware gets installed on the server. We do know that the Apache binaries themselves are modified, so the first thing to look at is to see if this risk can be reduced. Of course, using an intrusion detection system like &lt;a href="https://wiki.gentoo.org/wiki/AIDE"&gt;AIDE&lt;/a&gt; helps, but even with Gentoo’s &lt;b&gt;qcheck&lt;/b&gt; command you can test the integrity of the files:
&lt;/p&gt;
&lt;pre&gt;# qcheck www-servers/apache
Checking www-servers/apache-2.2.24 ...
  * 424 out of 424 files are good
&lt;/pre&gt;
&lt;p&gt;
If the binary is modified, this would result in something equivalent to:
&lt;/p&gt;
&lt;pre&gt;Checking www-servers/apache-2.2.24 ...
 MD5-DIGEST: /usr/sbin/apache2
  * 423 out of 424 files are good
&lt;/pre&gt;
&lt;p&gt;
I don’t know if the modified binary would otherwise work just fine, I have not been able to find exact details on the infected binary to (in a sandbox environment of course) analyze this further. Also, because we don’t know how they are installed, it is not easy to know if binaries that you built yourself are equally likely to be modified/substituted or if the attack checks checksums of the binaries against a known list.
&lt;/p&gt;
&lt;p&gt;
Assuming that it would run, then the infecting malware would need to set the proper SELinux context on the file (if it overwrites the existing binary, then the context is retained, otherwise it gets the default context of &lt;tt&gt;bin_t&lt;/tt&gt;). If the context is wrong, then starting Apache results in:
&lt;/p&gt;
&lt;pre&gt;apache2: Syntax error on line 61 of /etc/apache2/httpd.conf: Cannot load /usr/lib64/apache2/modules/mod_actions.so into server: /usr/lib64/apache2/modules/mod_actions.so: cannot open shared object file: Permission denied
&lt;/pre&gt;
&lt;p&gt;
This is because the modified binary stays in the calling domain context (&lt;tt&gt;initrc_t&lt;/tt&gt;). If you use a targeted policy, then this will not present itself as &lt;tt&gt;initrc_t&lt;/tt&gt; is an unconfined domain. But with strict policies, &lt;tt&gt;initrc_t&lt;/tt&gt; is not allowed to read &lt;tt&gt;httpd_modules_t&lt;/tt&gt;. Even worse, the remainder of SELinux protections don’t apply anymore, since with unconfined domains, all bets are off. That is why Gentoo focuses this hard on using a strict policy.
&lt;/p&gt;
&lt;p&gt;
So, what if the binary runs in the proper domain? Well then, from the articles I read, the malware can do a reverse connect. That means that the domain will attempt to connect to an IP address provided by the attacker (in a specifically crafted URL). For SELinux, this means that the &lt;em&gt;name_connect&lt;/em&gt; permission is checked:
&lt;/p&gt;
&lt;pre&gt;# sesearch -s httpd_t -c tcp_socket -p name_connect -ACTS
Found 20 semantic av rules:
   allow nsswitch_domain dns_port_t : tcp_socket { name_connect } ; 
DT allow httpd_t port_type : tcp_socket { name_connect } ; [ httpd_can_network_connect ]
DT allow httpd_t ftp_port_t : tcp_socket { name_connect } ; [ httpd_can_network_relay ]
DT allow httpd_t smtp_port_t : tcp_socket { name_connect } ; [ httpd_can_sendmail ]
DT allow httpd_t postgresql_port_t : tcp_socket { name_connect } ; [ httpd_can_network_connect_db ]
DT allow httpd_t oracledb_port_t : tcp_socket { name_connect } ; [ httpd_can_network_connect_db ]
DT allow httpd_t squid_port_t : tcp_socket { name_connect } ; [ httpd_can_network_relay ]
DT allow httpd_t mssql_port_t : tcp_socket { name_connect } ; [ httpd_can_network_connect_db ]
DT allow httpd_t kerberos_port_t : tcp_socket { name_connect } ; [ allow_kerberos ]
DT allow nsswitch_domain ldap_port_t : tcp_socket { name_connect } ; [ authlogin_nsswitch_use_ldap ]
DT allow httpd_t http_cache_port_t : tcp_socket { name_connect } ; [ httpd_can_network_relay ]
DT allow httpd_t http_port_t : tcp_socket { name_connect } ; [ httpd_can_network_relay ]
DT allow httpd_t http_port_t : tcp_socket { name_connect } ; [ httpd_graceful_shutdown ]
DT allow httpd_t mysqld_port_t : tcp_socket { name_connect } ; [ httpd_can_network_connect_db ]
DT allow httpd_t ocsp_port_t : tcp_socket { name_connect } ; [ allow_kerberos ]
DT allow nsswitch_domain kerberos_port_t : tcp_socket { name_connect } ; [ allow_kerberos ]
DT allow httpd_t pop_port_t : tcp_socket { name_connect } ; [ httpd_can_sendmail ]
DT allow nsswitch_domain ocsp_port_t : tcp_socket { name_connect } ; [ allow_kerberos ]
DT allow httpd_t gds_db_port_t : tcp_socket { name_connect } ; [ httpd_can_network_connect_db ]
DT allow httpd_t gopher_port_t : tcp_socket { name_connect } ; [ httpd_can_network_relay ]
&lt;/pre&gt;
&lt;p&gt;
So by default, the Apache (&lt;tt&gt;httpd_t&lt;/tt&gt;) domain is allowed to connect to DNS port (to resolve hostnames). All other &lt;em&gt;name_connect&lt;/em&gt; calls depend on SELinux booleans (mentioned after it) that are by default disabled (at least on Gentoo). Disabling hostname resolving is not really feasible, so if the attacker uses a DNS port as port that the malware needs to connect to, SELinux will not deny it (unless you use additional networking constraints).
&lt;/p&gt;
&lt;p&gt;
Now, the reverse connect is an interesting feature of the malware, but not the main one. The main focus of the malware is to redirect customers to particular sites that can trick the user in downloading additional (client) malware. Because this is done internally within Apache, SELinux cannot deal with this. As a user, make sure you configure your browser not to trust non-local iframes and such (always do this, not just because there is a possible threat right now). The configuration of Cdorked is a shared memory segment of Apache itself. Of course, since Apache uses shared memory, the malware embedded within will also have access to the shared memory. However, if this shared memory would need to be accessed by third party applications (the malware seems to grant read/write rights on everybody to this segment) SELinux will prevent this:
&lt;/p&gt;
&lt;pre&gt;# sesearch -t httpd_t -c shm -ACTS
Found 2 semantic av rules:
   allow unconfined_domain_type domain : shm { create destroy getattr setattr read write associate unix_read unix_write lock } ; 
   allow httpd_t httpd_t : shm { create destroy getattr setattr read write associate unix_read unix_write lock } ; 
&lt;/pre&gt;
&lt;p&gt;
Only unconfined domains and the &lt;tt&gt;httpd_t&lt;/tt&gt; domain itself have access to &lt;tt&gt;httpd_t&lt;/tt&gt; labeled shared memory.
&lt;/p&gt;
&lt;p&gt;
So what about IMA/EVM? Well, those will not help here since IMA checks for integrity of files that were modified &lt;em&gt;offline&lt;/em&gt;. As the modification of the Apache binaries is most likely done online, IMA would just accept this.
&lt;/p&gt;
&lt;p&gt;
For now, it seems that a good system integrity approach is the most effective until we know more about how the malware-infected binary is written to the system in the first place (as this is better protected by MAC controls like SELinux).&lt;/p&gt;</description>
	<pubDate>Tue, 14 May 2013 01:50:01 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: SECMARK and SELinux</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1113</guid>
	<link>http://blog.siphos.be/2013/05/secmark-and-selinux/</link>

	<description>&lt;p&gt;
When using SECMARK, the administrator configures the &lt;b&gt;iptables&lt;/b&gt; or &lt;b&gt;netfilter&lt;/b&gt; rules to add a label to the packet data structure (on the host itself) that can be governed through SELinux policies. Unlike peer labeling, here the labels assigned to the network traffic is completely locally defined. Consider the following command:
&lt;/p&gt;
&lt;pre&gt;# iptables -t mangle -A INPUT -p tcp --src 192.168.1.2 --dport 443
  -j SECMARK --selctx system_u:object_r:myauth_packet_t
&lt;/pre&gt;
&lt;p&gt;
With this command, packets that originate from the &lt;em&gt;192.168.1.2&lt;/em&gt; host and arrive on port 443 (typically used for HTTPS traffic) are marked as &lt;tt&gt;myauth_packet_t&lt;/tt&gt;. SELinux policy writers can then allow domains to receive this type of packets (or send) through the &lt;em&gt;packet&lt;/em&gt; class:
&lt;/p&gt;
&lt;pre&gt;# Allow sockets with mydomain_t context to receive packets labeled myauth_packet_t
allow mydomain_t myauth_packet_t:packet recv;
&lt;/pre&gt;
&lt;p&gt;
The SELinux policy modules enable this through the &lt;em&gt;corenet_sendrecv_&amp;lt;type&amp;gt;_{client,server}_packets&lt;/em&gt; interfaces:
&lt;/p&gt;
&lt;pre&gt;corenet_sendrecv_http_client_packets(mybrowser_t)
# allow mybrowser_t http_client_packet_t:packet { send recv };
&lt;/pre&gt;
&lt;p&gt;
As a common rule, packets are marked as client packets or server packets, depending on the role of the &lt;em&gt;domain&lt;/em&gt;. In the above example, the domain is a browser, so acts as a web client. So, it needs to send and receive &lt;tt&gt;http_client_packet_t&lt;/tt&gt;. A web server on the other hand would need to send and receive &lt;tt&gt;http_server_packet_t&lt;/tt&gt;. Note that the packets that are sent over the wire do not have any labels assigned to them – this is all local to the system. So even when the source and destination use SELinux with SECMARK, on the source server the packets might be labeled as &lt;tt&gt;http_client_packet_t&lt;/tt&gt; whereas on the target they are seen as &lt;tt&gt;http_server_packet_t&lt;/tt&gt;.
&lt;/p&gt;
&lt;p&gt;
As far as I know, when you want to use SECMARK, you will need to set the contexts with &lt;b&gt;iptables&lt;/b&gt; yourself (there is no default labeling), so knowing about the above convention is important.
&lt;/p&gt;
&lt;p&gt;
Again, Paul Moore has &lt;a href="http://paulmoore.livejournal.com/4281.html"&gt;more information&lt;/a&gt; about this.&lt;/p&gt;</description>
	<pubDate>Mon, 13 May 2013 01:50:19 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Peer labeling in SELinux policy</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1107</guid>
	<link>http://blog.siphos.be/2013/05/peer-labeling-in-selinux-policy/</link>

	<description>&lt;p&gt;
Allow me to start with an important warning: I don’t have much hands-on experience with the remainder of this post. Its based on the few resources I found on the Internet and a few tests done locally which I’ve investigated in my attempt to understand SELinux policy writing for networking stuff.
&lt;/p&gt;
&lt;p&gt;
So, with that out of the way, let’s look into &lt;em&gt;peer labeling&lt;/em&gt;. As mentioned in my &lt;a href="http://blog.siphos.be/2013/05/selinux-policy-and-network-controls/"&gt;previous post&lt;/a&gt;, SELinux supports some more advanced networking security features than the default socket restrictions. I mentioned SECMARK and NetLabel before, but NetLabel is actually part of the family of &lt;em&gt;peer&lt;/em&gt; labeling technologies.
&lt;/p&gt;
&lt;p&gt;
With this technology approach, all participating systems in the network must support the same labeling method. NetLabel supports CIPSO (&lt;a href="https://tools.ietf.org/html/draft-ietf-cipso-ipsecurity-01"&gt;Commerial IP Security Option&lt;/a&gt;) where hosts label their network traffic to be part of a particular “Domain of Interpretation”. The labels are used by the hosts to identify where a packet should be for. NetLabel, within Linux, is then used to translate those CIPSO labels. SELinux itself labels the incoming sockets based on the NetLabel information and the context of the listening socket, resulting in a context that is governed policy-wise through the &lt;em&gt;peer&lt;/em&gt; class. Since this is based on the information in the packet instead of defined on the system itself, this allows remote systems to have a say in how the packets are labeled.
&lt;/p&gt;
&lt;p&gt;
Another peer technology is the &lt;em&gt;Labeled IPSec&lt;/em&gt; one. In this case the labels are fully provided by the remote system. I think they are based on the security association within the IPSec setup.
&lt;/p&gt;
&lt;p&gt;
In both cases, in the SELinux policies, three definitions are important to keep an eye out on: &lt;em&gt;interface&lt;/em&gt; definitions, &lt;em&gt;node&lt;/em&gt; definitions and &lt;em&gt;peer&lt;/em&gt; definitions.
&lt;/p&gt;
&lt;p&gt;
Interface definitions allow users to (mainly) set the sensitivity that is allowed to pass the interface. Using &lt;b&gt;semanage interface&lt;/b&gt; this can be controlled by the user. One can also assign a different context to the interface – by default, this is &lt;tt&gt;netif_t&lt;/tt&gt;. The permissions that are checked on the traffic is &lt;em&gt;ingress&lt;/em&gt; (incoming) and &lt;em&gt;egress&lt;/em&gt; (outgoing) traffic, and most policies set this through the following call (comment shows the underlying SELinux rules, where &lt;em&gt;tcp_send&lt;/em&gt; and &lt;em&gt;tcp_recv&lt;/em&gt; are – I think – obsolete):
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_sendrecv_generic_if(something_t)
# allow something_t netif_t:netif { tcp_send tcp_recv egress ingress };
&lt;/pre&gt;
&lt;p&gt;
Node definitions define which targets (nodes, which can be IP addresses or subnets) traffic meant for a particular socket is allow to originate from (&lt;em&gt;recvfrom&lt;/em&gt;) or sent to (&lt;em&gt;sendto&lt;/em&gt;). Again, users can define their own node types and manage them using &lt;b&gt;semanage node&lt;/b&gt;. The default node I already covered in the previous post (&lt;tt&gt;node_t&lt;/tt&gt;) and is allowed by most policies by default through the following call (where the &lt;em&gt;tcp_send&lt;/em&gt; and &lt;em&gt;tcp_recv&lt;/em&gt; are probably deprecated as well):
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_sendrecv_generic_node(something_t)
# allow something_t node_t:node { tcp_send tcp_recv sendto recvfrom };
&lt;/pre&gt;
&lt;p&gt;
Finally, peer definitions are based on the labels from the traffic. If the system uses NetLabel, then the target label will always be &lt;tt&gt;netlabel_peer_t&lt;/tt&gt; since the workings of CIPSO are mainly (only?) mapped towards sensitivity labels (in MLS policy). As a result, SELinux always displays the peer as being &lt;tt&gt;netlabel_peer_t&lt;/tt&gt;. In case of Labeled IPSec, this isn’t the case as the peer label is transmitted by the peer itself.
&lt;/p&gt;
&lt;p&gt;
For NetLabel support, policies generally include two methods – one is to support unlabeled traffic (only needed the moment you have support for labeled traffic) and one is to allow the NetLabel’ed traffic:
&lt;/p&gt;
&lt;pre&gt;corenet_all_recvfrom_unlabeled(something_t)
# allow something_t unlabeled_t:peer recv;
corenet_all_recvfrom_netlabel(something_t)
# allow something_t netlabel_peer_t:peer recv;
&lt;/pre&gt;
&lt;p&gt;
In case of IPSec for instance, the peer will have a provided label, as is shown by the call for accepting hadoop traffic:
&lt;/p&gt;
&lt;pre&gt;hadoop_recvfrom(something_t)
# allow something_t hadoop_t:peer recv;
&lt;/pre&gt;
&lt;p&gt;
However, this alone is not sufficient for labeled IPSec. We also need to allow the domain to be allowed to send anything towards an IPSec security association. There is an interface called &lt;em&gt;corenet_tcp_recvfrom_labeled&lt;/em&gt; that takes two arguments which, amongst other things, enables &lt;em&gt;sendto&lt;/em&gt; towards its association.
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_recvfrom_labeled(some_t, thing_t)
# allow { some_t thing_t} self:association sendto;
# allow some_t thing_t:peer recv;
# allow thing_t some_t:peer recv;
# corenet_tcp_recvfrom_netlabel(some_t)
# corenet_tcp_recvfrom_netlabel(thing_t)
&lt;/pre&gt;
&lt;p&gt;
This interface is usually called within a &lt;em&gt;*_tcp_connect()&lt;/em&gt; interface for a particular domain, like with the &lt;em&gt;mysql_tcp_connect&lt;/em&gt; example:
&lt;/p&gt;
&lt;pre&gt;interface(`mysql_tcp_connect',`
        gen_require(`
                type mysqld_t;
        ')

        corenet_tcp_recvfrom_labeled($1, mysqld_t)
        corenet_tcp_sendrecv_mysqld_port($1) # deprecated
        corenet_tcp_connect_mysqld_port($1)
        corenet_sendrecv_mysqld_client_packets($1)
')
&lt;/pre&gt;
&lt;p&gt;
When using peer labeling, the domain that is allowed something is based on the socket context of the application. Also, the rules when using peer labeling are &lt;em&gt;in addition to&lt;/em&gt; the rules mentioned before (“standard” networking control): &lt;em&gt;name_bind&lt;/em&gt; and &lt;em&gt;name_connect&lt;/em&gt; are always checked.
&lt;/p&gt;
&lt;p&gt;
For more information, make sure you check &lt;a href="http://paulmoore.livejournal.com"&gt;Paul Moore’s blog&lt;/a&gt;, such as the &lt;a href="http://paulmoore.livejournal.com/2128.html?nojs=1"&gt;egress/ingress&lt;/a&gt; information. And if you know of resources that show this in a more practical setting (above is mainly to work with the SELinux policy) I’m all ears.&lt;/p&gt;</description>
	<pubDate>Sun, 12 May 2013 01:50:42 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: SELinux policy and network controls</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1096</guid>
	<link>http://blog.siphos.be/2013/05/selinux-policy-and-network-controls/</link>

	<description>&lt;p&gt;
Let’s talk about how SELinux governs network streams (and how it reflects this into the policy).
&lt;/p&gt;
&lt;p&gt;
When you don’t do fancy stuff like SECMARK or netlabeling, then the classes that you should keep an eye on are &lt;em&gt;tcp_socket&lt;/em&gt; and &lt;em&gt;udp_socket&lt;/em&gt; (depending on the protocol). There used to be &lt;em&gt;node&lt;/em&gt; and &lt;em&gt;netif&lt;/em&gt; as well, but the support (enforcement) for these have been &lt;a href="http://lists.openwall.net/netdev/2009/03/27/144"&gt;removed a while ago&lt;/a&gt; for the “old style” network control enforcement. The concepts are still available though, and I believe they take effect when netlabeling is used. But let’s first look at the regular networking aspects.
&lt;/p&gt;
&lt;p&gt;
The idea behind the regular network related permissions are that you define either daemon-like behavior (which “binds” to a port) or client-like behavior (which “connects” to a port). Consider an FTP daemon (domain &lt;tt&gt;ftpd_t&lt;/tt&gt;) versus FTP client (example domain &lt;tt&gt;ncftp_t&lt;/tt&gt;).
&lt;/p&gt;
&lt;p&gt;
In case of a daemon, the policy would contain the following (necessary) rules:
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_bind_generic_node(ftpd_t) # Somewhat legacy but still needed
corenet_tcp_bind_ftp_port(ftpd_t)
corenet_tcp_bind_ftp_data_port(ftpd_t)
corenet_tcp_bind_all_unreserved_ports(ftpd_t) # In case of passive mode
&lt;/pre&gt;
&lt;p&gt;
This gets translated to the following “real” SELinux statements:
&lt;/p&gt;
&lt;pre&gt;allow ftpd_t node_t:tcp_socket node_bind;
allow ftpd_t ftp_port_t:tcp_socket name_bind;
allow ftpd_t ftp_data_port_t:tcp_socket name_bind;
allow ftpd_t unreserved_port_type:tcp_socket name_bind;
&lt;/pre&gt;
&lt;p&gt;
I mention that &lt;em&gt;corenet_tcp_bind_generic_node&lt;/em&gt; as being somewhat legacy. When you use netlabeling, you can define different nodes (a “node” in that case is a label assigned to an IP address or IP subnet) and as such define policy-wise where daemons can bind on (or clients can connect to). However, without netlabel, the only node that you get to work with is &lt;tt&gt;node_t&lt;/tt&gt; which represents any possible node. Also, the use of passive mode within the ftp policy is governed through the &lt;em&gt;ftpd_use_passive_mode&lt;/em&gt; boolean.
&lt;/p&gt;
&lt;p&gt;
For a client, the following policy line would suffice:
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_connect_ftp_port(ncftp_t)
# allow ncftp_t ftp_port_t:tcp_socket name_connect;
&lt;/pre&gt;
&lt;p&gt;
Well, I lied. Because of how FTP works, if you use active connections, you need to allow the client to bind on an unreserved port, and allow the server to connect to unreserved ports (cfr code snippet below), but you get the idea.
&lt;/p&gt;
&lt;pre&gt;corenet_tcp_connect_all_unreserved_ports(ftpd_t)

corenet_tcp_bind_generic_node(ncftp_t)
corenet_tcp_bind_all_unreserved_ports(ncftp_t)
&lt;/pre&gt;
&lt;p&gt;
In the past, policy developers also had to include other lines, but these have by time become obsolete (&lt;em&gt;corenet_tcp_sendrecv_ftp_port&lt;/em&gt; for instance). These methods defined the ability to send and receive messages on the port, but this is no longer controlled this way. If you need such controls, you will need to look at SELinux and SECMARK (which uses packets with the &lt;em&gt;packet&lt;/em&gt; class) or netlabel (which uses the &lt;em&gt;peer&lt;/em&gt; class and peer types to send or receive messages from).
&lt;/p&gt;
&lt;p&gt;
And that’ll be for a different post.&lt;/p&gt;</description>
	<pubDate>Sat, 11 May 2013 01:50:08 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Gentoo metadata support for CPE</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1126</guid>
	<link>http://blog.siphos.be/2013/05/gentoo-metadata-support-for-cpe/</link>

	<description>&lt;p&gt;
Recently, the &lt;tt&gt;metadata.xml&lt;/tt&gt; file syntax definition (the DTD for those that know a bit of XML) has been updated to support CPE definitions. A &lt;a href="https://nvd.nist.gov/cpe.cfm"&gt;CPE&lt;/a&gt; (Common Platform Enumeration) is an identifier that &lt;a href="http://cpe.mitre.org/specification/index.html"&gt;describes&lt;/a&gt; an application, operating system or hardware device using its vendor, product name, version, update, edition and language. This CPE information is used in the CVE releases (Common Vulnerabilities and Exposures) – announcements about vulnerabilities in applications, operating systems or hardware. Not all security vulnerabilities are assigned a CVE number, but this is as close as you get towards a (public) elaborate dictionary of vulnerabilities.
&lt;/p&gt;
&lt;p&gt;
By allowing Gentoo package maintainers to enter (part of) the CPE information in the &lt;tt&gt;metadata.xml&lt;/tt&gt; file, applications that parse the CVE information can now more easily match if software installed on Gentoo is related to a CVE. I had a &lt;a href="http://blog.siphos.be/2013/04/matching-packages-with-cves/"&gt;related post&lt;/a&gt; to this not that long ago on my blog and I’m glad this change has been made. With this information at hand, we can start feeding CPE information to the packages and then easily match this with CVEs.
&lt;/p&gt;
&lt;p&gt;
I had a request to “provide” the scripts I used for the previous post. Mind you, these are taking too many assumptions (and probably wrong ones) for now (and I’m not really planning on updating them as I have different methods for getting information related to CVEs), but I’m planning on integrating CPE data in Gentoo’s packages more and then create a small script that generates a “watchlist” that I can feed to &lt;a href="http://cvechecker.sourceforge.net"&gt;cvechecker&lt;/a&gt;. But anyway, here are the scripts.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://dev.gentoo.org/~swift/blog/01/0_createcve.txt"&gt;First&lt;/a&gt;, I took all CVE information and put it in a simple CSV file. The CSV is the same one used by cvechecker, so check out the application to see where it fetches the data from (there is a CVE RSS feed and a simple XSL transformation). &lt;a href="http://dev.gentoo.org/~swift/blog/01/1_createhitlist.txt"&gt;Second&lt;/a&gt;, I create a “hitlist” which generates the CPEs. With the recent change to &lt;tt&gt;metadata.xml&lt;/tt&gt; this step can be simplified a lot. &lt;a href="http://dev.gentoo.org/~swift/blog/01/2_matchcve.txt"&gt;Third&lt;/a&gt;, I try to match the CPE data with the CVE data, depending on a given time delay of commits. In other words, you can ask possible CVE fixes for commits made in the last few XXX days.&lt;/p&gt;</description>
	<pubDate>Fri, 10 May 2013 01:50:51 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Enabling Kernel Samepage Merging (KSM)</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1091</guid>
	<link>http://blog.siphos.be/2013/05/enabling-kernel-samepage-merging-ksm/</link>

	<description>&lt;p&gt;
When using virtualization extensively, you will pretty soon hit the limits of your system (at least, the resources on it). When the virtualization is used primarily for testing (such as in my case), the limit is memory. So it makes sense to seek memory optimization strategies on such systems. The first thing to enable is KSM or &lt;em&gt;Kernel Samepage Merging&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
This Linux feature looks for memory pages that the applications have marked as being a possible candidate for optimization (sharing) which are then reused across multiple processes. The idea is that, especially for virtualized environments (but KSM is not limited to that), some processes will have the same contents in memory. Without any sharing abilities, these memory pages will be unique (meaning at different locations in your system’s memory). With KSM, such memory pages are consolidated to a single page which is then referred to by the various processes. When one process wants to modify the page, it is “unshared” so that there is no corruption or unwanted modification of data for the other processes.
&lt;/p&gt;
&lt;p&gt;
Such features are not new – VMWare has it named TPS (&lt;em&gt;Transparent Page Sharing&lt;/em&gt;) and Xen calls it “Memory CoW” (Copy-on-Write). One advantage of KSM is that it is simple to setup and advantageous for other processes as well. For instance, if you host multiple instances of the same service (web service, database, tomcat, whatever) there is a high chance that several of its memory pages are prime candidates for sharing.
&lt;/p&gt;
&lt;p&gt;
Now before I do mention that this sharing is only enabled when the application has marked it as such. This is done through the &lt;em&gt;madvise()&lt;/em&gt; method, where applications mark the memory with &lt;em&gt;MADV_MERGEABLE&lt;/em&gt;, meaning that the applications explicitly need to support KSM in order for it to be successful. There is work on the way to support transparent KSM (such as &lt;a href="http://www.phoronix.com/scan.php?page=news_item&amp;amp;px=MTEzMTI"&gt;UKSM&lt;/a&gt; and &lt;a href="https://code.google.com/p/pksm/"&gt;PKSM&lt;/a&gt;) where no &lt;em&gt;madvise&lt;/em&gt; calls would be needed anymore. But beyond quickly reading the home pages (or translated home pages in case of UKSM ;-) I have no experience with those projects.
&lt;/p&gt;
&lt;p&gt;
So let’s get back to KSM. I am currently running three virtual machines (all configured to take at most 1.5 Gb of memory). Together, they take just a little over 1 Gb of memory (sum of their resident set sizes). When I consult KSM, I get the following information:
&lt;/p&gt;
&lt;pre&gt; # grep -H '' /sys/kernel/mm/ksm/pages_*
/sys/kernel/mm/ksm/pages_shared:48911
/sys/kernel/mm/ksm/pages_sharing:90090
/sys/kernel/mm/ksm/pages_to_scan:100
/sys/kernel/mm/ksm/pages_unshared:123002
/sys/kernel/mm/ksm/pages_volatile:1035
&lt;/pre&gt;
&lt;p&gt;
The &lt;tt&gt;pages_shared&lt;/tt&gt; tells me that 48911 pages are shared (which means about 191 Mb) through 90090 references (&lt;tt&gt;pages_sharing&lt;/tt&gt; – meaning the various processes have in total 90090 references to pages that are being shared). That means a gain of 41179 pages (160 Mb). Note that the resident set sizes do not take into account shared pages, so the sum of the RSS has to be subtracted with this to find the “real” memory consumption. The &lt;tt&gt;pages_unshared&lt;/tt&gt; value tells me that 123002 pages are marked with the &lt;tt&gt;MADV_MERGEABLE&lt;/tt&gt; advise flag but are not used by other processes.
&lt;/p&gt;
&lt;p&gt;
If you want to use KSM yourself, configure your kernel with &lt;tt&gt;CONFIG_KSM&lt;/tt&gt; and start KSM by echo’ing the value “1″ into &lt;tt&gt;/sys/kernel/mm/ksm/run&lt;/tt&gt;. That’s all there is to it.&lt;/p&gt;</description>
	<pubDate>Thu, 09 May 2013 01:50:21 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: The Linux “.d” approach</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1086</guid>
	<link>http://blog.siphos.be/2013/05/the-linux-d-approach/</link>

	<description>&lt;p&gt;
Many services on a Linux system use a &lt;tt&gt;*.d&lt;/tt&gt; directory approach to make their configuration easily configurable by other services. This is a remarkably simple yet efficient method for exposing services towards other applications. Let’s look into how this &lt;tt&gt;.d&lt;/tt&gt; approach works.
&lt;/p&gt;
&lt;p&gt;
Take a look at the &lt;tt&gt;/etc/pam.d&lt;/tt&gt; structure: services that are PAM-aware can place their PAM configuration files in this location, without needing any additional configuration steps or registration. Same with &lt;tt&gt;/etc/cron.d&lt;/tt&gt;: applications that need specific cronjobs do not need to edit &lt;tt&gt;/etc/crontab&lt;/tt&gt; directly (with the problem of concurrent access, overwriting changes, etc.) but instead can place their definitions in the &lt;tt&gt;cron.d&lt;/tt&gt; directory.
&lt;/p&gt;
&lt;p&gt;
This approach is getting more traction, as can be seen from the available “dot-d” directories on a system:
&lt;/p&gt;
&lt;pre&gt;$ ls -d /etc/*.d
/etc/bash_completion.d  /etc/ld.so.conf.d  /etc/pam.d          /etc/sysctl.d
/etc/conf.d             /etc/local.d       /etc/profile.d      /etc/wgetpaste.d
/etc/dracut.conf.d      /etc/logrotate.d   /etc/request-key.d  /etc/xinetd.d
/etc/env.d              /etc/makedev.d     /etc/sandbox.d      /etc/cron.d
/etc/init.d             /etc/modprobe.d    /etc/sudoers.d
&lt;/pre&gt;
&lt;p&gt;
An application can place its configuration files in these directories, automatically “plugging” it in into the operating system and the services that it provides. And the more services adopt this approach, the easier it is for applications to be pluggable within the operating system. Even complex systems such as database systems can easily configure themselves this way. And for larger organizations, this is a very interesting approach.
&lt;/p&gt;
&lt;p&gt;
Consider the need to deploy a database server on a Linux system in a larger organization. Each organization has its standards for file system locations, policies for log file management, etc. With the &lt;tt&gt;*.d&lt;/tt&gt; approach, these organizations only need to put files on the file system (a rather primitive feature that every organization supports) and manage these files instead of using specific, proprietary interfaces to configure the environment. But to properly control this flexibility, a few attention points need to be taken into account.
&lt;/p&gt;
&lt;p&gt;
The first is to use a proper &lt;em&gt;naming convention&lt;/em&gt;. If the organization has a data management structure, it might have specific names for services. These names are then used throughout the organization to properly identify owners or responsibilities. When using the &lt;tt&gt;*.d&lt;/tt&gt; directories, these naming conventions also allow administrators to easily know who to contact if a malfunctioning definition is placed. For instance, if a log rotation definition has a wrong entry, a file called &lt;tt&gt;mylogrotation&lt;/tt&gt; does not reveal much information. However, &lt;tt&gt;CDBM-postgres-querylogs&lt;/tt&gt; might reveal that the file is placed there by the customer database management team for a postgresql database. And it isn’t only about knowing who to contact (because that could easily be done by comments as well), but also to ensure no conflicts occur. On a shared database system, it is much more likely that two different teams place a &lt;tt&gt;postgresql&lt;/tt&gt; file (which would overwrite the file already there) unless they use a proper naming convention.
&lt;/p&gt;
&lt;p&gt;
The second is to use something identifying where the file comes from. A best practice when using Puppet for instance is to add in a comment to the file such as the following:
&lt;/p&gt;
&lt;pre&gt;# This file is managed by Puppet through the org-pgsl-def module
# Please do not modify manually
&lt;/pre&gt;
&lt;p&gt;
This informs the administrator how the file is put there; you might even want to include version information.
&lt;/p&gt;
&lt;p&gt;
A third one is when the order of configuration entries is important. Most &lt;tt&gt;*.d&lt;/tt&gt; supporting tools do not really care about ordering, but some, like udev, do. When that is the case, the common consensus is to use numbers in the beginning of the file name. The numbers then provide a good ordering of the files.
&lt;/p&gt;
&lt;p&gt;
Not all services already offer &lt;tt&gt;*.d&lt;/tt&gt; functionality, although it isn’t that difficult to provide it as well. Consider the Linux audit daemon, whose rules are managed in the &lt;tt&gt;/etc/audit/audit.rules&lt;/tt&gt; file. Not that flexible, isn’t it? But one can create a &lt;tt&gt;/etc/audit/audit.rules.d&lt;/tt&gt; location and have the audit init script read these files (in alphanumeric order), creating the same functionality.
&lt;/p&gt;
&lt;p&gt;
Given enough service adoption, software distribution can be sufficient to configure an application completely and integrate it with all services used by the operating system. And even services that do not support &lt;tt&gt;*.d&lt;/tt&gt; directories can still be easily wrapped around so that their configuration file itself is generated based on the information in such directories. Consider a hypothetical &lt;a href="https://wiki.gentoo.org/wiki/AIDE"&gt;AIDE&lt;/a&gt; configuration, where the &lt;tt&gt;aide.conf&lt;/tt&gt; is generated based on the &lt;tt&gt;aide.conf.head&lt;/tt&gt;, &lt;tt&gt;aide.d/*&lt;/tt&gt; and &lt;tt&gt;aide.conf.tail&lt;/tt&gt; files (similar to how &lt;tt&gt;resolv.conf&lt;/tt&gt; is sometimes managed). The generation is triggered right before &lt;b&gt;aide&lt;/b&gt; itself is called (perhaps all in a single script).
&lt;/p&gt;
&lt;p&gt;
Such an approach allows full integration:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A PAM configuration file is placed, allowing the service authentication to be easily managed by administrators. Changes on the authentication (for instance, switch to an LDAP authentication or introduce some trust relation) is done by placing an updated file.&lt;/li&gt;
&lt;li&gt;A log rotation configuration file is placed, making sure that the log files for the service do not eventually fill the partitions&lt;/li&gt;
&lt;li&gt;A syslog configuration is provided, allowing for some events to be sent to a different server instead of keeping it local – or perhaps both&lt;/li&gt;
&lt;li&gt;A cron configuration is stored so that statistics and other house-cleaning jobs for the service can run at night&lt;/li&gt;
&lt;li&gt;An audit configuration snippet is added to ensure critical commands and configuration files are properly checked&lt;/li&gt;
&lt;li&gt;Intrusion detection rules are added when needed&lt;/li&gt;
&lt;li&gt;Monitoring information is placed on the file system, causing additional monitoring metrics to be automatically picked up&lt;/li&gt;
&lt;li&gt;Firewall definitions are extended based on the snippets placed on the system&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
etc. And all this by only placing files on the file system. Keep It Simple, and efficient ;-)&lt;/p&gt;</description>
	<pubDate>Wed, 08 May 2013 01:50:05 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Added “predictable network interface” info into the handbook</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1118</guid>
	<link>http://blog.siphos.be/2013/05/added-predictable-network-interface-info-into-the-handbook/</link>

	<description>&lt;p&gt;
Being long overdue – like many of our documentation-reported bugs :-( I worked on &lt;a href="https://bugs.gentoo.org/show_bug.cgi?id=466262"&gt;bug 466262&lt;/a&gt; to update the &lt;a href="http://www.gentoo.org/doc/en/handbook/"&gt;Gentoo Handbook&lt;/a&gt; with information about &lt;a href="http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?part=4&amp;amp;chap=2#doc_chap4"&gt;Network Interface Naming&lt;/a&gt;. Of course, the installation instructions have also seen the necessary updates to refer to this change.
&lt;/p&gt;
&lt;p&gt;
With some luck (read: time) I might be able to fix various other documentation-related ones soon. I had some problems with the new SELinux userspace that I wanted to get fixed before, and then I worked on the new SELinux policies as well as trying to figure out how SELinux deals with network related aspects. Hence I saw time fly by at the speed of a neutrino…
&lt;/p&gt;
&lt;p&gt;
BTW, the 20130424 policies are in the tree.&lt;/p&gt;</description>
	<pubDate>Tue, 07 May 2013 01:50:22 +0000</pubDate>
</item>
<item>
	<title>Sven Vermeulen: Overview of Linux capabilities, part 3</title>
	<guid isPermalink="false">http://blog.siphos.be/?p=1068</guid>
	<link>http://blog.siphos.be/2013/05/overview-of-linux-capabilities-part-3/</link>

	<description>&lt;p&gt;
In &lt;a href="http://blog.siphos.be/2013/05/capabilities-a-short-intro/"&gt;previous&lt;/a&gt; &lt;a href="http://blog.siphos.be/2013/05/restricting-and-granting-capabilities/"&gt;posts&lt;/a&gt; &lt;a href="http://blog.siphos.be/2013/05/overview-of-linux-capabilities-part-1/"&gt;I&lt;/a&gt; &lt;a href="http://blog.siphos.be/2013/05/overview-of-linux-capabilities-part-2/"&gt;talked&lt;/a&gt; about capabilities and gave an introduction to how this powerful security feature within Linux can be used (and also exploited). I also covered a few capabilities, so let’s wrap this up with the remainder of them.
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;CAP_AUDIT_CONTROL&lt;/dt&gt;
&lt;dd&gt;Enable and disable kernel auditing; change auditing filter rules; retrieve auditing status and filtering rules&lt;/dd&gt;
&lt;dt&gt;CAP_AUDIT_WRITE&lt;/dt&gt;
&lt;dd&gt;Write records to kernel auditing log&lt;/dd&gt;
&lt;dt&gt;CAP_BLOCK_SUSPEND&lt;/dt&gt;
&lt;dd&gt;Employ features that can block system suspend&lt;/dd&gt;
&lt;dt&gt;CAP_MAC_ADMIN&lt;/dt&gt;
&lt;dd&gt;Override Mandatory Access Control (implemented for the SMACK LSM)&lt;/dd&gt;
&lt;dt&gt;CAP_MAC_OVERRIDE&lt;/dt&gt;
&lt;dd&gt;Allow MAC configuration or state changes (implemented for the SMACK LSM)&lt;/dd&gt;
&lt;dt&gt;CAP_NET_ADMIN&lt;/dt&gt;
&lt;dd&gt;Perform various network-related operations:&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;interface configuration&lt;/li&gt;
&lt;li&gt;administration of IP firewall, masquerading and accounting&lt;/li&gt;
&lt;li&gt;modify routing tables&lt;/li&gt;
&lt;li&gt;bind to any address for transparent proxying&lt;/li&gt;
&lt;li&gt;set type-of-service (TOS)&lt;/li&gt;
&lt;li&gt;clear driver statistics&lt;/li&gt;
&lt;li&gt;set promiscuous mode&lt;/li&gt;
&lt;li&gt;enabling multicasting&lt;/li&gt;
&lt;li&gt;use &lt;em&gt;setsockopt()&lt;/em&gt; for privileged socket operations&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;dt&gt;CAP_NET_BIND_SERVICE&lt;/dt&gt;
&lt;dd&gt;Bind a socket to Internet domain privileged ports (less than 1024)&lt;/dd&gt;
&lt;dt&gt;CAP_NET_RAW&lt;/dt&gt;
&lt;dd&gt;Use RAW and PACKET sockets, and bind to any address for transparent proxying&lt;/dd&gt;
&lt;dt&gt;CAP_SETPCAP&lt;/dt&gt;
&lt;dd&gt;Allow the process to add any capability from the calling thread’s bounding set to its inheritable set, and drop capabilities from the bounding set (using &lt;em&gt;prctl()&lt;/em&gt;) and make changes to the &lt;em&gt;securebits&lt;/em&gt; flags.&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_ADMIN&lt;/dt&gt;
&lt;dd&gt;Very powerful capability, includes:&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Running quota control, mount, swap management, set hostname, …&lt;/li&gt;
&lt;li&gt;Perform &lt;em&gt;VM86_REQUEST_IRQ vm86&lt;/em&gt; command&lt;/li&gt;
&lt;li&gt;Perform &lt;em&gt;IPC_SET&lt;/em&gt; and &lt;em&gt;IPC_RMID&lt;/em&gt; operations on arbitrary System V IPC objects&lt;/li&gt;
&lt;li&gt;Perform operations on &lt;tt&gt;trusted.*&lt;/tt&gt; and &lt;tt&gt;security.*&lt;/tt&gt; extended attributes&lt;/li&gt;
&lt;li&gt;Use &lt;em&gt;lookup_dcookie&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and many, many more. &lt;b&gt;man capabilities&lt;/b&gt; gives a good overview of them.
&lt;/p&gt;&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_BOOT&lt;/dt&gt;
&lt;dd&gt;Use &lt;em&gt;reboot()&lt;/em&gt; and &lt;em&gt;kexec_load()&lt;/em&gt;&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_CHROOT&lt;/dt&gt;
&lt;dd&gt;Use &lt;em&gt;chroot()&lt;/em&gt;&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_MODULE&lt;/dt&gt;
&lt;dd&gt;Load and unload kernel modules&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_RESOURCE&lt;/dt&gt;
&lt;dd&gt;Another capability with many consequences, including:&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use reserved space on ext2 file systems&lt;/li&gt;
&lt;li&gt;Make &lt;em&gt;ioctl()&lt;/em&gt; calls controlling ext3 journaling&lt;/li&gt;
&lt;li&gt;Override disk quota limits&lt;/li&gt;
&lt;li&gt;Increase resource limits&lt;/li&gt;
&lt;li&gt;Override &lt;tt&gt;RLIMIT_NPROC&lt;/tt&gt; resource limits&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and many more.
&lt;/p&gt;&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_TIME&lt;/dt&gt;
&lt;dd&gt;Set system clock and real-time hardware clock&lt;/dd&gt;
&lt;dt&gt;CAP_SYS_TTY_CONFIG&lt;/dt&gt;
&lt;dd&gt;Use &lt;em&gt;vhangup()&lt;/em&gt; and employ various privileged &lt;em&gt;ioctl()&lt;/em&gt; operations on virtual terminals&lt;/dd&gt;
&lt;dt&gt;CAP_SYSLOG&lt;/dt&gt;
&lt;dd&gt;Perform privileged &lt;em&gt;syslog()&lt;/em&gt; operations and view kernel addresses exposed with &lt;tt&gt;/proc&lt;/tt&gt; and other interfaces (if &lt;tt&gt;kptr_restrict&lt;/tt&gt; is set)&lt;/dd&gt;
&lt;dt&gt;CAP_WAKE_ALARM&lt;/dt&gt;
&lt;dd&gt;Trigger something that will wake up the system&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
Now when you look through the manual page of the capabilities, you’ll notice it talks about &lt;em&gt;securebits&lt;/em&gt; as well. This is an additional set of flags that govern how capabilities are used, inherited etc. System administrators don’t set these flags – they are governed by the applications themselves (when creating threads, forking, etc.) These flags are set on a per-thread level, and govern the following behavior:
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;SECBIT_KEEP_CAPS&lt;/dt&gt;
&lt;dd&gt;
Allow a thread with UID 0 to retain its capabilities when it switches its UIDs to a nonzero (non-root) value. By default, this flag is &lt;em&gt;not&lt;/em&gt; set, and even if it is set, it is cleared on an &lt;em&gt;execve&lt;/em&gt; call, reducing the likelihood that capabilities are “leaked”.
&lt;/dd&gt;
&lt;dt&gt;SECBIT_NO_SETUID_FIXUP&lt;/dt&gt;
&lt;dd&gt;
When set, the kernel will not adjust the capability sets when the thread’s effective and file system UIDs are switched between zero (root) and non-zero values.
&lt;/dd&gt;
&lt;dt&gt;SECBIT_NOROOT&lt;/dt&gt;
&lt;dd&gt;
If set, the kernel does not grant capabilities when a setuid-root program is executed, or when a process with an effective or real UID of 0 (root) calls &lt;em&gt;execve&lt;/em&gt;.
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
Manipulating these bits requires the &lt;tt&gt;CAP_SETPCAP&lt;/tt&gt; capability. Except for the &lt;tt&gt;SECBIT_KEEP_CAPS&lt;/tt&gt; security bit, the others are preserved on an &lt;em&gt;execve()&lt;/em&gt; call, and all bits are inherited by child processes (such as when &lt;em&gt;fork()&lt;/em&gt; is used).
&lt;/p&gt;
&lt;p&gt;
As a user or admin, you can also see capability-related information through the &lt;tt&gt;/proc&lt;/tt&gt; file system:
&lt;/p&gt;
&lt;pre&gt; # grep ^Cap /proc/$$/status
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff

$ grep ^Cap /proc/$$/status
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000001fffffffff
&lt;/pre&gt;
&lt;p&gt;
The capabilities listed therein are bitmasks for the various capabilities. The mask &lt;tt&gt;1FFFFFFFFF&lt;/tt&gt; holds 37 positions, which match the 37 capabilities known (again, see &lt;tt&gt;uapi/linux/capabilities.h&lt;/tt&gt; in the kernel sources to see the values of each of the capabilities). Again, the &lt;b&gt;pscap&lt;/b&gt; can be used to get information about the enabled capabilities of running processes in a more human readable format. But another tool provided by the &lt;tt&gt;sys-libs/libcap&lt;/tt&gt; is interested as well to look at: &lt;b&gt;capsh&lt;/b&gt;. The tool offers many capability-related features, including decoding the &lt;tt&gt;status&lt;/tt&gt; fields:
&lt;/p&gt;
&lt;pre&gt;$ capsh --decode=0000001fffffffff
0x0000001fffffffff=cap_chown,cap_dac_override,cap_dac_read_search,
cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,
cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,
cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,
cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,
cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,
cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,
cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,
cap_syslog,35,36
&lt;/pre&gt;
&lt;p&gt;
Next to fancy decoding, &lt;b&gt;capsh&lt;/b&gt; can also launch a shell with reduced capabilities. This makes it a good utility for jailing chroots even more.&lt;/p&gt;</description>
	<pubDate>Mon, 06 May 2013 01:50:35 +0000</pubDate>
</item>

</channel>
</rss>
