SELinux: remove crazy contortions around proc
PATCH 1/7 SELinux: remove crazy contortions around proc
We check if the fsname is proc and if so set the proc superblock security struct flag. We then check if the flag is set and use the string 'proc' for the fsname instead of just using the fsname. What's the point? It's always proc... Get rid of the useless conditional.
--- security/selinux/hooks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/hooks.c +1 -1
@@ -673,7 +673,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, sbsec->flags |=SE_SBPROC ;/* Determine the labeling behavior to use for this filesystem type. */ - rc =security_fs_use ((sbsec->flags &SE_SBPROC ) ?"proc" : sb->s_type->name, &sbsec->behavior, &sbsec->sid); + rc =security_fs_use (sb->s_type->name, &sbsec->behavior, &sbsec->sid);if (rc) {printk (KERN_WARNING "%s: security_fs_use(%s) returned %d\n" , __func__, sb->s_type->name, rc);
--
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.
PATCH 2/7 SELinux: make it harder to get the number of mnt opts wrong
Instead of just hard coding a value, use the enum to out benefit.
--- security/selinux/hooks.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
security/selinux/hooks.c +3 -2
@@ -96,8 +96,6 @@#include "audit.h" #include "avc_ss.h" -#define NUM_SEL_MNT_OPTS 5 -extern struct security_operations *security_ops;/* SECMARK reference count */
@@ -309,8 +307,11 @@ enum { Opt_defcontext =3 , Opt_rootcontext =4 , Opt_labelsupport =5 , + Opt_nextmntopt = 6, }; +#define NUM_SEL_MNT_OPTS (Opt_nextmntopt - 1) +static const match_table_t tokens = { {Opt_context,CONTEXT_STR "%s" }, {Opt_fscontext, FSCONTEXT_STR "%s"},
--
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.
PATCH 3/7 SELinux: define bits in the mask in a header
In reply to Eric ParisWe had this random hard coded value of '8' in the code (I put it there) for the number of bits to check for mount options. This is stupid. Instead put the number of bits in the header so we don't hit problems down the road.
--- security/selinux/hooks.c | 5 ++++- security/selinux/include/security.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
security/selinux/hooks.c +4 -1
@@ -461,9 +461,12 @@ static int selinux_get_mnt_opts(const struct super_block *sb,if (!ss_initialized)return -EINVAL ; +/* make sure we always check enough bits to cover the mask */ +BUILD_BUG_ON (SE_MNTMASK >= (1 <<SE_MNTMASK_BITS )); + tmp = sbsec->flags &SE_MNTMASK ;/* count the number of mount options for this sb */ -for (i =0 ; i <8 ; i++) { +for (i =0 ; i <SE_MNTMASK_BITS ; i++) {if (tmp &0x01 ) opts->num_mnt_opts++; tmp >>=1 ;
security/selinux/include/security.h +1 -0
@@ -44,6 +44,7 @@/* Mask for just the mount related flags */ #define SE_MNTMASK 0x0f +#define SE_MNTMASK_BITS 4/* Super block security struct flags for mount options */ #define CONTEXT_MNT 0x01#define FSCONTEXT_MNT 0x02
--
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.
PATCH 4/7 SELinux: pass a sbsec to security_fs_use
In reply to Eric ParisRather than passing pointers to memory locations inside security_fs_use just pass the struct itself. As we need more fields later, this cuts down on future argument lists.
--- security/selinux/hooks.c | 2 +- security/selinux/include/security.h | 4 ++-- security/selinux/ss/services.c | 18 +++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-)
security/selinux/hooks.c +1 -1
@@ -677,7 +677,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, sbsec->flags |=SE_SBPROC ;/* Determine the labeling behavior to use for this filesystem type. */ - rc =security_fs_use (sb->s_type->name, &sbsec->behavior, &sbsec->sid); + rc =security_fs_use (sb->s_type->name, sbsec);if (rc) {printk (KERN_WARNING "%s: security_fs_use(%s) returned %d\n" , __func__, sb->s_type->name, rc);
security/selinux/include/security.h +2 -2
@@ -173,8 +173,8 @@ int security_get_allow_unknown(void);#define SECURITY_FS_USE_NONE 5/* no labeling support */ #define SECURITY_FS_USE_MNTPOINT 6/* use mountpoint labeling */ -int security_fs_use (const char *fstype,unsigned int *behavior, -u32 *sid); +struct superblock_security_struct ; +int security_fs_use (const char *fstype,struct superblock_security_struct *sbsec);int security_genfs_sid (const char *fstype,char *name,u16 sclass,u32 *sid);
security/selinux/ss/services.c +7 -11
@@ -2327,13 +2327,9 @@ out:/** * security_fs_use - Determine how to handle labeling for a filesystem. * @fstype: filesystem type -* @behavior: labeling behavior -* @sid: SID for filesystem (superblock) +* @sbsec: security structure for the superblock in question */ -int security_fs_use ( -const char *fstype, -unsigned int *behavior, -u32 *sid) +int security_fs_use (const char *fstype,struct superblock_security_struct *sbsec) {int rc =0 ;struct ocontext *c;
@@ -2348,21 +2344,21 @@ int security_fs_use( }if (c) { - *behavior = c->v.behavior; + sbsec->behavior = c->v.behavior;if (!c->sid[0 ]) { rc =sidtab_context_to_sid (&sidtab, &c->context[0 ], &c->sid[0 ]);if (rc) goto out; } - *sid = c->sid[0 ]; + sbsec->sid = c->sid[0 ]; }else { - rc =security_genfs_sid (fstype,"/" ,SECCLASS_DIR , sid); + rc =security_genfs_sid (fstype,"/" ,SECCLASS_DIR , &sbsec->sid);if (rc) { - *behavior =SECURITY_FS_USE_NONE ; + sbsec->behavior =SECURITY_FS_USE_NONE ; rc =0 ; }else { - *behavior =SECURITY_FS_USE_GENFS ; + sbsec->behavior =SECURITY_FS_USE_GENFS ; } }
--
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.
Re: [PATCH 4/7] SELinux: pass a sbsec to security_fs_use
Quoted 5 lines · Eric Paris
Rather than passing pointers to memory locations inside
security_fs_usejust pass the struct itself. As we need more fields later, this cuts down on future argument lists.Signed-off-by Eric Paris <[email protected]>
Not a hard NAK, but we originally tried to maintain a clean separation between the hook function implementations and the security server, and the security server had no knowledge of the security structures or other kernel-internal data structures. I think that line has blurred over time with the netlabel and audit support, and perhaps it has limited usefulness now, but wanted to note it.
Quoted 81 lines
--- security/selinux/hooks.c | 2 +- security/selinux/include/security.h | 4 ++-- security/selinux/ss/services.c | 18 +++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-)security/selinux/hooks.c +1
-1@@ -677,7 +677,7 @@ static int selinux_set_mnt_opts(struct super_block *sb, sbsec->flags |=SE_SBPROC ;/* Determine the labeling behavior to use for this filesystem type. */ - rc =security_fs_use (sb->s_type->name, &sbsec->behavior, &sbsec->sid); + rc =security_fs_use (sb->s_type->name, sbsec);if (rc) {printk (KERN_WARNING "%s: security_fs_use(%s) returned %d\n" , __func__, sb->s_type->name, rc);security/selinux/include/security.h +2
-2@@ -173,8 +173,8 @@ int security_get_allow_unknown(void);#define SECURITY_FS_USE_NONE 5/* no labeling support */ #define SECURITY_FS_USE_MNTPOINT 6/* use mountpoint labeling */ -int security_fs_use (const char *fstype,unsigned int *behavior, -u32 *sid); +struct superblock_security_struct ; +int security_fs_use (const char *fstype,struct superblock_security_struct *sbsec);int security_genfs_sid (const char *fstype,char *name,u16 sclass,u32 *sid);security/selinux/ss/services.c +7
-11@@ -2327,13 +2327,9 @@ out:/** * security_fs_use - Determine how to handle labeling for a filesystem. * @fstype: filesystem type -* @behavior: labeling behavior -* @sid: SID for filesystem (superblock) +* @sbsec: security structure for the superblock in question */ -int security_fs_use ( -const char *fstype, -unsigned int *behavior, -u32 *sid) +int security_fs_use (const char *fstype,struct superblock_security_struct *sbsec) {int rc =0 ;struct ocontext *c;@@ -2348,21 +2344,21 @@ int security_fs_use( }if (c) { - *behavior = c->v.behavior; + sbsec->behavior = c->v.behavior;if (!c->sid[0 ]) { rc =sidtab_context_to_sid (&sidtab, &c->context[0 ], &c->sid[0 ]);if (rc) goto out; } - *sid = c->sid[0 ]; + sbsec->sid = c->sid[0 ]; }else { - rc =security_genfs_sid (fstype,"/" ,SECCLASS_DIR , sid); + rc =security_genfs_sid (fstype,"/" ,SECCLASS_DIR , &sbsec->sid);if (rc) { - *behavior =SECURITY_FS_USE_NONE ; + sbsec->behavior =SECURITY_FS_USE_NONE ; rc =0 ; }else { - *behavior =SECURITY_FS_USE_GENFS ; + sbsec->behavior =SECURITY_FS_USE_GENFS ; } }
Signature · 8 lines
Stephen Smalley 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.
PATCH 5/7 SELinux: do all flags twiddling in one place
In reply to Eric ParisCurrently we set the initialize and seclabel flag in one place. Do some unrelated printk then we unset the seclabel flag. Eww. Instead do the flag twiddling in one place in the code not seperated by unrelated printk. Also don't set and unset the seclabel flag. Only set it if we need to.
--- security/selinux/hooks.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
security/selinux/hooks.c +5 -7
@@ -389,8 +389,6 @@ static int sb_finish_set_opts(struct super_block *sb) } } - sbsec->flags |= (SE_SBINITIALIZED |SE_SBLABELSUPP ); -if (sbsec->behavior >ARRAY_SIZE (labeling_behaviors))printk (KERN_ERR "SELinux: initialized (dev %s, type %s), unknown behavior\n" , sb->s_id, sb->s_type->name);
@@ -399,11 +397,11 @@ static int sb_finish_set_opts(struct super_block *sb) sb->s_id, sb->s_type->name, labeling_behaviors[sbsec->behavior-1]); -if (sbsec->behavior ==SECURITY_FS_USE_GENFS || - sbsec->behavior ==SECURITY_FS_USE_MNTPOINT || - sbsec->behavior ==SECURITY_FS_USE_NONE || - sbsec->behavior >ARRAY_SIZE (labeling_behaviors)) - sbsec->flags &= ~SE_SBLABELSUPP ; + sbsec->flags |=SE_SBINITIALIZED ; +if (sbsec->behavior ==SECURITY_FS_USE_XATTR || + sbsec->behavior ==SECURITY_FS_USE_TRANS || + sbsec->behavior ==SECURITY_FS_USE_TASK ) + sbsec->flags |=SE_SBLABELSUPP ;/* Special handling for sysfs. Is genfs but also has setxattr handler*/ if (strncmp (sb->s_type->name,"sysfs" ,sizeof ("sysfs" )) ==0 )
--
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.
PATCH 6/7 SELinux: do not handle seclabel as a special flag
In reply to Eric ParisInstead of having special code around the 'non-mount' seclabel mount option just handle it like the mount options.
--- security/selinux/hooks.c | 3 --- security/selinux/include/security.h | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-)
security/selinux/hooks.c +0 -3
@@ -469,9 +469,6 @@ static int selinux_get_mnt_opts(const struct super_block *sb, opts->num_mnt_opts++; tmp >>=1 ; } -/* Check if the Label support flag is set */ -if (sbsec->flags &SE_SBLABELSUPP ) - opts->num_mnt_opts++; opts->mnt_opts =kcalloc (opts->num_mnt_opts,sizeof (char *),GFP_ATOMIC );if (!opts->mnt_opts) {
security/selinux/include/security.h +5 -5
@@ -43,17 +43,17 @@#endif /* Mask for just the mount related flags */ -#define SE_MNTMASK 0x0f -#define SE_MNTMASK_BITS 4 +#define SE_MNTMASK 0x1f +#define SE_MNTMASK_BITS 5/* Super block security struct flags for mount options */ #define CONTEXT_MNT 0x01#define FSCONTEXT_MNT 0x02#define ROOTCONTEXT_MNT 0x04#define DEFCONTEXT_MNT 0x08 +#define SE_SBLABELSUPP 0x10/* Non-mount related flags */ -#define SE_SBINITIALIZED 0x10 -#define SE_SBPROC 0x20 -#define SE_SBLABELSUPP 0x40 +#define SE_SBINITIALIZED 0x20 +#define SE_SBPROC 0x40#define CONTEXT_STR "context="#define FSCONTEXT_STR "fscontext="
--
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.
PATCH 7/7 SELinux: mount option to force xattr test
In reply to Eric ParisAt the moment we hard code in policy which filesystems support xattrs and which do not. Although FUSE supports xattrs it has a deadlock if the kernel makes an xattr call before mount(8) (NOT mount(2)) returns successfully. This is especially broken since even during mount(2) the kernel believes the FS is ready for use immediately after the filesystem ops init call. Obviously at this point mount(2) and mount(8) aren't finished so doing so will deadlock FUSE.
So we have to hard code in SELinux policy that FUSE does not support xattrs. There is a version of FUSE which solves this problem by doing work in parallel to the mount(8). However we cannot distinguish which version is which! This gives meaning to the existing 'seclabel' mount option which is currently ignored. It will use the option to force the kernel to check if xattrs on the filesystem can be used, imitating the same behaviour as if the policy declared the filesystem type xattr capable.
The intention is that future FUSE will be able to set the seclabel mount option once it is able to handle xattr calls during mount(2) while we retain the policy statement that FUSE does not support xattrs. Old FUSE will continue to work as it does today and new FUSE will seamlessly be able to transition to using xattrs.
--- security/selinux/hooks.c | 16 ++++++++++++++-- security/selinux/ss/services.c | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-)
security/selinux/hooks.c +14 -2
@@ -605,8 +605,10 @@ static int selinux_set_mnt_opts(struct super_block *sb,for (i =0 ; i < num_opts; i++) {u32 sid; -if (flags[i] ==SE_SBLABELSUPP ) +if (flags[i] ==SE_SBLABELSUPP ) { + sbsec->flags |=SE_SBLABELSUPP ;continue ; + } rc =security_context_to_sid (mount_options[i],strlen (mount_options[i]), &sid);if (rc) {
@@ -815,7 +817,7 @@ static int selinux_parse_opts_str(char *options,char *p;char *context =NULL , *defcontext =NULL ;char *fscontext =NULL , *rootcontext =NULL ; -int rc, num_mnt_opts =0 ; +int rc, num_mnt_opts =0 , forceseclabel =0 ; opts->num_mnt_opts =0 ;
@@ -882,6 +884,12 @@ static int selinux_parse_opts_str(char *options, }break ;case Opt_labelsupport: +if (context) { + rc = -EINVAL ; + printk(KERN_WARNING SEL_MOUNT_FAIL_MSG); + goto out_err; + } + forceseclabel =1 ;break ;default : rc = -EINVAL ;
@@ -902,6 +910,10 @@ static int selinux_parse_opts_str(char *options, goto out_err; } +if (forceseclabel) { + opts->mnt_opts[num_mnt_opts] =NULL ; + opts->mnt_opts_flags[num_mnt_opts++] =SE_SBLABELSUPP ; + }if (fscontext) { opts->mnt_opts[num_mnt_opts] = fscontext; opts->mnt_opts_flags[num_mnt_opts++] =FSCONTEXT_MNT ;
security/selinux/ss/services.c +2 -0
@@ -2361,6 +2361,8 @@ int security_fs_use(const char *fstype, struct superblock_security_struct *sbsec sbsec->behavior =SECURITY_FS_USE_GENFS ; } } +if (sbsec->flags &SE_SBLABELSUPP ) + sbsec->behavior =SECURITY_FS_USE_XATTR ; out:read_unlock (&policy_rwlock);
--
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.