Tips for Taming SE Linux, Part Two - Page 2

By Carla Schroder | Posted Dec 3, 2007
Page 2 of 2   |  Back to Page 1
Print ArticleEmail Article
  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn

The security context is used by your SELinux policy to control who can do what. The identity controls which domains the process is allowed to enter. This is defined somewhere inside the vast directory — /etc/selinux— that contains your SELinux policy. In the targeted SELinux policy, every subject and object runs in the unconfined_t domain, which is just like running under our old familiar Unix DAC (Discretionary Access Control) permissions. Except for a select set of daemons that are restricted by SELinux policy and run in their own restricted domains. For example, httpd runs in the httpd_t domain, and is tightly restricted so that a successful intrusion will be confined to the HTTP process, and not gain access to the rest of the system. Nor will users or processes who have no business with httpd be allowed to interfere with its operation, or access data files they have no business looking at.

The ps command will show you some examples of this in action:

$ ps aZ
LABEL                         PID TTY STAT TIME COMMAND
system_u:system_r:getty_t:s0 2587 tty1 Ss+ 0:00 /sbin/mingetty tty1
system_u:system_r:xdm_xserver_t:s0:c0.c1023 2664 tty7 Ss+ 7:38 /usr/bin/X

Open Networks Today
Networks, Security and Privacy. Daily.

Managing editor Michael Hall blogs about everything from warrantless wiretaps to the latest malware menaces at Open Networks Today.

What does the s0 mean? Well now, that opens a whole new can o' terminology. That field belongs to Multilevel Security (MLS); it sets a sensitivity value that ranges from s0-s15. When you use MLS you also need a capabilities field, which goes from c0 - c255, so it would look something like s1:c2. MLS is super-strict and overkill for most of us. So instead Fedora uses Multi-Category Security (MCS). The MLS sensitivity field is required by the kernel and it always says s0, but you can ignore it. MCS allows you to further refine access controls with user-defined categories.

For example, you could have a MCS category called "super-secret!_yes_really!". Then files labeled with this will be accessible only to processes with permissions to enter this category. In the ps output above, you'll see an example of this with the X process. If you want to try your hand at these read A Brief Introduction to Multi-Category Security (MCS), and Getting Started with Multi-Category Security (MCS).

SELinux Commands

While most files can be controlled by SELinux without any modifications, a few have had to be patched to become SELinux-aware, such as the Linux coreutils files, login programs like login, sshd, gdm, cron, and the X windows system. You should also find these on systems that do not ship with SELinux, such as Ubuntu. If your system does not have SELinux, they will return empty fields where the SELinux labels should go, like this ps example:

$ ps aZ
LABEL       PID TTY STAT TIME COMMAND
-           4248 tty4 Ss+ 0:00 /sbin/getty 38400 tty4
-           4249 tty5 Ss+ 0:00 /sbin/getty 38400 tty5

The nice SELinux devs have kindly made Z the universal "show me the security context" option. SELinux comes with it own set of user-space commands, which are bundled up in the policycoretutils package. You can run a number of SELinux commands without hurting anything, like see your own personal security context:

$ id -Z system_u:system_r:unconfined:t:s0

You can check SELinux status:

$ /usr/sbin/sestatus
SELinux status: enabled
SELinux mount: /selinux
Current mode: permissive
Mode from config file: permissive
Policy version: 21
Policy from config file: targeted

avcstat displays AVC (Access Vector Cache) statistics. avcstat 5 runs it every five seconds; of course you can make this any interval you want.

Fedora's SELinux Tools

Fedora 7 and 8 have three good graphical SELinux tools: SELinux Management, SELinux Policy Generation Tool, and SELinux Troubleshooter. Start with SELinux Management; this lets you fine-tune the existing SELinux policy, or change to a different policy type entirely.

It costs nothing but time and a spare PC to learn your way around this potent security tool. I've seen a lot of comments on forums and mailing lists that say it's too complex to bother with. I don't agree with this; I think a security tool of this nature is overdue for Linux. Any Internet-facing server is a good candidate for SELinux, and especially the notoriously porous category of LAMP servers.

What about AppArmor and GRSecurity? We'll soon be looking at these as well.

Resources

Comment and Contribute
(Maximum characters: 1200). You have
characters left.
Get the Latest Scoop with Enterprise Networking Planet Newsletter