mini policy for initrd
I've developed a mini policy for an initrd, but now I have a problem.
On boot after the root file system is mounted the mappings of PSIDs to SIDs are made BEFORE the policy is loaded from the root file system. This means that 95% of all files on my root file system lose their labels...
Is there any possibility of solving this in the kernel? Or should I just make sure that my initrd policy contains all the types for all files on the root file system?
Signature · 9 lines
If you send email to me or to a mailing list that I use which has >4 lines of legalistic junk at the end then you are specifically authorizing me to do whatever I wish with the message and all other messages from your domain, by posting the message you agree that your long legalistic sig is void. -- You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · Russell Coker
I've developed a mini policy for an initrd, but now I have a problem.
On boot after the root file system is mounted the mappings of PSIDs to SIDs are made BEFORE the policy is loaded from the root file system. This means that 95% of all files on my root file system lose their labels...
Is there any possibility of solving this in the kernel? Or should I just make sure that my initrd policy contains all the types for all files on the root file system?
I'll try to look into solving this problem within the SELinux kernel module.
--
Stephen D. Smalley, NAI Labs
[email protected]
--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 9 lines · Russell Coker
I've developed a mini policy for an initrd, but now I have a problem.
On boot after the root file system is mounted the mappings of PSIDs to SIDs are made BEFORE the policy is loaded from the root file system. This means that 95% of all files on my root file system lose their labels...
Is there any possibility of solving this in the kernel? Or should I just make sure that my initrd policy contains all the types for all files on the root file system?
I've attached a patch that changes the SELinux kernel module to _not_ automatically remap invalid PSIDs when the PSID mapping is loaded and to reload the PSID mapping after a policy reload upon a change_root or pivot_root operation. This should address this problem. However, note the initrd policy will still need to define the types for the small set of files on the real root filesystem that are accessed prior to the completion of the PSID reloading, e.g. root_t, etc_t, policy_config_t, file_labels_t. This patch has not yet been committed. Feedback is welcome.
--
Stephen D. Smalley, NAI Labs
[email protected]
Index: security/selinux/hooks.c
===================================================================
RCS file: /cvs/lsm/lsm-2.4/security/selinux/hooks.c,v retrieving revision 1.69
selinux/hooks.c +49 -3
@@ -2160,8 +2160,12 @@static void selinux_post_mountroot (void ) { +struct super_block *sb; +struct superblock_security_struct *sbsec;int rc; +int reinit_psids =0 ; +if (!ss_precondition ()) {/* Perform the initial load of the policy during booting. A failure here is fatal unless the development module
@@ -2176,19 +2180,35 @@If one exists, it will replace the initrd policy. Otherwise, we continue operating under the initrd policy. This occurs when the old change_root mechanism is used. */ -if (sys_security_load_policy (NULL ,0 )) +if (sys_security_load_policy (NULL ,0 )) {printk ("selinux_post_mountroot: unable to reload policy from new root.\n" ); + }else { + reinit_psids =1 ; + } }if (!current->fs || !current->fs->rootmnt || !current->fs->rootmnt->mnt_sb) {printk ("selinux_post_mountroot: unable to initialize root filesystem.\n" );return ; } + sb = current->fs->rootmnt->mnt_sb; - rc =superblock_precondition (current->fs->rootmnt->mnt_sb); + rc =superblock_precondition (sb);if (rc <=0 )return ; +if (reinit_psids) { + sbsec = sb->s_security; +if (sbsec->uses_psids && sbsec->psidtab) { +psid_release (sb); + rc =psid_init (sb); +if (rc <0 ) { +printk ("selinux_post_mountroot: unable to reinitialize the PSID mapping\n" ); +return ; + } + } + } +return ; }
@@ -2206,12 +2226,38 @@static void selinux_post_pivotroot (struct nameidata *old_nd,struct nameidata *new_nd) { +struct super_block *sb; +struct superblock_security_struct *sbsec; +int rc; +/* Try to reload the policy from the new root filesystem. If one exists, it will replace the initrd policy. Otherwise, we continue operating under the initrd policy. This occurs when the pivot_root mechanism is used. */ -if (sys_security_load_policy (NULL ,0 )) +if (sys_security_load_policy (NULL ,0 )) {printk ("selinux_post_pivotroot: unable to reload policy.\n" ); +return ; + } + +/* Try to reinitialize the PSID mapping based on the new policy */ + +if (!new_nd->mnt || !new_nd->mnt->mnt_sb) +return ; + sb = new_nd->mnt->mnt_sb; + + rc =superblock_precondition (sb); +if (rc <=0 ) +return ; + sbsec = sb->s_security; + +if (sbsec->uses_psids && sbsec->psidtab) { +psid_release (sb); + rc =psid_init (sb); +if (rc <0 ) { +printk ("selinux_post_pivotroot: unable to reinitialize the PSID mapping\n" ); +return ; + } + } }/* inode security operations */
Index: security/selinux/psid.c
===================================================================
RCS file: /cvs/lsm/lsm-2.4/security/selinux/psid.c,v retrieving revision 1.1
selinux/psid.c +2 -0
@@ -616,6 +616,7 @@ if (rc) { printk("psidfiles_init: error %d in obtaining SID for context %s (psid %d).\n", -rc, cbuf, t->next_psid); +#if 0 if ((sb->s_flags & MS_RDONLY) == 0) { rc = write_abs(&t->index_fp, (const char*)&t->raw_sindex,
@@ -630,6 +631,7 @@if (t->n_bad <BAD_PSIDS ) t->bad_psids[t->n_bad++] = t->next_psid; } +#endif t->next_psid++; }else