new kernel patch
Subsystems (6)
Quoted 10 lines
When an inode is allocated, its SID is initialized to the unlabeled initial SID (=> system_u:object_r:unlabeled_t), and its security class is initialized to the file class by default. This log message indicates that a devfs inode reached a permission check without first being initialized by
inode_doinit, likely due to a race betweenselinux_inode_post_lookupand a cached lookup. The empty permission set is due to an inability to map the requested permission (likely search) to a permission in the file class.
Quoted 3 lines
As a short term fix, I'd suggest the attached patch. A proper fix requires adjusting the
inode_initcall ind_instantiateand the SELinux hook function to properly handle filesystems that rely ongenfs_contexts.
The attached patches, also committed to the sourceforge CVS tree, should implement a proper fix to this problem. To apply to an existing tree, you would revert the short term fix (perminit.patch), revert the old version of the selinux-2.[45].patch, apply the attached lsm-2.[45]-inode.patch, and then apply the attached new version of the selinux-2.[45].patch.
As a side note, if you haven't already picked it up, don't forget to apply the nfsd.patch to your lsm-2.4 tree as well (the second patch included in
http://marc.theaimsgroup.com/?l=selinux&m=104041691605427&w=2, also committed to the sourceforge CVS tree). The lsm-2.5 tree is already fine in that regard.
--
Stephen Smalley, NSA
[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.23
security/selinux/hooks.c +16 -15
@@ -458,7 +458,12 @@ "not configured for labeling" }; -static int inode_doinit (struct inode *inode); +static int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry); + +static inline int inode_doinit (struct inode *inode) +{ +return inode_doinit_with_dentry (inode,NULL ); +}static int superblock_doinit (struct super_block *sb) {
@@ -548,7 +553,7 @@ labeling_behaviors[behavior-1]);/* Initialize the root inode. */ - rc =inode_doinit (sb->s_root->d_inode); + rc =inode_doinit_with_dentry (sb->s_root->d_inode, sb->s_root);if (rc)return rc;
@@ -560,7 +565,7 @@* The /proc/PID entries are labeled with the SID of the owning process. * Most entries simply inherit their SID from the parent directory SID. */ -static void procfs_set_sid (struct dentry *dentry) +static void procfs_set_sid (struct inode *inode,struct dentry *dentry) {struct task_security_struct *tsec;struct inode_security_struct *isec, *pisec;
@@ -570,10 +575,7 @@const char *name;int len; -if (!dentry->d_inode) -return ; - - isec = dentry->d_inode->i_security; + isec = inode->i_security;#ifndef _SELINUX_KERNEL_PATCH_if (!isec)return ;
@@ -641,7 +643,7 @@ char *buffer, int buflen);/* The inode's security attributes must be initialized before first use. */ -static int inode_doinit (struct inode *inode) +static int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry) {struct superblock_security_struct *sbsec =NULL ;struct inode_security_struct *isec = inode->i_security;
@@ -716,7 +718,10 @@ isec->sid = sbsec->sid;/* Obtain a SID based on the fstype, path, and class. */ - dentry =d_find_alias (inode); +if (opt_dentry) + dentry =dget (opt_dentry); +else + dentry =d_find_alias (inode);if (dentry) { buffer = (char *)__get_free_page (GFP_KERNEL );if (buffer) {
@@ -747,7 +752,7 @@if (sbsec->proc) {/* Handle /proc/PID. */ -procfs_set_sid (dentry); +procfs_set_sid (inode, dentry); }dput (dentry);
@@ -2032,7 +2037,7 @@/* No permission to check. Existence test. */ return 0 ; } - +return inode_has_perm (current, inode,file_mask_to_av (inode->i_mode, mask),NULL ,NULL ); }
@@ -2066,10 +2071,6 @@static void selinux_inode_post_lookup (struct inode *dir,struct dentry *dentry) { -struct inode *inode = dentry->d_inode; - -if (inode) -inode_doinit (inode);return ; }
Index: lsm-2.5/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/security/selinux/hooks.c,v retrieving revision 1.11
security/selinux/hooks.c +15 -14
@@ -461,7 +461,12 @@ "not configured for labeling" }; -static int inode_doinit (struct inode *inode); +static int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry); + +static inline int inode_doinit (struct inode *inode) +{ +return inode_doinit_with_dentry (inode,NULL ); +}static int superblock_doinit (struct super_block *sb) {
@@ -551,7 +556,7 @@ labeling_behaviors[behavior-1]);/* Initialize the root inode. */ - rc =inode_doinit (sb->s_root->d_inode); + rc =inode_doinit_with_dentry (sb->s_root->d_inode, sb->s_root);if (rc)return rc;
@@ -563,7 +568,7 @@* The /proc/PID entries are labeled with the SID of the owning process. * Most entries simply inherit their SID from the parent directory SID. */ -static void procfs_set_sid (struct dentry *dentry) +static void procfs_set_sid (struct inode *inode,struct dentry *dentry) {struct task_security_struct *tsec;struct inode_security_struct *isec, *pisec;
@@ -573,10 +578,7 @@const char *name;int len; -if (!dentry->d_inode) -return ; - - isec = dentry->d_inode->i_security; + isec = inode->i_security;#ifndef _SELINUX_KERNEL_PATCH_if (!isec)return ;
@@ -644,7 +646,7 @@ char *buffer, int buflen);/* The inode's security attributes must be initialized before first use. */ -static int inode_doinit (struct inode *inode) +static int inode_doinit_with_dentry (struct inode *inode,struct dentry *opt_dentry) {struct superblock_security_struct *sbsec =NULL ;struct inode_security_struct *isec = inode->i_security;
@@ -719,7 +721,10 @@ isec->sid = sbsec->sid;/* Obtain a SID based on the fstype, path, and class. */ - dentry =d_find_alias (inode); +if (opt_dentry) + dentry =dget (opt_dentry); +else + dentry =d_find_alias (inode);if (dentry) { buffer = (char *)__get_free_page (GFP_KERNEL );if (buffer) {
@@ -750,7 +755,7 @@if (sbsec->proc) {/* Handle /proc/PID. */ -procfs_set_sid (dentry); +procfs_set_sid (inode, dentry); }dput (dentry);
@@ -2073,10 +2078,6 @@static void selinux_inode_post_lookup (struct inode *dir,struct dentry *dentry) { -struct inode *inode = dentry->d_inode; - -if (inode) -inode_doinit (inode);return ; }
Index: lsm-2.4/Makefile
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/Makefile,v
retrieving revision 1.1.1.6
Makefile +1 -1
@@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 4 SUBLEVEL = 20 -EXTRAVERSION = -lsm1 +EXTRAVERSION = -selinux KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
Index: lsm-2.4/arch/i386/defconfig
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/arch/i386/defconfig,v retrieving revision 1.1.1.4
arch/i386/defconfig +11 -1
@@ -160,7 +160,8 @@ CONFIG_PACKET=y # CONFIG_PACKET_MMAP is not set # CONFIG_NETLINK_DEV is not set -# CONFIG_NETFILTER is not set +CONFIG_NETFILTER=y +# CONFIG_NETFILTER_DEBUG is not set # CONFIG_FILTER is not set CONFIG_UNIX=y CONFIG_INET=y
@@ -879,3 +880,12 @@ # Kernel hacking # # CONFIG_DEBUG_KERNEL is not set + +# +# Security options +# +CONFIG_SECURITY_CAPABILITIES=y +CONFIG_SECURITY_SELINUX=y +CONFIG_SECURITY_SELINUX_DEVELOP=y +CONFIG_SECURITY_SELINUX_NSID=n +CONFIG_SECURITY_SELINUX_SELOPT=n
Index: lsm-2.4/fs/dcache.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/fs/dcache.c,v retrieving revision 1.1.1.5
fs/dcache.c +1 -0
@@ -651,6 +651,7 @@void d_instantiate (struct dentry *entry,struct inode * inode) {if (!list_empty (&entry->d_alias))BUG (); + security_ops->d_instantiate (entry, inode);spin_lock (&dcache_lock);if (inode)list_add (&entry->d_alias, &inode->i_dentry);
Index: lsm-2.4/fs/devpts/inode.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/fs/devpts/inode.c,v retrieving revision 1.1.1.1
fs/devpts/inode.c +1 -0
@@ -199,6 +199,7 @@ inode->i_gid = sbi->setgid ? sbi->gid : current->fsgid; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME ;init_special_inode (inode,S_IFCHR |sbi->mode,kdev_t_to_nr (device)); + security_ops->devpts_pty_new (inode);if ( sbi->inodes[number] ) {iput (inode);
Index: lsm-2.4/include/linux/security.h
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/include/linux/security.h,v retrieving revision 1.1.1.7
include/linux/security.h +5 -0
@@ -1425,6 +1425,11 @@ struct security_operations * ops);int (*unregister_security) (const char *name,struct security_operations * ops); + +/* Added by the separate SELinux patch. */ +void (*devpts_pty_new) (struct inode * inode); +void (*d_instantiate) (struct dentry * dentry,struct inode * inode); + };/* prototypes */
Index: lsm-2.4/init/do_mounts.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/init/do_mounts.c,v retrieving revision 1.1.1.2
init/do_mounts.c +2 -0
@@ -812,6 +812,8 @@/* switch root and cwd back to / of rootfs */ sys_fchdir (root_fd);sys_chroot ("." ); +close (old_fd); +close (root_fd);sys_umount ("/old/dev" ,0 );if (real_root_dev == ram0) {
Index: lsm-2.4/init/main.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/init/main.c,v retrieving revision 1.1.1.4
init/main.c +7 -0
@@ -342,6 +342,10 @@cpu_idle (); } +#ifdef CONFIG_SECURITY_SELINUX +extern void selinux_init (void ); +#endif +/* * Activate the first processor. */
@@ -412,6 +416,9 @@fork_init (num_mappedpages);proc_caches_init ();security_scaffolding_startup (); +#ifdef CONFIG_SECURITY_SELINUX +selinux_init (); +#endif vfs_caches_init (num_physpages);buffer_init (num_physpages);page_cache_init (num_physpages);
Index: lsm-2.4/net/netsyms.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/net/netsyms.c,v retrieving revision 1.1.1.5
net/netsyms.c +3 -1
@@ -295,7 +295,9 @@#include <net/ip6_route.h> EXPORT_SYMBOL (ip6_route_output);#endif -#if defined (CONFIG_IPV6_MODULE ) || defined (CONFIG_KHTTPD ) || defined (CONFIG_KHTTPD_MODULE ) +#if defined (CONFIG_IPV6_MODULE ) || defined (CONFIG_KHTTPD ) || \ + defined (CONFIG_KHTTPD_MODULE ) || defined (CONFIG_SECURITY_SELINUX_SELOPT_MODULE ) +extern struct tcp_func ipv4_specific;/* inet functions common to v4 and v6 */ EXPORT_SYMBOL (inet_release);EXPORT_SYMBOL (inet_stream_connect);
Index: lsm-2.4/security/capability.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/capability.c,v retrieving revision 1.1.1.6
security/capability.c +13 -0
@@ -1065,6 +1065,16 @@return -EINVAL ; } +static void cap_devpts_pty_new (struct inode *inode) +{ +return ; +} + +static void cap_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} +static struct security_operations capability_ops = { sethostname: cap_sethostname, setdomainname: cap_setdomainname,
@@ -1242,6 +1252,9 @@ register_security: cap_register, unregister_security: cap_unregister, + + devpts_pty_new: cap_devpts_pty_new, + d_instantiate: cap_d_instantiate, };#if defined(CONFIG_SECURITY_CAPABILITIES_MODULE )
Index: lsm-2.4/security/dummy.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/dummy.c,v retrieving revision 1.1.1.7
security/dummy.c +13 -0
@@ -886,6 +886,16 @@return -EINVAL ; } +static void dummy_devpts_pty_new (struct inode *inode) +{ +return ; +} + +static void dummy_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} +struct security_operations dummy_security_ops = { sethostname: dummy_sethostname, setdomainname: dummy_setdomainname,
@@ -1063,5 +1073,8 @@ register_security: dummy_register, unregister_security: dummy_unregister, + + devpts_pty_new: dummy_devpts_pty_new, + d_instantiate: dummy_d_instantiate, };
Index: lsm-2.4/security/owlsm.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/owlsm.c,v retrieving revision 1.1.1.6
security/owlsm.c +13 -0
@@ -901,6 +901,16 @@return -EINVAL ; } +static void owlsm_devpts_pty_new (struct inode *inode) +{ +return ; +} + +static void owlsm_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} +static struct security_operations owlsm_ops = { sethostname: owlsm_sethostname, setdomainname: owlsm_setdomainname,
@@ -1078,6 +1088,9 @@ register_security: owlsm_register, unregister_security: owlsm_unregister, + + devpts_pty_new: owlsm_devpts_pty_new, + d_instantiate: owlsm_d_instantiate, };#if defined(CONFIG_SECURITY_owlsm_MODULE)
Index: lsm-2.4/security/dte/dte.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/dte/dte.c,v retrieving revision 1.1.1.6
security/dte/dte.c +13 -0
@@ -934,6 +934,16 @@return dte_secondary_ops->unregister_security (name, ops); } +static void dte_devpts_pty_new (struct inode *inode) +{ +return ; +} + +static void dte_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} +struct security_operations dte_security_ops = { sethostname: dte_sethostname, setdomainname: dte_setdomainname,
@@ -1110,6 +1120,9 @@ register_security: dte_register, unregister_security: dte_unregister, + + devpts_pty_new: dte_devpts_pty_new, + d_instantiate: dte_d_instantiate, };extern int setup_dte_module (void );
Index: lsm-2.4/security/lids/lids_lsm.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/lids/lids_lsm.c,v retrieving revision 1.1.1.4
security/lids/lids_lsm.c +13 -0
@@ -1106,6 +1106,16 @@return -EINVAL ; } +static void lids_devpts_pty_new (struct inode *inode) +{ +return ; +} + +static void lids_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} +struct security_operations lids_security_ops = { sethostname: lids_sethostname, setdomainname: lids_setdomainname,
@@ -1288,6 +1298,9 @@ register_security: lids_register, unregister_security: lids_unregister, + + devpts_pty_new: lids_devpts_pty_new, + d_instantiate: lids_d_instantiate, };extern void setup_lids_module (void );
Index: lsm-2.4/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/hooks.c,v retrieving revision 1.24
security/selinux/hooks.c +16 -0
@@ -62,6 +62,8 @@#include "selinux_plug.h" #include "extsocket.h" +#define _SELINUX_KERNEL_PATCH_ +#ifndef _SELINUX_KERNEL_PATCH_#warning "SELinux: The separate SELinux kernel patch has not been applied. Using SELinux without this patch is not recommended."#endif
@@ -3991,6 +3993,17 @@return 0 ; } +static void selinux_devpts_pty_new (struct inode *inode) +{ +inode_doinit (inode); +} + +static void selinux_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +if (inode) +inode_doinit_with_dentry (inode, dentry); +} +struct security_operations selinux_ops = { sethostname: selinux_sethostname, setdomainname: selinux_setdomainname,
@@ -4167,6 +4180,9 @@ register_security: &selinux_register_security, unregister_security: &selinux_unregister_security, + + devpts_pty_new: selinux_devpts_pty_new, + d_instantiate: selinux_d_instantiate, };extern long sys_security_selinux (struct pt_regs regs);
Index: lsm-2.5/Makefile
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/Makefile,v
retrieving revision 1.1.1.8
Makefile +1 -1
@@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 5 SUBLEVEL = 51 -EXTRAVERSION = -lsm1 +EXTRAVERSION = -selinux # *DOCUMENTATION* # To see a list of typical targets execute "make help"
Index: lsm-2.5/arch/i386/defconfig
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/arch/i386/defconfig,v retrieving revision 1.1.1.5
arch/i386/defconfig +11 -1
@@ -401,7 +401,7 @@ CONFIG_PACKET=y # CONFIG_PACKET_MMAP is not set # CONFIG_NETLINK_DEV is not set -# CONFIG_NETFILTER is not set +CONFIG_NETFILTER=y # CONFIG_FILTER is not set CONFIG_UNIX=y CONFIG_INET=y
@@ -1169,3 +1169,13 @@ CONFIG_X86_SMP=y CONFIG_X86_HT=y CONFIG_X86_BIOS_REBOOT=y + +# +# Security options +# +CONFIG_SECURITY=y +CONFIG_SECURITY_CAPABILITIES=y +CONFIG_SECURITY_SELINUX=y +CONFIG_SECURITY_SELINUX_DEVELOP=y +CONFIG_SECURITY_SELINUX_NSID=y +CONFIG_SECURITY_SELINUX_SELOPT=y
Index: lsm-2.5/fs/dcache.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/fs/dcache.c,v retrieving revision 1.1.1.8
fs/dcache.c +3 -0
@@ -25,6 +25,7 @@#include <linux/module.h> #include <linux/mount.h> #include <asm/uaccess.h> +#include <linux/security.h> #define DCACHE_PARANOIA 1/* #define DCACHE_DEBUG 1 */
@@ -699,6 +700,7 @@void d_instantiate (struct dentry *entry,struct inode * inode) {if (!list_empty (&entry->d_alias))BUG (); +security_d_instantiate (entry, inode);spin_lock (&dcache_lock);if (inode)list_add (&entry->d_alias, &inode->i_dentry);
@@ -825,6 +827,7 @@struct dentry *new =NULL ;if (inode &&S_ISDIR (inode->i_mode)) { +security_d_instantiate (dentry, inode);spin_lock (&dcache_lock);if (!list_empty (&inode->i_dentry)) { new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
Index: lsm-2.5/include/linux/security.h
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/include/linux/security.h,v retrieving revision 1.1.1.8
include/linux/security.h +10 -0
@@ -1375,6 +1375,9 @@ struct security_operations *ops);int (*unregister_security) (const char *name,struct security_operations *ops); + +/* Added by the separate SELinux patch. */ +void (*d_instantiate) (struct dentry * dentry,struct inode * inode); };/* global variables */
@@ -2244,6 +2247,10 @@return security_ops->sem_semctl (sma, cmd); } +static inline void security_d_instantiate (struct dentry *dentry,struct inode *inode) +{ + security_ops->d_instantiate (dentry, inode); +}/* prototypes */ extern int security_scaffolding_startup (void );
@@ -3066,6 +3073,9 @@ {return 0 ; } + +static inline void security_d_instantiate (struct dentry *dentry,struct inode *inode) +{ }#endif /* CONFIG_SECURITY */
Index: lsm-2.5/init/main.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/init/main.c,v retrieving revision 1.1.1.8
init/main.c +7 -0
@@ -370,6 +370,10 @@cpu_idle (); } +#ifdef CONFIG_SECURITY_SELINUX +extern void selinux_init (void ); +#endif +/* * Activate the first processor. */
@@ -425,6 +429,9 @@fork_init (num_physpages);proc_caches_init ();security_scaffolding_startup (); +#ifdef CONFIG_SECURITY_SELINUX +selinux_init (); +#endif buffer_init ();vfs_caches_init (num_physpages);radix_tree_init ();
Index: lsm-2.5/net/netsyms.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/net/netsyms.c,v retrieving revision 1.1.1.8
net/netsyms.c +2 -1
@@ -324,7 +324,8 @@EXPORT_SYMBOL (xfrm_policy_list); -#if defined (CONFIG_IPV6_MODULE ) || defined (CONFIG_IP_SCTP_MODULE ) +#if defined (CONFIG_IPV6_MODULE ) || defined (CONFIG_IP_SCTP_MODULE ) || defined (CONFIG_SECURITY_SELINUX_SELOPT_MODULE ) +extern struct tcp_func ipv4_specific;/* inet functions common to v4 and v6 */ EXPORT_SYMBOL (inet_release);EXPORT_SYMBOL (inet_stream_connect);
Index: lsm-2.5/security/dummy.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/security/dummy.c,v retrieving revision 1.2
security/dummy.c +7 -0
@@ -873,6 +873,12 @@return -EINVAL ; } +static void dummy_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +return ; +} + +struct security_operations dummy_security_ops;#define set_to_dummy_if_null (ops, function) \
@@ -1039,5 +1045,6 @@set_to_dummy_if_null (ops, skb_set_owner_w);set_to_dummy_if_null (ops, skb_recv_datagram);set_to_dummy_if_null (ops, skb_free_security); +set_to_dummy_if_null (ops, d_instantiate); }
Index: lsm-2.5/security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.5/security/selinux/hooks.c,v retrieving revision 1.12
security/selinux/hooks.c +10 -0
@@ -65,6 +65,8 @@#include "selinux_plug.h" #include "extsocket.h" +#define _SELINUX_KERNEL_PATCH_ +#ifndef _SELINUX_KERNEL_PATCH_#warning "SELinux: The separate SELinux kernel patch has not been applied. Using SELinux without this patch is not recommended."#endif
@@ -3994,6 +3996,12 @@return 0 ; } +static void selinux_d_instantiate (struct dentry *dentry,struct inode *inode) +{ +if (inode) +inode_doinit_with_dentry (inode, dentry); +} +struct security_operations selinux_ops = { sethostname: selinux_sethostname, setdomainname: selinux_setdomainname,
@@ -4164,6 +4172,8 @@ register_security: &selinux_register_security, unregister_security: &selinux_unregister_security, + + d_instantiate: selinux_d_instantiate, };extern long sys_security_selinux (struct pt_regs regs);