Skip to contentSkip to conversation

named policy

PATCH Russell Coker 2 participants 5 messages Aug 24, 2004 – Aug 25, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The attached patch adjusts some comments in the named policy to match what's being done, fixes up a lot of the type labelling (including some ifdef's for distro specific stuff), removes rndc_conf_t references from the policy (the typealias statement is only there for files that are already labelled on the file system), and removes some access that should not be needed.

If ndc_t really needs to write to type named_zone_t then we probably have a mis-labelling issue.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
program/unused/named.te renamed from usr/src/se/policy/domains/program/unused/named.te +8 -6
@@ -32,10 +32,10 @@
 type named_conf_t, file_type, sysadmfile;
 typealias named_conf_t alias rndc_conf_t;
 
-# for zone files
+# for primary zone files
 type named_zone_t, file_type, sysadmfile;
 
-# named.ca files
+# for secondary zone files
 type named_cache_t, file_type, sysadmfile;
 
 # Use capabilities. Surplus capabilities may be allowed.
@@ -65,10 +65,12 @@
 #create and modify zone files
 create_dir_file(named_t, named_zone_t)
 }
+
 #read zone files
 r_dir_file(named_t, named_zone_t)
 
-r_dir_file(named_t, named_cache_t)
+#write cache for secondary zones
+rw_dir_create_file(named_t, named_cache_t)
 
 allow named_t self:unix_stream_socket create_stream_socket_perms;
 allow named_t self:unix_dgram_socket create_socket_perms;
@@ -100,7 +102,9 @@
 can_ypbind(ndc_t)
 read_locale(ndc_t)
 can_tcp_connect(ndc_t, named_t)
-allow { named_t ndc_t initrc_t } rndc_conf_t:file { getattr read };
+
+# for /etc/rndc.key
+allow { ndc_t initrc_t } named_conf_t:file { getattr read };
 
 allow ndc_t etc_t:dir r_dir_perms;
 allow ndc_t etc_t:file r_file_perms;
@@ -138,8 +142,6 @@
 allow ndc_t named_var_run_t:file getattr;
 allow ndc_t named_zone_t:dir { read getattr };
 allow ndc_t named_zone_t:file getattr;
-create_dir_file(ndc_t, named_zone_t)
 dontaudit ndc_t sysadm_home_t:dir { getattr search read };
 ')
 allow ndc_t self:netlink_route_socket { bind create getattr nlmsg_read read write };
-dontaudit named_t devpts_t:chr_file { read write };
program/named.fc renamed from usr/src/se/policy/file_contexts/program/named.fc +15 -16
@@ -1,28 +1,27 @@
 # named
 /var/named(/.*)?      		system_u:object_r:named_zone_t
-/var/named/named.ca     --	system_u:object_r:named_cache_t
+/var/named/slaves(/.*)?		system_u:object_r:named_cache_t
 /etc/named\.conf	--	system_u:object_r:named_conf_t
-/etc/named\.custom	--	system_u:object_r:named_conf_t
-/etc/rndc.*		--	system_u:object_r:rndc_conf_t
+ifdef(`distro_debian', `
+/etc/bind(/.*)?			system_u:object_r:named_zone_t
+/etc/bind/named\.conf	--	system_u:object_r:named_conf_t
+/etc/bind/rndc\.key	--	system_u:object_r:named_conf_t
+/var/cache/bind(/.*)?		system_u:object_r:named_cache_t
+')
+/etc/rndc.*		--	system_u:object_r:named_conf_t
 /usr/sbin/named.*      	--	system_u:object_r:named_exec_t
 /usr/sbin/r?ndc		--	system_u:object_r:ndc_exec_t
 /var/run/ndc		-s	system_u:object_r:named_var_run_t
+/var/run/bind(/.*)?		system_u:object_r:named_var_run_t
 /var/run/named.*		system_u:object_r:named_var_run_t
 /usr/sbin/lwresd	--	system_u:object_r:named_exec_t
-/var/named/chroot	-d    	system_u:object_r:root_t
-/var/named/chroot/dev(/.*)?    	system_u:object_r:device_t
+ifdef(`distro_redhat', `
+/var/named/chroot(/.*)?		system_u:object_r:named_conf_t
 /var/named/chroot/dev/null   -c	system_u:object_r:null_device_t
-/var/named/chroot/dev/zero   -c	system_u:object_r:zero_device_t
 /var/named/chroot/dev/random -c	system_u:object_r:random_device_t
-/var/named/chroot/etc(/.*)?    	system_u:object_r:etc_t
 /var/named/chroot/etc/named\.conf -- system_u:object_r:named_conf_t
-/var/named/chroot/etc/named\.custom -- system_u:object_r:named_conf_t
-/var/named/chroot/etc/rndc.* -- system_u:object_r:rndc_conf_t
-/var/named/chroot/var(/.*)?	system_u:object_r:var_t
-/var/named/chroot/var/named(/.*)?   		system_u:object_r:named_zone_t
-/var/named/chroot/var/named/named.ca    system_u:object_r:named_cache_t
-/var/named/chroot/var/run(/.*)?	system_u:object_r:var_run_t
+/var/named/chroot/etc/rndc.* -- system_u:object_r:named_conf_t
 /var/named/chroot/var/run/named.* system_u:object_r:named_var_run_t
-/var/named/chroot/var/tmp	-d system_u:object_r:tmp_t
-
-
+/var/named/chroot/var/tmp(/.*)? system_u:object_r:named_cache_t
+/var/named/slaves(/.*)?		system_u:object_r:named_cache_t
+')
#1 lore raw
Quoted 8 lines · Russell Coker

The attached patch adjusts some comments in the named policy to match what's being done, fixes up a lot of the type labelling (including some ifdef's for distro specific stuff), removes rndc_conf_t references from the policy (the typealias statement is only there for files that are already labelled on the file system), and removes some access that should not be needed.

If ndc_t really needs to write to type named_zone_t then we probably have a mis-labelling issue.

Requires coordination with named maintainer:
1) You are reverting named_cache_t to being used for secondary zone files and being writable, whereas he (or Dan) was using it for named.ca files and keeping it read-only. So what happens to the named.ca files?
2) named maintainer claimed that ndc did need write access to /var/named (named_zone_t). See his earlier email.
3) /var/named/chroot labeling changes seem wrong to me; the current .fc file provides consistent labels with a normal filesystem layout.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 7 lines · Russell Coker

The attached patch adjusts some comments in the named policy to match what's being done, fixes up a lot of the type labelling (including some ifdef's for distro specific stuff), removes rndc_conf_t references from the policy (the typealias statement is only there for files that are already labelled on the file system), and removes some access that should not be needed.

Quoted 7 lines
Quoted 2 lines

If ndc_t really needs to write to type named_zone_t then we probably have a mis-labelling issue.

Requires coordination with named maintainer:
1) You are reverting named_cache_t to being used for secondary zone files and being writable, whereas he (or Dan) was using it for named.ca files and keeping it read-only. So what happens to the named.ca files?

They have to be relabeled. named_conf_t is a read-only type for named_t to read which should do well for named.ca.

Quoted 2 lines

2) named maintainer claimed that ndc did need write access to /var/named (named_zone_t). See his earlier email.

He is incorrect. The command "rndc dumpdb" will instruct the named process to write the dump file to the location specified in the configuration.

options {
        directory "/var/named/";
        dump-file "/var/named/slaves/named_dump.db";
        statistics-file "/var/named/slaves/named.stats";
};

I have the above in my /etc/named.custom to make this work. NB The default is to have it in /var/named, if we choose to stick with that then we need to have the following policy:
file_type_auto_trans(named_t, named_conf_t, named_cache_t, file)

This is something I would prefer to avoid. But we'll have to do it if we want to support this operation with the old configuration.

The above changes also apply for "rndc stats" in the same manner. They should also apply for memstats which appears in the named binary but which I haven't worked out how to trigger (maybe I'll have to read the source for that).

Quoted 2 lines

3) /var/named/chroot labeling changes seem wrong to me; the current .fc file provides consistent labels with a normal filesystem layout.

The .fc file in CVS does use more consistent labels with a normal file system. However I don't think that this is a benefit.

For example using tmp_t for the tmp directory is a bad idea IMHO. If somehow (due to a mistake in policy or a policy which matches a configuration that's significantly altered from the default) a process in another gets access to the chroot then it would be allowed to create temporary files there even though the policy may correctly prevent it writing to all types associated with named. I think that tmp_t should be reserved for directories that are designed for use by a large number of domains for temporary files.

The same applies for the dev directory, we don't need to allow all domains to search that directory, just named_t, sysadm_t, and a small number of others.

The only possible problem I can think of in regard to this is if someone uses bind mounts and then relabels. If we want to be safe against this we would need to duplicate all entries for /dev. To do this properly if we were to go down that path would require changing genhomedircon to duplicate /dev entries for different paths. Incidentally I recently did some performance analysis on setfiles which showed that the /dev labels take so little time as to be insignificant (I was concerned that the "dev" -> "u?dev" change would hurt performance because of breaking stem compression, but as all device nodes are under the one directory the type checking removes the relevance of stem compression for this). So this is a feasible option.

In any case with regard to bind mounts my proposed fc file won't break things any more than the one that's currently in CVS. ;)

I have attached new named policy files which work well on my system including "rndc dumpdb".

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

#DESC BIND - Name server
#
# Authors: Yuichi Nakamura <[email protected]>,
# Russell Coker
# X-Debian-Packages: bind bind9
#
#

#################################
#
# Rules for the named_t domain.
#
type rndc_port_t, port_type;

daemon_domain(named)
tmp_domain(named)

# for /var/run/ndc used in BIND 8
file_type_auto_trans(named_t, var_run_t, named_var_run_t, sock_file)
# ndc_t is the domain for the ndc program
type ndc_t, domain, privlog;
role sysadm_r types ndc_t;
role system_r types ndc_t;

can_exec(named_t, named_exec_t)
allow named_t sbin_t:dir search;

allow named_t self:process setsched;

# A type for configuration files of named.
type named_conf_t, file_type, sysadmfile;
typealias named_conf_t alias rndc_conf_t;

# for primary zone files
type named_zone_t, file_type, sysadmfile;
# for secondary zone files
type named_cache_t, file_type, sysadmfile;

# Use capabilities. Surplus capabilities may be allowed.
allow named_t self:capability { chown dac_override fowner setgid setuid net_bind_service sys_chroot sys_nice sys_resource };

allow named_t etc_t:file { getattr read };
allow named_t etc_runtime_t:{ file lnk_file } { getattr read };

#Named can use network
can_network(named_t)
can_ypbind(named_t)

# allow UDP transfer to/from any program
can_udp_send(domain, named_t)
can_udp_send(named_t, domain)
can_tcp_connect(domain, named_t)

# Bind to the named port.
allow named_t dns_port_t:udp_socket name_bind;
allow named_t { dns_port_t rndc_port_t }:tcp_socket name_bind;

bool named_write_master_zones false;

#read configuration files
r_dir_file(named_t, named_conf_t)

if (named_write_master_zones) {
#create and modify zone files
create_dir_file(named_t, named_zone_t)
}
#read zone files
r_dir_file(named_t, named_zone_t)

#write cache for secondary zones
rw_dir_create_file(named_t, named_cache_t)

allow named_t self:unix_stream_socket create_stream_socket_perms; allow named_t self:unix_dgram_socket create_socket_perms;

# Read sysctl kernel variables.
allow named_t sysctl_t:dir r_dir_perms;
allow named_t sysctl_kernel_t:dir r_dir_perms;
allow named_t sysctl_kernel_t:file r_file_perms;

# Read /proc/cpuinfo.
allow named_t proc_t:dir r_dir_perms;
allow named_t proc_t:file r_file_perms;

# Read /dev/random.
allow named_t device_t:dir r_dir_perms; allow named_t random_device_t:chr_file r_file_perms;

# Use a pipe created by self.
allow named_t self:fifo_file rw_file_perms;

# Set own capabilities.
allow named_t self:process setcap;

#A type for /usr/sbin/ndc
type ndc_exec_t, file_type,sysadmfile, exec_type; domain_auto_trans({ sysadm_t initrc_t }, ndc_exec_t, ndc_t) uses_shlib(ndc_t)
can_network(ndc_t)
can_ypbind(ndc_t)
read_locale(ndc_t)
can_tcp_connect(ndc_t, named_t)

# for /etc/rndc.key
ifdef(`distro_redhat', `
allow { ndc_t initrc_t } named_conf_t:dir search;
')
allow { ndc_t initrc_t } named_conf_t:file { getattr read };

allow ndc_t etc_t:dir r_dir_perms;
allow ndc_t etc_t:file r_file_perms;
allow ndc_t self:unix_stream_socket create_stream_socket_perms; allow ndc_t self:unix_stream_socket connect;
allow ndc_t self:capability { dac_override net_admin }; allow ndc_t named_var_run_t:sock_file rw_file_perms; allow ndc_t named_t:unix_stream_socket connectto; allow ndc_t { privfd init_t }:fd use;

# seems to need read as well for some reason
allow ndc_t { admin_tty_type initrc_devpts_t }:chr_file { getattr read write };
allow ndc_t fs_t:filesystem getattr;

# Read sysctl kernel variables.
allow ndc_t sysctl_t:dir r_dir_perms;
allow ndc_t sysctl_kernel_t:dir r_dir_perms;
allow ndc_t sysctl_kernel_t:file r_file_perms;

allow ndc_t self:process { fork signal_perms }; allow ndc_t self:fifo_file { read write getattr ioctl }; allow ndc_t named_zone_t:dir search;

# for chmod in start script
dontaudit initrc_t named_var_run_t:dir setattr;
# for ndc_t to be used for restart shell scripts
ifdef(`ndc_shell_script', `
system_crond_entry(ndc_exec_t, ndc_t)
allow ndc_t devtty_t:chr_file { read write ioctl };
allow ndc_t etc_runtime_t:file { getattr read };
allow ndc_t proc_t:dir search;
allow ndc_t proc_t:file { getattr read };
can_exec(ndc_t, { bin_t sbin_t shell_exec_t })
allow ndc_t var_t:dir search;
allow ndc_t named_var_run_t:file getattr;
allow ndc_t named_zone_t:dir { read getattr };
allow ndc_t named_zone_t:file getattr;
dontaudit ndc_t sysadm_home_t:dir { getattr search read };
')
allow ndc_t self:netlink_route_socket { bind create getattr nlmsg_read read write };
# named
/var/named(/.*)?		system_u:object_r:named_zone_t
/var/named/slaves(/.*)?		system_u:object_r:named_cache_t
/etc/named\.conf	--	system_u:object_r:named_conf_t
ifdef(`distro_debian', `
/etc/bind(/.*)?			system_u:object_r:named_zone_t
/etc/bind/named\.conf	--	system_u:object_r:named_conf_t
/etc/bind/rndc\.key	--	system_u:object_r:named_conf_t
/var/cache/bind(/.*)?		system_u:object_r:named_cache_t
')
/etc/rndc.*		--	system_u:object_r:named_conf_t
/usr/sbin/named.*      	--	system_u:object_r:named_exec_t
/usr/sbin/r?ndc		--	system_u:object_r:ndc_exec_t
/var/run/ndc		-s	system_u:object_r:named_var_run_t
/var/run/bind(/.*)?		system_u:object_r:named_var_run_t
/var/run/named.*		system_u:object_r:named_var_run_t
/usr/sbin/lwresd	--	system_u:object_r:named_exec_t
ifdef(`distro_redhat', `
/var/named/chroot(/.*)?		system_u:object_r:named_conf_t
/var/named/chroot/dev/null   -c	system_u:object_r:null_device_t
/var/named/chroot/dev/random -c	system_u:object_r:random_device_t
/var/named/chroot/etc/named\.conf -- system_u:object_r:named_conf_t
/var/named/chroot/etc/rndc.* -- system_u:object_r:named_conf_t
/var/named/chroot/var/run/named.* system_u:object_r:named_var_run_t
/var/named/chroot/var/tmp(/.*)? system_u:object_r:named_cache_t
/var/named/slaves(/.*)?		system_u:object_r:named_cache_t
/var/named/chroot/var/named/slaves(/.*)? system_u:object_r:named_cache_t
/var/named/named\.ca	--	system_u:object_r:named_conf_t
')
#3 lore raw
Quoted 5 lines · Russell Coker
Quoted 2 lines

3) /var/named/chroot labeling changes seem wrong to me; the current .fc file provides consistent labels with a normal filesystem layout.

The .fc file in CVS does use more consistent labels with a normal file system. However I don't think that this is a benefit.

If you were to remove named_t's access to base system types (like root_t, etc_t, var_t, tmp_t, ...) entirely and only support chroot'd operation, then it would make sense to only use named-specific types for the chroot environment and use the policy to prohibit any access by named outside of the chroot. Otherwise, I think you want consistency between the chroot and non-chroot environment labeling for policy consistency between the two setups and to avoid overly permissive access to named even within the chroot.

Do you really want named_conf_t assigned to the chroot's /, /dev, /etc, /var, /var/run and any otherwise unspecified files within them? Audit messages will be rather interesting there. Nits: Your .fc file also has no entries for /dev/zero or /var/named within the chroot. Finally, I don't see why chroot'd named is redhat-specific.

Quoted 10 lines

For example using tmp_t for the tmp directory is a bad idea IMHO. If somehow (due to a mistake in policy or a policy which matches a configuration that's significantly altered from the default) a process in another gets access to the chroot then it would be allowed to create temporary files there even though the policy may correctly prevent it writing to all types associated with named. I think that tmp_t should be reserved for directories that are designed for use by a large number of domains for temporary files.

The same applies for the dev directory, we don't need to allow all domains to search that directory, just named_t, sysadm_t, and a small number of others.

As above, if you wanted strong isolation, you could put each daemon into a chroot with its own set of types, not allow any access to any of the base system types or to another domain's types by the daemon's domain. But if you are going to give them access to the base system types anyway (e.g. if they can access the system /tmp directory or the system /dev directory), then what does it matter? They are unlikely to be able to reach each other's chroot environments anyway due to base protections on the containing directory (e.g. /var/named itself), but even if they did, they can't do any more harm than they can do to the base system (and your policy has to be written from that perspective anyway, as you are writing it for non-chroot setups as well as chroot setups).

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
Quoted 7 lines · Stephen Smalley
Quoted 5 lines · Russell Coker
Quoted 2 lines

3) /var/named/chroot labeling changes seem wrong to me; the current .fc file provides consistent labels with a normal filesystem layout.

The .fc file in CVS does use more consistent labels with a normal file system. However I don't think that this is a benefit.

Quoted 8 lines

If you were to remove named_t's access to base system types (like root_t, etc_t, var_t, tmp_t, ...) entirely and only support chroot'd operation, then it would make sense to only use named-specific types for the chroot environment and use the policy to prohibit any access by named outside of the chroot. Otherwise, I think you want consistency between the chroot and non-chroot environment labeling for policy consistency between the two setups and to avoid overly permissive access to named even within the chroot.

We don't need the same types to have consistent policy. If we have a read-only type such as named_conf_t instead of another read-only type such as etc_t or locale_t it makes no difference to the policy.

Quoted 4 lines

Do you really want named_conf_t assigned to the chroot's /, /dev, /etc, /var, /var/run and any otherwise unspecified files within them? Audit messages will be rather interesting there. Nits: Your .fc file also has no entries for /dev/zero or /var/named within the chroot.

OK, I've added those.

Quoted 2 lines

Finally,
I don't see why chroot'd named is redhat-specific.

Because no other distribution does it the same way (AFAIK).

I've attached a new named.fc, tell me what you think about it.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
# named
/var/named(/.*)?		system_u:object_r:named_zone_t
/var/named/slaves(/.*)?		system_u:object_r:named_cache_t
/etc/named\.conf	--	system_u:object_r:named_conf_t
ifdef(`distro_debian', `
/etc/bind(/.*)?			system_u:object_r:named_zone_t
/etc/bind/named\.conf	--	system_u:object_r:named_conf_t
/etc/bind/rndc\.key	--	system_u:object_r:named_conf_t
/var/cache/bind(/.*)?		system_u:object_r:named_cache_t
')
/etc/rndc.*		--	system_u:object_r:named_conf_t
/usr/sbin/named.*      	--	system_u:object_r:named_exec_t
/usr/sbin/r?ndc		--	system_u:object_r:ndc_exec_t
/var/run/ndc		-s	system_u:object_r:named_var_run_t
/var/run/bind(/.*)?		system_u:object_r:named_var_run_t
/var/run/named.*		system_u:object_r:named_var_run_t
/usr/sbin/lwresd	--	system_u:object_r:named_exec_t
ifdef(`distro_redhat', `
/var/named/chroot(/.*)?		system_u:object_r:named_conf_t
/var/named/chroot/dev	-d	system_u:object_r:device_t
/var/named/chroot/dev/null   -c	system_u:object_r:null_device_t
/var/named/chroot/dev/random -c	system_u:object_r:random_device_t
/var/named/chroot/dev/zero -c	system_u:object_r:zero_device_t
/var/named/chroot/etc	-d	system_u:object_r:etc_t
/var/named/chroot/etc/localtime -- system_u:object_r:locale_t
/var/named/chroot/etc/named\.conf -- system_u:object_r:named_conf_t
/var/named/chroot/etc/rndc.* -- system_u:object_r:named_conf_t
/var/named/chroot/var/run/named.* system_u:object_r:named_var_run_t
/var/named/chroot/var/tmp(/.*)? system_u:object_r:named_cache_t
/var/named/chroot/var/named(/.*)? system_u:object_r:named_zone_t
/var/named/chroot/var/named/slaves(/.*)? system_u:object_r:named_cache_t
')