setfiles buglet
/usr/sbin/setfiles: conflicting specifications for /var/spool/postfix/incoming/6/9/69AB444B and /var/www/mrtg/eth1.old, using system_u:object_r:postfix_spool_t.
root@caesar:~# l -i /var/spool/postfix/incoming/6/9/69AB444B 1099 -rw------- 1 postfix postfix 0 Sep 19 05:23 /var/spool/postfix/incoming/6/9/69AB444B root@caesar:~# l -i /var/www/mrtg/eth1.old 8160 -rw-r--r-- 1 root root 58441 Sep 19 05:15 /var/www/mrtg/eth1.old root@caesar:~#
There is either a bug in setfiles or in it's documentation.
If run on a live system it can give inconsistant results as shown above. In the example above I believe that the /var/www directory got processed first, then the eth1.old file was unlinked and the inode number got re-used by postfix. This is on a P-133 machine and setfiles takes 6 minutes to run...
I think that either the documentation should mention that running in single user mode is a good idea (something I should have done when writing the man page), or it should stat the files again before changing the permissions (which still probably won't be flawless so changing the documentation is probably necessary).
Signature · 10 lines
There is no point PGP/GPG signing an email unless the signature can be verified. If you post to a list then don't sign the message unless your key is available on public key servers and has been signed by someone who is in the web of trust, otherwise you just waste bandwidth and CPU. -- 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.
Quoted 5 lines · Russell Coker
I think that either the documentation should mention that running in single user mode is a good idea (something I should have done when writing the man page), or it should stat the files again before changing the permissions (which still probably won't be flawless so changing the documentation is probably necessary).
I'd agree that running setfiles in single user mode is preferable. However, to reduce the likelihood of this problem occurring on a live system, the attached patch modifies setfiles to stat the file again and verify that the file still exists with the same inode number.
--
Stephen D. Smalley, NAI Labs
[email protected]
Index: selinux/setfiles/setfiles.c
===================================================================
RCS file: /cvs/lsm/selinux/setfiles/setfiles.c,v
retrieving revision 1.13
setfiles/setfiles.c +18 -1
@@ -149,12 +149,29 @@static file_spec_t *file_spec_add (ino_t ino,int specind,const char *file) {file_spec_t *prevfl, *fl; -int h, no_conflict; +int h, no_conflict, ret; +struct stat sb; h = (ino + (ino >>HASH_BITS )) &HASH_MASK ;for (prevfl = &fl_head[h], fl = fl_head[h].next; fl; prevfl = fl, fl = fl->next) {if (ino == fl->ino) { + ret =lstat (fl->file, &sb); +if (ret <0 || sb.st_ino != ino) { + fl->specind = specind; +free (fl->file); + fl->file =malloc (strlen (file) +1 ); +if (!fl->file) { +fprintf (stderr, +"%s: insufficient memory for file label entry for %s\n" , + progname, file); +return NULL ; + } +strcpy (fl->file, file); +return fl; + + } +if (flask_enabled) no_conflict = (spec[fl->specind].sid == spec[specind].sid);else