SELinux: fix selinux to safely handle any bugs even when not CONFIG_BUG
Subsystems (2)
PATCH 1/3 SELinux: fix selinux to safely handle any bugs even when not CONFIG_BUG
If CONFIG_BUG is not set places in the code where BUG is called will not end execution. Look for places where this might result is system problems and keep the system running.
---
kernel/capability.c | 1 + security/selinux/avc.c | 9 +++++-- security/selinux/hooks.c | 8 +++++- security/selinux/netnode.c | 3 ++ security/selinux/ss/ebitmap.h | 15 +++++++++-- security/selinux/ss/services.c | 54 +++++++++++++++++++++++++++++----------- security/selinux/xfrm.c | 15 +++++++++-- 7 files changed, 81 insertions(+), 24 deletions(-)
kernel/capability.c +1 -0
@@ -304,6 +304,7 @@ int capable(int cap)if (unlikely (!cap_valid (cap))) {printk (KERN_CRIT "capable() called with invalid cap=%u\n" , cap);BUG (); +return 0 ; }if (security_capable (cap) ==0 ) {
security/selinux/avc.c +7 -2
@@ -220,8 +220,13 @@ static void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tclakfree (scontext); } -BUG_ON (tclass >=ARRAY_SIZE (class_to_string) || !class_to_string[tclass]); -audit_log_format (ab," tclass=%s" , class_to_string[tclass]); +if (unlikely (tclass >=ARRAY_SIZE (class_to_string) || !class_to_string[tclass])) { +printk (KERN_ERR "%s: with tclass=%d\n" , __func__, tclass); +BUG (); +audit_log_format (ab," tclass=%d" , tclass); + }else { +audit_log_format (ab," tclass=%s" , class_to_string[tclass]); + } }/**
security/selinux/hooks.c +7 -1
@@ -995,7 +995,11 @@ static int superblock_doinit(struct super_block *sb, void *data)if (!data) goto out; -BUG_ON (sb->s_type->fs_flags &FS_BINARY_MOUNTDATA ); +if (unlikely (sb->s_type->fs_flags &FS_BINARY_MOUNTDATA )) { +BUG (); + rc = -EINVAL ; + goto out_err; + } rc =selinux_parse_opts_str (options, &opts);if (rc)
@@ -1042,6 +1046,7 @@ static void selinux_write_opts(struct seq_file *m,continue ;default :BUG (); +continue ; };/* we need a comma before each option */ seq_putc (m,',' );
@@ -1500,6 +1505,7 @@ static int task_has_capability(struct task_struct *tsk,printk (KERN_ERR "SELinux: out of range capability %d\n" , cap);BUG (); +return -EPERM ; } rc =avc_has_perm_noaudit (sid, sid, sclass, av,0 , &avd);
security/selinux/netnode.c +3 -0
@@ -140,6 +140,7 @@ static struct sel_netnode *sel_netnode_find(const void *addr, u16 family)break ;default :BUG (); +return NULL ; }list_for_each_entry_rcu (node, &sel_netnode_hash[idx].list, list)
@@ -180,6 +181,7 @@ static void sel_netnode_insert(struct sel_netnode *node)break ;default :BUG (); +return ; }INIT_RCU_HEAD (&node->rcu);
@@ -240,6 +242,7 @@ static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)break ;default :BUG (); + ret = -EPROTONOSUPPORT ; }if (ret !=0 ) goto out;
security/selinux/ss/ebitmap.h +12 -3
@@ -85,7 +85,10 @@ static inline int ebitmap_node_get_bit(struct ebitmap_node *n,unsigned int index =EBITMAP_NODE_INDEX (n, bit);unsigned int ofs =EBITMAP_NODE_OFFSET (n, bit); -BUG_ON (index >=EBITMAP_UNIT_NUMS ); +if (unlikely ((index >=EBITMAP_UNIT_NUMS ))) { +panic ("index >= EBITMAP_UNIT_NUMS" ); +return 0 ; + }if ((n->maps[index] & (EBITMAP_BIT << ofs)))return 1 ;return 0 ;
@@ -97,7 +100,10 @@ static inline void ebitmap_node_set_bit(struct ebitmap_node *n,unsigned int index =EBITMAP_NODE_INDEX (n, bit);unsigned int ofs =EBITMAP_NODE_OFFSET (n, bit); -BUG_ON (index >=EBITMAP_UNIT_NUMS ); +if (unlikely ((index >=EBITMAP_UNIT_NUMS ))) { +panic ("index >= EBITMAP_UNIT_NUMS" ); +return ; + } n->maps[index] |= (EBITMAP_BIT << ofs); }
@@ -107,7 +113,10 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n,unsigned int index =EBITMAP_NODE_INDEX (n, bit);unsigned int ofs =EBITMAP_NODE_OFFSET (n, bit); -BUG_ON (index >=EBITMAP_UNIT_NUMS ); +if (unlikely ((index >=EBITMAP_UNIT_NUMS ))) { +panic ("index >= EBITMAP_UNIT_NUMS" ); +return ; + } n->maps[index] &= ~(EBITMAP_BIT << ofs); }
security/selinux/ss/services.c +39 -15
139 lines not on this page · raw message
security/selinux/xfrm.c +12 -3
@@ -202,7 +202,10 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,char *ctx_str =NULL ;u32 str_len; -BUG_ON (uctx && sid); +if (unlikely (ctx && sid)) { +BUG (); +return -EINVAL ; + }if (!uctx) goto not_from_user;
@@ -288,7 +291,10 @@ int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, {int err; -BUG_ON (!uctx); +if (unlikely (!uctx)) { +BUG (); +return -EINVAL ; + } err =selinux_xfrm_sec_ctx_alloc (ctxp, uctx,0 );if (err ==0 )
@@ -356,7 +362,10 @@ int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uct {int err; -BUG_ON (!x); +if (unlikely (!x)) { +BUG (); +return -EINVAL ; + } err =selinux_xfrm_sec_ctx_alloc (&x->security, uctx, secid);if (err ==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 2/3 SELinux: call capabilities code directory
For cleanliness and efficiency remove all calls to secondary-> and instead call capabilities code directly. capabilities are the only module that selinux stacks with and so the code should not indicate that other stacking might be possible.
---
security/selinux/hooks.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-)
security/selinux/hooks.c +13 -17
@@ -1863,7 +1863,7 @@ static int selinux_ptrace_may_access(struct task_struct *child, {int rc; - rc = secondary_ops->ptrace_may_access (child, mode); + rc =cap_ptrace_may_access (child, mode);if (rc)return rc;
@@ -1880,7 +1880,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) {int rc; - rc = secondary_ops->ptrace_traceme (parent); + rc =cap_ptrace_traceme (parent);if (rc)return rc;
@@ -1896,7 +1896,7 @@ static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,if (error)return error; -return secondary_ops->capget (target, effective, inheritable, permitted); +return cap_capget (target, effective, inheritable, permitted); } static int selinux_capset(struct cred *new, const struct cred *old,
@@ -1906,7 +1906,7 @@ static int selinux_capset(struct cred *new, const struct cred *old, {int error; - error = secondary_ops->capset (new, old, + error =cap_capset (new, old, effective, inheritable, permitted);if (error)return error;
@@ -1929,7 +1929,7 @@ static int selinux_capable(struct task_struct *tsk, const struct cred *cred, {int rc; - rc = secondary_ops->capable (tsk, cred, cap, audit); + rc =cap_capable (tsk, cred, cap, audit);if (rc)return rc;
@@ -2055,7 +2055,7 @@ static int selinux_syslog(int type) {int rc; - rc = secondary_ops->syslog (type); + rc =cap_syslog (type);if (rc)return rc;
@@ -2086,10 +2086,6 @@ static int selinux_syslog(int type)* mapping. 0 means there is enough memory for the allocation to * succeed and -ENOMEM implies there is not. * -* Note that secondary_ops->capable and task_has_perm_noaudit return 0 -* if the capability is granted, but __vm_enough_memory requires 1 if -* the capability is granted. -* * Do not audit the selinux permission check, as this is applied to all * processes that allocate mappings. */
@@ -2116,7 +2112,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)struct inode *inode = bprm->file->f_path.dentry->d_inode;int rc; - rc = secondary_ops->bprm_set_creds (bprm); + rc =cap_bprm_set_creds (bprm);if (rc)return rc;
@@ -2233,7 +2229,7 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) PROCESS__NOATSECURE, NULL); } -return (atsecure || secondary_ops->bprm_secureexec (bprm)); +return (atsecure ||cap_bprm_secureexec (bprm)); }extern struct vfsmount *selinuxfs_mount;
@@ -3334,7 +3330,7 @@ static int selinux_task_setnice(struct task_struct *p, int nice) {int rc; - rc = secondary_ops->task_setnice (p, nice); + rc =cap_task_setnice (p, nice);if (rc)return rc;
@@ -3345,7 +3341,7 @@ static int selinux_task_setioprio(struct task_struct *p, int ioprio) {int rc; - rc = secondary_ops->task_setioprio (p, ioprio); + rc =cap_task_setioprio (p, ioprio);if (rc)return rc;
@@ -3375,7 +3371,7 @@ static int selinux_task_setscheduler(struct task_struct *p, int policy, struct s {int rc; - rc = secondary_ops->task_setscheduler (p, policy, lp); + rc =cap_task_setscheduler (p, policy, lp);if (rc)return rc;
@@ -4633,7 +4629,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) {int err; - err = secondary_ops->netlink_send (sk, skb); + err =cap_netlink_send (sk, skb);if (err)return err;
@@ -4648,7 +4644,7 @@ static int selinux_netlink_recv(struct sk_buff *skb, int capability)int err;struct avc_audit_data ad; - err = secondary_ops->netlink_recv (skb, capability); + err =cap_netlink_recv (skb, capability);if (err)return err;
--
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 -v2 2/3] SELinux: call capabilities code directory
Quoted 6 lines · Eric Paris
For cleanliness and efficiency remove all calls to secondary-> and instead call capabilities code directly. capabilities are the only module that selinux stacks with and so the code should not indicate that other stacking might be possible.
Signed-off-by Eric Paris <[email protected]>
Quoted 143 lines
---
security/selinux/hooks.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-)security/selinux/hooks.c +13
-18@@ -1863,7 +1863,7 @@ static int selinux_ptrace_may_access(struct task_struct *child, {int rc; - rc = secondary_ops->ptrace_may_access (child, mode); + rc =cap_ptrace_may_access (child, mode);if (rc)return rc;@@ -1880,7 +1880,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) {int rc; - rc = secondary_ops->ptrace_traceme (parent); + rc =cap_ptrace_traceme (parent);if (rc)return rc;@@ -1896,7 +1896,7 @@ static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,if (error)return error; -return secondary_ops->capget (target, effective, inheritable, permitted); +return cap_capget (target, effective, inheritable, permitted); } static int selinux_capset(struct cred *new, const struct cred *old,@@ -1906,7 +1906,7 @@ static int selinux_capset(struct cred *new, const struct cred *old, {int error; - error = secondary_ops->capset (new, old, + error =cap_capset (new, old, effective, inheritable, permitted);if (error)return error;@@ -1929,7 +1929,7 @@ static int selinux_capable(struct task_struct *tsk, const struct cred *cred, {int rc; - rc = secondary_ops->capable (tsk, cred, cap, audit); + rc =cap_capable (tsk, cred, cap, audit);if (rc)return rc;@@ -2055,7 +2055,7 @@ static int selinux_syslog(int type) {int rc; - rc = secondary_ops->syslog (type); + rc =cap_syslog (type);if (rc)return rc;@@ -2086,10 +2086,6 @@ static int selinux_syslog(int type)* mapping. 0 means there is enough memory for the allocation to * succeed and -ENOMEM implies there is not. * -* Note that secondary_ops->capable and task_has_perm_noaudit return 0 -* if the capability is granted, but __vm_enough_memory requires 1 if -* the capability is granted. -* * Do not audit the selinux permission check, as this is applied to all * processes that allocate mappings. */ @@ -2116,7 +2112,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)struct inode *inode = bprm->file->f_path.dentry->d_inode;int rc; - rc = secondary_ops->bprm_set_creds (bprm); + rc =cap_bprm_set_creds (bprm);if (rc)return rc;@@ -2233,7 +2229,7 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) PROCESS__NOATSECURE, NULL); } -return (atsecure || secondary_ops->bprm_secureexec (bprm)); +return (atsecure ||cap_bprm_secureexec (bprm)); }extern struct vfsmount *selinuxfs_mount;@@ -3334,7 +3330,7 @@ static int selinux_task_setnice(struct task_struct *p, int nice) {int rc; - rc = secondary_ops->task_setnice (p, nice); + rc =cap_task_setnice (p, nice);if (rc)return rc;@@ -3345,7 +3341,7 @@ static int selinux_task_setioprio(struct task_struct *p, int ioprio) {int rc; - rc = secondary_ops->task_setioprio (p, ioprio); + rc =cap_task_setioprio (p, ioprio);if (rc)return rc;@@ -3375,7 +3371,7 @@ static int selinux_task_setscheduler(struct task_struct *p, int policy, struct s {int rc; - rc = secondary_ops->task_setscheduler (p, policy, lp); + rc =cap_task_setscheduler (p, policy, lp);if (rc)return rc;@@ -4633,7 +4629,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) {int err; - err = secondary_ops->netlink_send (sk, skb); + err =cap_netlink_send (sk, skb);if (err)return err;@@ -4648,7 +4644,7 @@ static int selinux_netlink_recv(struct sk_buff *skb, int capability)int err;struct avc_audit_data ad; - err = secondary_ops->netlink_recv (skb, capability); + err =cap_netlink_recv (skb, capability);if (err)return err; --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.
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.
Re: [PATCH -v2 2/3] SELinux: call capabilities code directory
Stephen (Neil, Tony),
I keep following this, hoping it's going to be able to 'step up' for things, but it just
seems to be always 'not ready for primetime'. Any idea when it'll be ready to be
shown to us? r/HAL
Quoted 173 lines · Eric Paris
Quoted 8 lines
For cleanliness and efficiency remove all calls to secondary-> and instead
call capabilities code directly. capabilities are the only module that selinux stacks with and so the code should not indicate that other stacking
might be possible.Signed-off-by Eric Paris <[email protected]>Acked-by Stephen Smalley <[email protected]>Quoted 153 lines
---
security/selinux/hooks.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-)security/selinux/hooks.c +3
-3@@ -1863,7 +1863,7 @@ static int selinux_ptrace_may_access(structtask_struct *child, { int rc; - rc = secondary_ops->ptrace_may_access (child, mode); + rc =cap_ptrace_may_access (child, mode);if (rc)return rc;@@ -1880,7 +1880,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) {int rc; - rc = secondary_ops->ptrace_traceme (parent); + rc =cap_ptrace_traceme (parent);if (rc)return rc;@@ -1896,7 +1896,7 @@ static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, if (error)return error; -return secondary_ops->capget (target, effective, inheritable, permitted); +return cap_capget (target, effective, inheritable, permitted); }static int selinux_capset(struct cred *new, const struct cred *old,
security/selinux/hooks.c +1
-1@@ -1906,7 +1906,7 @@ static int selinux_capset(struct cred *new, conststruct cred *old, { int error; - error = secondary_ops->capset (new, old, + error =cap_capset (new, old, effective, inheritable, permitted);if (error)security/selinux/hooks.c +4
-8return error;@@ -1929,7 +1929,7 @@ static int selinux_capable(struct task_struct *tsk, const struct cred *cred, {int rc; - rc = secondary_ops->capable (tsk, cred, cap, audit); + rc =cap_capable (tsk, cred, cap, audit);if (rc)return rc;@@ -2055,7 +2055,7 @@ static int selinux_syslog(int type) {int rc; - rc = secondary_ops->syslog (type); + rc =cap_syslog (type);if (rc)return rc;@@ -2086,10 +2086,6 @@ static int selinux_syslog(int type)* mapping. 0 means there is enough memory for the allocation to * succeed and -ENOMEM implies there is not. * -* Note that secondary_ops->capable and task_has_perm_noaudit return 0 -* if the capability is granted, but __vm_enough_memory requires 1 if -* the capability is granted. -* * Do not audit the selinux permission check, as this is applied to all * processes that allocate mappings. */ @@ -2116,7 +2112,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)struct inode *inode = bprm->file->f_path.dentry->d_inode;int rc; - rc = secondary_ops->bprm_set_creds (bprm); + rc =cap_bprm_set_creds (bprm);if (rc)return rc;@@ -2233,7 +2229,7 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) PROCESS__NOATSECURE, NULL); } -return (atsecure || secondary_ops->bprm_secureexec (bprm)); +return (atsecure ||cap_bprm_secureexec (bprm)); }extern struct vfsmount
*selinuxfs_mount;security/selinux/hooks.c +2
-2@@ -3334,7 +3330,7 @@ static int selinux_task_setnice(struct task_struct *p, int nice) {int rc; - rc = secondary_ops->task_setnice (p, nice); + rc =cap_task_setnice (p, nice);if (rc)return rc;@@ -3345,7 +3341,7 @@ static int selinux_task_setioprio(struct task_struct *p, int ioprio) {int rc; - rc = secondary_ops->task_setioprio (p, ioprio); + rc =cap_task_setioprio (p, ioprio);if (rc)return rc;@@ -3375,7 +3371,7 @@ static int selinux_task_setscheduler(struct
task_struct*p, int policy, struct s
{security/selinux/hooks.c +3
-4int rc; - rc = secondary_ops->task_setscheduler (p, policy, lp); + rc =cap_task_setscheduler (p, policy, lp);if (rc)return rc;@@ -4633,7 +4629,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) {int err; - err = secondary_ops->netlink_send (sk, skb); + err =cap_netlink_send (sk, skb);if (err)return err;@@ -4648,7 +4644,7 @@ static int selinux_netlink_recv(struct sk_buff *skb, int capability)int err;struct avc_audit_data ad; - err = secondary_ops->netlink_recv (skb, capability); + err =cap_netlink_recv (skb, capability);if (err)return err; --Quoted 4 lines
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.--
Stephen Smalley
National Security Agency
Quoted 7 lines
--
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.
--
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.
James Morris
AppliedRe: [PATCH -v2 2/3] SELinux: call capabilities code directory
In reply to Eric ParisQuoted 6 lines · Eric Paris
For cleanliness and efficiency remove all calls to secondary-> and instead call capabilities code directly. capabilities are the only module that selinux stacks with and so the code should not indicate that other stacking might be possible.
Signed-off-by Eric Paris <[email protected]>
Applied.
Quoted 138 lines
---
security/selinux/hooks.c | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-)security/selinux/hooks.c +13
-17@@ -1863,7 +1863,7 @@ static int selinux_ptrace_may_access(struct task_struct *child, {int rc; - rc = secondary_ops->ptrace_may_access (child, mode); + rc =cap_ptrace_may_access (child, mode);if (rc)return rc;@@ -1880,7 +1880,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) {int rc; - rc = secondary_ops->ptrace_traceme (parent); + rc =cap_ptrace_traceme (parent);if (rc)return rc;@@ -1896,7 +1896,7 @@ static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,if (error)return error; -return secondary_ops->capget (target, effective, inheritable, permitted); +return cap_capget (target, effective, inheritable, permitted); } static int selinux_capset(struct cred *new, const struct cred *old,@@ -1906,7 +1906,7 @@ static int selinux_capset(struct cred *new, const struct cred *old, {int error; - error = secondary_ops->capset (new, old, + error =cap_capset (new, old, effective, inheritable, permitted);if (error)return error;@@ -1929,7 +1929,7 @@ static int selinux_capable(struct task_struct *tsk, const struct cred *cred, {int rc; - rc = secondary_ops->capable (tsk, cred, cap, audit); + rc =cap_capable (tsk, cred, cap, audit);if (rc)return rc;@@ -2055,7 +2055,7 @@ static int selinux_syslog(int type) {int rc; - rc = secondary_ops->syslog (type); + rc =cap_syslog (type);if (rc)return rc;@@ -2086,10 +2086,6 @@ static int selinux_syslog(int type)* mapping. 0 means there is enough memory for the allocation to * succeed and -ENOMEM implies there is not. * -* Note that secondary_ops->capable and task_has_perm_noaudit return 0 -* if the capability is granted, but __vm_enough_memory requires 1 if -* the capability is granted. -* * Do not audit the selinux permission check, as this is applied to all * processes that allocate mappings. */ @@ -2116,7 +2112,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)struct inode *inode = bprm->file->f_path.dentry->d_inode;int rc; - rc = secondary_ops->bprm_set_creds (bprm); + rc =cap_bprm_set_creds (bprm);if (rc)return rc;@@ -2233,7 +2229,7 @@ static int selinux_bprm_secureexec(struct linux_binprm *bprm) PROCESS__NOATSECURE, NULL); } -return (atsecure || secondary_ops->bprm_secureexec (bprm)); +return (atsecure ||cap_bprm_secureexec (bprm)); }extern struct vfsmount *selinuxfs_mount;@@ -3334,7 +3330,7 @@ static int selinux_task_setnice(struct task_struct *p, int nice) {int rc; - rc = secondary_ops->task_setnice (p, nice); + rc =cap_task_setnice (p, nice);if (rc)return rc;@@ -3345,7 +3341,7 @@ static int selinux_task_setioprio(struct task_struct *p, int ioprio) {int rc; - rc = secondary_ops->task_setioprio (p, ioprio); + rc =cap_task_setioprio (p, ioprio);if (rc)return rc;@@ -3375,7 +3371,7 @@ static int selinux_task_setscheduler(struct task_struct *p, int policy, struct s {int rc; - rc = secondary_ops->task_setscheduler (p, policy, lp); + rc =cap_task_setscheduler (p, policy, lp);if (rc)return rc;@@ -4633,7 +4629,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) {int err; - err = secondary_ops->netlink_send (sk, skb); + err =cap_netlink_send (sk, skb);if (err)return err;@@ -4648,7 +4644,7 @@ static int selinux_netlink_recv(struct sk_buff *skb, int capability)int err;struct avc_audit_data ad; - err = secondary_ops->netlink_recv (skb, capability); + err =cap_netlink_recv (skb, capability);if (err)return err;
Signature · 7 lines
James Morris <[email protected]> -- 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/3 SELinux: better printk when file with invalid label found
In reply to Eric ParisCurrently when an inode is read into the kernel with an invalid label string (can often happen with removable media) we output a string like:
SELinux: inode_doinit_with_dentry: context_to_sid([SOME INVALID LABEL]) returned -22 dor dev=[blah] ino=[blah]
Which is all but incomprehensible to all but a couple of us. Instead, on EINVAL only, I plan to output a much more user friendly string and I plan to ratelimit the printk since many of these could be generated very rapidly.
---
security/selinux/hooks.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
security/selinux/hooks.c +13 -4
@@ -1335,10 +1335,19 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent sbsec->def_sid, GFP_NOFS);if (rc) { -printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " -"returned %d for dev=%s ino=%ld\n" , - __func__, context, -rc, - inode->i_sb->s_id, inode->i_ino); +char *dev = inode->i_sb->s_id; +unsigned long ino = inode->i_ino; + +if (rc == -EINVAL ) { +if (printk_ratelimit ()) +printk (KERN_NOTICE "SELinux: inode=%lu on dev=%s was found to have an invalid " +"context=%s. This indicates you may need to relabel the inode or the " +"filesystem in question.\n" , ino, dev, context); + }else { +printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " +"returned %d for dev=%s ino=%ld\n" , + __func__, context, -rc, dev, ino); + }kfree (context);/* Leave with the unlabeled SID */ rc =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.
Re: [PATCH -v2 3/3] SELinux: better printk when file with invalid label found
Quoted 11 lines · Eric Paris
Currently when an inode is read into the kernel with an invalid label string (can often happen with removable media) we output a string like:
SELinux:
inode_doinit_with_dentry:context_to_sid([SOME INVALID LABEL])returned -22 dor dev=[blah] ino=[blah]Which is all but incomprehensible to all but a couple of us. Instead, on EINVAL only, I plan to output a much more user friendly string and I plan to ratelimit the printk since many of these could be generated very rapidly.
Signed-off-by Eric Paris <[email protected]>
Quoted 39 lines
---
security/selinux/hooks.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)security/selinux/hooks.c +13
-5@@ -1335,10 +1335,19 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent sbsec->def_sid, GFP_NOFS);if (rc) { -printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " -"returned %d for dev=%s ino=%ld\n" , - __func__, context, -rc, - inode->i_sb->s_id, inode->i_ino); +char *dev = inode->i_sb->s_id; +unsigned long ino = inode->i_ino; + +if (rc == -EINVAL ) { +if (printk_ratelimit ()) +printk (KERN_NOTICE "SELinux: inode=%lu on dev=%s was found to have an invalid " +"context=%s. This indicates you may need to relabel the inode or the " +"filesystem in question.\n" , ino, dev, context); + }else { +printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " +"returned %d for dev=%s ino=%ld\n" , + __func__, context, -rc, dev, ino); + }kfree (context);/* Leave with the unlabeled SID */ rc =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.
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.
James Morris
AppliedRe: [PATCH -v2 3/3] SELinux: better printk when file with invalid label found
In reply to Eric ParisQuoted 11 lines · Eric Paris
Currently when an inode is read into the kernel with an invalid label string (can often happen with removable media) we output a string like:
SELinux:
inode_doinit_with_dentry:context_to_sid([SOME INVALID LABEL])returned -22 dor dev=[blah] ino=[blah]Which is all but incomprehensible to all but a couple of us. Instead, on EINVAL only, I plan to output a much more user friendly string and I plan to ratelimit the printk since many of these could be generated very rapidly.
Signed-off-by Eric Paris <[email protected]>
Applied.
Quoted 34 lines
---
security/selinux/hooks.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)security/selinux/hooks.c +13
-4@@ -1335,10 +1335,19 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent sbsec->def_sid, GFP_NOFS);if (rc) { -printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " -"returned %d for dev=%s ino=%ld\n" , - __func__, context, -rc, - inode->i_sb->s_id, inode->i_ino); +char *dev = inode->i_sb->s_id; +unsigned long ino = inode->i_ino; + +if (rc == -EINVAL ) { +if (printk_ratelimit ()) +printk (KERN_NOTICE "SELinux: inode=%lu on dev=%s was found to have an invalid " +"context=%s. This indicates you may need to relabel the inode or the " +"filesystem in question.\n" , ino, dev, context); + }else { +printk (KERN_WARNING "SELinux: %s: context_to_sid(%s) " +"returned %d for dev=%s ino=%ld\n" , + __func__, context, -rc, dev, ino); + }kfree (context);/* Leave with the unlabeled SID */ rc =0 ;
Signature · 7 lines
James Morris <[email protected]> -- 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 114 lines · Eric Paris
If
CONFIG_BUGis not set places in the code where BUG is called will not end execution. Look for places where this might result is system problems and keep the system running.Signed-off-by Eric Paris <[email protected]>---
kernel/capability.c | 1 + security/selinux/avc.c | 9 +++++-- security/selinux/hooks.c | 8 +++++- security/selinux/netnode.c | 3 ++ security/selinux/ss/ebitmap.h | 15 +++++++++-- security/selinux/ss/services.c | 54 +++++++++++++++++++++++++++++----------- security/selinux/xfrm.c | 15 +++++++++-- 7 files changed, 81 insertions(+), 24 deletions(-)kernel/capability.c +1
-0@@ -304,6 +304,7 @@ int capable(int cap)if (unlikely (!cap_valid (cap))) {printk (KERN_CRIT "capable() called with invalid cap=%u\n" , cap);BUG (); +return 0 ; }if (security_capable (cap) ==0 ) {security/selinux/avc.c +7
-2@@ -220,8 +220,13 @@ static void avc_dump_query(struct audit_buffer *ab, u32 ssid, u32 tsid, u16 tclakfree (scontext); } -BUG_ON (tclass >=ARRAY_SIZE (class_to_string) || !class_to_string[tclass]); -audit_log_format (ab," tclass=%s" , class_to_string[tclass]); +if (unlikely (tclass >=ARRAY_SIZE (class_to_string) || !class_to_string[tclass])) { +printk (KERN_ERR "%s: with tclass=%d\n" , __func__, tclass); +BUG (); +audit_log_format (ab," tclass=%d" , tclass); + }else { +audit_log_format (ab," tclass=%s" , class_to_string[tclass]); + } }/** security/selinux/hooks.c +7
-1@@ -995,7 +995,11 @@ static int superblock_doinit(struct super_block *sb, void *data)if (!data) goto out; -BUG_ON (sb->s_type->fs_flags &FS_BINARY_MOUNTDATA ); +if (unlikely (sb->s_type->fs_flags &FS_BINARY_MOUNTDATA )) { +BUG (); + rc = -EINVAL ; + goto out_err; + } rc =selinux_parse_opts_str (options, &opts);if (rc)@@ -1042,6 +1046,7 @@ static void selinux_write_opts(struct seq_file *m,continue ;default :BUG (); +continue ; };/* we need a comma before each option */ seq_putc (m,',' );@@ -1500,6 +1505,7 @@ static int task_has_capability(struct task_struct *tsk,printk (KERN_ERR "SELinux: out of range capability %d\n" , cap);BUG (); +return -EPERM ; } rc =avc_has_perm_noaudit (sid, sid, sclass, av,0 , &avd);security/selinux/netnode.c +3
-0@@ -140,6 +140,7 @@ static struct sel_netnode *sel_netnode_find(const void *addr, u16 family)break ;default :BUG (); +return NULL ; }list_for_each_entry_rcu (node, &sel_netnode_hash[idx].list, list)@@ -180,6 +181,7 @@ static void sel_netnode_insert(struct sel_netnode *node)break ;default :BUG (); +return ; }INIT_RCU_HEAD (&node->rcu);@@ -240,6 +242,7 @@ static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)break ;default :BUG (); + ret = -EPROTONOSUPPORT ; }if (ret !=0 ) goto out;security/selinux/ss/ebitmap.h +0
-0
security/selinux/ss/ebitmap.h static inline int ebitmap_node_get_bit(struct ebitmap_node *n, · line 90
Quoted 7 lines
security/selinux/ss/ebitmap.h +3
-1@@ -85,7 +85,10 @@ static inline int ebitmap_node_get_bit(struct ebitmap_node *n,unsigned int index =EBITMAP_NODE_INDEX (n, bit);unsigned int ofs =EBITMAP_NODE_OFFSET (n, bit); -BUG_ON (index >=EBITMAP_UNIT_NUMS ); +if (unlikely ((index >=EBITMAP_UNIT_NUMS ))) { +panic ("index >= EBITMAP_UNIT_NUMS" ); +return 0 ;
Unlike BUG(), you don't need anything after panic(), right? It is a no-return function under all configurations, right?
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.