Skip to contentSkip to conversation

losing type information under high load

DISCUSSION Russell Coker 2 participants 3 messages Sep 27, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

I have two machines running ReiserFS for /var/cache/squid where files occasionally get changed to type system_u:object_r:file_t for no good reason.

This has happened for the last few kernel patches, with kernel 2.4.18 and 2.4.19, and is not related to power failures or crashes.

The only other similar occurance I observed involved a mail server queue file (but this only happened once and I'm not certain it wasn't due to another cause).

I suspect that there is some sort of ReiserFS/SE problem here regarding file systems that are under moderate load (neither of the Squid machines in question is under heavy load - the more highly loaded machine was running fine when it was a Pentium-166, now it's a well configured Athlon 1000 with corresponding improvements in RAM and disk).

These problems occur about two or three times a month (it'll be tough to track down). I can't recommend that the NSA people spend any great amount of time investigating this until/unless we get some confirmation of this (and preferrably from someone who isn't using ReiserFS).

However this raises another issue. In the default policy we allow almost everything read access to file_t directories, sym-links, and files. So any situation that results in a file changing to the default type (EG a power failure at an inconveniant time) may make a file world-readable!!!

Is there any reason for not restricting file_t to the administrator only?

Signature · 10 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


--
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.
#1 lore raw
Quoted 5 lines · Russell Coker

I have two machines running ReiserFS for /var/cache/squid where files occasionally get changed to type system_u:object_r:file_t for no good reason.

This has happened for the last few kernel patches, with kernel 2.4.18 and 2.4.19, and is not related to power failures or crashes.

Or switching back and forth between a SELinux kernel and a non-SELinux kernel? That could cause the file to be re-created while running a non-SELinux kernel, leaving it with an unspecified PSID.

Unless ReiserFS is dynamically remapping inode numbers (which would be very bad for the SELinux persistent label mapping), I don't know why you would see this behavior. My impression from earlier discussions on this list was that ReiserFS currently satisfies the requirement for persistent and unique inode numbers, but may cease to satisfy that requirement in the future. At that point, I would expect ReiserFS to natively support extended attribute-like functionality so that SELinux can defer file label management to it.

The only case where SELinux resets an inode to the default file PSID is when the inode is deleted (the final iput with a hard link count of zero). This isn't strictly necessary, since the inode will be reassigned a PSID when it is next allocated for a new file, but is good form. The first attached patch disables this code; you can try this patch if you like with ReiserFS to see if it makes any difference.

Quoted 6 lines

However this raises another issue. In the default policy we allow almost everything read access to file_t directories, sym-links, and files. So any situation that results in a file changing to the default type (EG a power failure at an inconveniant time) may make a file world-readable!!!

Is there any reason for not restricting file_t to the administrator only?

Not anymore. The second attached patch removes general read access to file_t, although further testing and review is recommended.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: lsm-2.4/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/hooks.c,v retrieving revision 1.21

security/selinux/hooks.c +1 -11
diff -u -r1.21 hooks.c
@@ -2255,17 +2255,7 @@
 
 static void selinux_inode_delete(struct inode *inode)
 {
-	struct super_block *sb = inode->i_sb; 
-	if (sb) {
-		struct superblock_security_struct *sbsec = sb->s_security;
-
-		if (!sbsec || sbsec->magic != SELINUX_MAGIC || 
-		    !sbsec->initialized)
-			return;
-
-		if (sbsec->uses_psids)
-			clear_psid(inode);
-	}
+	return;
 }
 
 

Index: selinux/policy/domains/program/apache.te
===================================================================
RCS file: /cvs/lsm/selinux/policy/domains/program/apache.te,v retrieving revision 1.14

policy/domains/program/apache.te +0 -2
diff -u -r1.14 apache.te
@@ -202,13 +202,11 @@
 ########################################################################
 allow httpd_user_script_process_t initrc_t:fd {use};
 allow httpd_user_script_process_t init_t:fd {use};
-allow httpd_user_script_process_t file_t:dir r_dir_perms;
 
 allow httpd_user_script_process_t random_device_t:chr_file r_file_perms;
 
 allow httpd_sys_script_process_t initrc_t:fd {use};
 allow httpd_sys_script_process_t init_t:fd {use};
-allow httpd_sys_script_process_t file_t:dir r_dir_perms;
 
 allow httpd_sys_script_process_t random_device_t:chr_file r_file_perms;
 

Index: selinux/policy/domains/program/initrc.te
===================================================================
RCS file: /cvs/lsm/selinux/policy/domains/program/initrc.te,v retrieving revision 1.17

policy/domains/program/initrc.te +1 -1
diff -u -r1.17 initrc.te
@@ -76,7 +76,7 @@
 
 # Mount and unmount file systems.
 allow initrc_t fs_type:filesystem mount_fs_perms;
-allow initrc_t file_t:dir mounton;
+allow initrc_t file_t:dir { read search getattr mounton };
 
 # Create runtime files in /etc, e.g. /etc/mtab, /etc/HOSTNAME.
 file_type_auto_trans(initrc_t, etc_t, etc_runtime_t)

Index: selinux/policy/macros/global_macros.te
===================================================================
RCS file: /cvs/lsm/selinux/policy/macros/global_macros.te,v retrieving revision 1.26

policy/macros/global_macros.te +0 -4
diff -u -r1.26 global_macros.te
@@ -677,10 +677,6 @@
 allow $1 readable_t:dir r_dir_perms;
 allow $1 readable_t:notdevfile_class_set r_file_perms;
 
-# Read directories and files with the default file type (file_t).
-allow $1 file_t:dir r_dir_perms;
-allow $1 file_t:{ file lnk_file } r_file_perms;
-
 # Stat /...security and lost+found.
 allow $1 file_labels_t:dir getattr;
 allow $1 lost_found_t:dir getattr;
#2 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 6 lines · Russell Coker

I have two machines running ReiserFS for /var/cache/squid where files occasionally get changed to type system_u:object_r:file_t for no good reason.

This has happened for the last few kernel patches, with kernel 2.4.18 and 2.4.19, and is not related to power failures or crashes.

Or switching back and forth between a SELinux kernel and a non-SELinux kernel? That could cause the file to be re-created while running a non-SELinux kernel, leaving it with an unspecified PSID.

Not in this case. This has happened with machines that were not rebooted for any reason.

Quoted 2 lines

Unless ReiserFS is dynamically remapping inode numbers (which would be very bad for the SELinux persistent label mapping), I don't know why you

I don't think it's doing such things. If ReiserFS did that then SE Linux would not work at all, machines configured to be in enforcing mode at boot probably would not complete the boot process.

Quoted 6 lines

The only case where SELinux resets an inode to the default file PSID is when the inode is deleted (the final iput with a hard link count of zero). This isn't strictly necessary, since the inode will be reassigned a PSID when it is next allocated for a new file, but is good form. The first attached patch disables this code; you can try this patch if you like with ReiserFS to see if it makes any difference.

I'll give it a go, but it will take some time to get results.

Quoted 9 lines
Quoted 6 lines

However this raises another issue. In the default policy we allow almost everything read access to file_t directories, sym-links, and files. So any situation that results in a file changing to the default type (EG a power failure at an inconveniant time) may make a file world-readable!!!

Is there any reason for not restricting file_t to the administrator only?

Not anymore. The second attached patch removes general read access to file_t, although further testing and review is recommended.

I'll test it.

Signature · 10 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


--
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.