Gentoo Archives: gentoo-hardened

From: Sven Vermeulen <swift@g.o>
To: gentoo-hardened@l.g.o
Subject: Re: [gentoo-hardened] Newbee alarm....
Date: Thu, 03 Nov 2011 07:10:56
Message-Id: 20111103071017.GA18771@gentoo.org
In Reply to: [gentoo-hardened] Newbee alarm.... by Nico Baggus
1 On Thu, Nov 03, 2011 at 01:22:40AM +0100, Nico Baggus wrote:
2 > Well.. at least is nice to introduce one-self.
3 >
4 > Hi, I am a self-employed OpenVMS Cluster/systems manager by profession and
5 > run some linux on the side.
6 >
7 > I am new to selinux on gentoo although I run Gentoo for some years now
8 > after migrating from some Slackware based mess, through Redhat (until 9),
9 > and felt at home with gentoo.
10 >
11 > I started using hardened recently and found quite some messages in the
12 > audit log... enough to not warrent moving to enforcing.
13 >
14 > I'll post some findings after this.
15
16 Hi Nico,
17
18 Welcome in the world of Security Enhanced Linux. I am very glad to see you
19 are trying to get it working, and I can promise you that it will be a
20 challenging road. SELinux is a Mandatory Access Control system that is very
21 flexible, yet also very cumbersome and detailed.
22
23 Now, in your other mails you are focusing on the AVC logs that you got from
24 running in permissive mode. That is fine, but will also cloud your view on
25 what you need and what you see. After all, there could be AVC denials that
26 are cosmetic (you should ignore them).
27
28 But the most difficult part you'll notice is to "read" these AVC denials. It
29 is not sufficient to just run audit2allow against them all and hope for the
30 best. If you do that, your system might work for a while, but you could have
31 opened up privileges that shouldn't be there in the first place.
32
33 For that reason, it is *very* *important* to look at each denial by itself,
34 figure out what is happening here, look for related denials and only /then/
35 on how to resolve it.
36
37 For instance, look at the following denials (I picked two from a whole bunch
38 since those two are related):
39
40 { create } comm="mkdir" name=".test.1390"
41 scontext=system_u:system_r:initrc_t
42 tcontext=system_u:object_r:var_log_t tclass=dir
43
44 { rmdir } comm="rmdir" name=".test.1390" dev=vda4 ino=16285
45 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:var_log_t
46 tclass=dir
47
48 You can imagine them being related since they both work on the same object
49 (a directory called ".test.1390"). Also, because of the name syntax, it is
50 probably created using mktemp or so. And since the context of the directory
51 is var_log_t, it is easily deducable that it is in /var/log.
52
53 As it turns out, these rules are triggered by /etc/init.d/bootmisc (hence
54 the source context of initrc_t) which tests to see if it can write to a
55 directory (/var/log). Although I can think this is a wrong approach here
56 (after all, the bootmisc script doesn't seem to create directories in
57 /var/log, only files like /var/log/dmesg) it is something that is a "valid"
58 situation.
59
60 Resolving this can be done in three ways (well, there are probably more)
61
62 (1.) Have bootmisc updated so that /var/log isn't "tested" with the
63 "dir_writeable" check, but with a proper file create check
64 (2.) Have initrc_t enhanced so that it can create initrc_var_log_t labeled
65 directories, and give it the proper privileges to create such directories
66 (3.) Give initrc_t the manage privileges for var_log_t directories (which is
67 somewhat what would happen if we throw audit2allow against the lines)
68
69 These are also in order of preference. As you can see, (3.) is last (but
70 easiest).
71
72 For each denial we get, we need to perform a similar analysis. Just pointing
73 out which denials we get isn't enough (but it is a start). Showing the
74 audit2allow "fixes" doesn't help us with anything though :-( They are meant
75 as a resolution, but since we do not know the problem we can't just accept
76 that.
77
78 For many denials, I personally also require that they are reproduced when
79 running in enforcing mode. Initially, that might not be possible on your
80 system so we first need to focus then on the denials that are "more
81 obvious".
82
83 If you ever want to try out enforcing mode, just boot in permissive, log in
84 as root and ensure that "id -Z" returns something like
85 "root:sysadm_r:sysadm_t", and *not* kernel_t, initrc_t, locallogin_t or
86 anything else. Only when your context is sysadm_t, then you can run
87 "setenforce 1" to switch to enforcing mode.
88
89 Keep that terminal logged on, work around a bit. If you get stuck, switch
90 back to the terminal, type in "setenforce 0" and you are back in permissive.
91
92 Wkr,
93 Sven Vermeulen