aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2011-04-26 04:22:15 -0400
committerJiri Kosina <jkosina@suse.cz>2011-04-26 04:22:59 -0400
commit07f9479a40cc778bc1462ada11f95b01360ae4ff (patch)
tree0676cf38df3844004bb3ebfd99dfa67a4a8998f5 /security/selinux
parent9d5e6bdb3013acfb311ab407eeca0b6a6a3dedbf (diff)
parentcd2e49e90f1cae7726c9a2c54488d881d7f1cd1c (diff)
Merge branch 'master' into for-next
Fast-forwarded to current state of Linus' tree as there are patches to be applied for files that didn't exist on the old branch.
Diffstat (limited to 'security/selinux')
-rw-r--r--security/selinux/avc.c36
-rw-r--r--security/selinux/hooks.c39
-rw-r--r--security/selinux/include/avc.h18
-rw-r--r--security/selinux/netlabel.c2
-rw-r--r--security/selinux/ss/services.c6
5 files changed, 69 insertions, 32 deletions
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 9da6420e2056..1d027e29ce8d 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -471,6 +471,7 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
471 * @avd: access vector decisions 471 * @avd: access vector decisions
472 * @result: result from avc_has_perm_noaudit 472 * @result: result from avc_has_perm_noaudit
473 * @a: auxiliary audit data 473 * @a: auxiliary audit data
474 * @flags: VFS walk flags
474 * 475 *
475 * Audit the granting or denial of permissions in accordance 476 * Audit the granting or denial of permissions in accordance
476 * with the policy. This function is typically called by 477 * with the policy. This function is typically called by
@@ -481,9 +482,10 @@ static void avc_audit_post_callback(struct audit_buffer *ab, void *a)
481 * be performed under a lock, to allow the lock to be released 482 * be performed under a lock, to allow the lock to be released
482 * before calling the auditing code. 483 * before calling the auditing code.
483 */ 484 */
484void avc_audit(u32 ssid, u32 tsid, 485int avc_audit(u32 ssid, u32 tsid,
485 u16 tclass, u32 requested, 486 u16 tclass, u32 requested,
486 struct av_decision *avd, int result, struct common_audit_data *a) 487 struct av_decision *avd, int result, struct common_audit_data *a,
488 unsigned flags)
487{ 489{
488 struct common_audit_data stack_data; 490 struct common_audit_data stack_data;
489 u32 denied, audited; 491 u32 denied, audited;
@@ -515,11 +517,24 @@ void avc_audit(u32 ssid, u32 tsid,
515 else 517 else
516 audited = requested & avd->auditallow; 518 audited = requested & avd->auditallow;
517 if (!audited) 519 if (!audited)
518 return; 520 return 0;
521
519 if (!a) { 522 if (!a) {
520 a = &stack_data; 523 a = &stack_data;
521 COMMON_AUDIT_DATA_INIT(a, NONE); 524 COMMON_AUDIT_DATA_INIT(a, NONE);
522 } 525 }
526
527 /*
528 * When in a RCU walk do the audit on the RCU retry. This is because
529 * the collection of the dname in an inode audit message is not RCU
530 * safe. Note this may drop some audits when the situation changes
531 * during retry. However this is logically just as if the operation
532 * happened a little later.
533 */
534 if ((a->type == LSM_AUDIT_DATA_FS) &&
535 (flags & IPERM_FLAG_RCU))
536 return -ECHILD;
537
523 a->selinux_audit_data.tclass = tclass; 538 a->selinux_audit_data.tclass = tclass;
524 a->selinux_audit_data.requested = requested; 539 a->selinux_audit_data.requested = requested;
525 a->selinux_audit_data.ssid = ssid; 540 a->selinux_audit_data.ssid = ssid;
@@ -529,6 +544,7 @@ void avc_audit(u32 ssid, u32 tsid,
529 a->lsm_pre_audit = avc_audit_pre_callback; 544 a->lsm_pre_audit = avc_audit_pre_callback;
530 a->lsm_post_audit = avc_audit_post_callback; 545 a->lsm_post_audit = avc_audit_post_callback;
531 common_lsm_audit(a); 546 common_lsm_audit(a);
547 return 0;
532} 548}
533 549
534/** 550/**
@@ -793,6 +809,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
793 * @tclass: target security class 809 * @tclass: target security class
794 * @requested: requested permissions, interpreted based on @tclass 810 * @requested: requested permissions, interpreted based on @tclass
795 * @auditdata: auxiliary audit data 811 * @auditdata: auxiliary audit data
812 * @flags: VFS walk flags
796 * 813 *
797 * Check the AVC to determine whether the @requested permissions are granted 814 * Check the AVC to determine whether the @requested permissions are granted
798 * for the SID pair (@ssid, @tsid), interpreting the permissions 815 * for the SID pair (@ssid, @tsid), interpreting the permissions
@@ -802,14 +819,19 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
802 * permissions are granted, -%EACCES if any permissions are denied, or 819 * permissions are granted, -%EACCES if any permissions are denied, or
803 * another -errno upon other errors. 820 * another -errno upon other errors.
804 */ 821 */
805int avc_has_perm(u32 ssid, u32 tsid, u16 tclass, 822int avc_has_perm_flags(u32 ssid, u32 tsid, u16 tclass,
806 u32 requested, struct common_audit_data *auditdata) 823 u32 requested, struct common_audit_data *auditdata,
824 unsigned flags)
807{ 825{
808 struct av_decision avd; 826 struct av_decision avd;
809 int rc; 827 int rc, rc2;
810 828
811 rc = avc_has_perm_noaudit(ssid, tsid, tclass, requested, 0, &avd); 829 rc = avc_has_perm_noaudit(ssid, tsid, tclass, requested, 0, &avd);
812 avc_audit(ssid, tsid, tclass, requested, &avd, rc, auditdata); 830
831 rc2 = avc_audit(ssid, tsid, tclass, requested, &avd, rc, auditdata,
832 flags);
833 if (rc2)
834 return rc2;
813 return rc; 835 return rc;
814} 836}
815 837
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6475e1f0223e..f7cf0ea6faea 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -79,6 +79,7 @@
79#include <linux/mutex.h> 79#include <linux/mutex.h>
80#include <linux/posix-timers.h> 80#include <linux/posix-timers.h>
81#include <linux/syslog.h> 81#include <linux/syslog.h>
82#include <linux/user_namespace.h>
82 83
83#include "avc.h" 84#include "avc.h"
84#include "objsec.h" 85#include "objsec.h"
@@ -1445,8 +1446,11 @@ static int task_has_capability(struct task_struct *tsk,
1445 } 1446 }
1446 1447
1447 rc = avc_has_perm_noaudit(sid, sid, sclass, av, 0, &avd); 1448 rc = avc_has_perm_noaudit(sid, sid, sclass, av, 0, &avd);
1448 if (audit == SECURITY_CAP_AUDIT) 1449 if (audit == SECURITY_CAP_AUDIT) {
1449 avc_audit(sid, sid, sclass, av, &avd, rc, &ad); 1450 int rc2 = avc_audit(sid, sid, sclass, av, &avd, rc, &ad, 0);
1451 if (rc2)
1452 return rc2;
1453 }
1450 return rc; 1454 return rc;
1451} 1455}
1452 1456
@@ -1466,7 +1470,8 @@ static int task_has_system(struct task_struct *tsk,
1466static int inode_has_perm(const struct cred *cred, 1470static int inode_has_perm(const struct cred *cred,
1467 struct inode *inode, 1471 struct inode *inode,
1468 u32 perms, 1472 u32 perms,
1469 struct common_audit_data *adp) 1473 struct common_audit_data *adp,
1474 unsigned flags)
1470{ 1475{
1471 struct inode_security_struct *isec; 1476 struct inode_security_struct *isec;
1472 struct common_audit_data ad; 1477 struct common_audit_data ad;
@@ -1486,7 +1491,7 @@ static int inode_has_perm(const struct cred *cred,
1486 ad.u.fs.inode = inode; 1491 ad.u.fs.inode = inode;
1487 } 1492 }
1488 1493
1489 return avc_has_perm(sid, isec->sid, isec->sclass, perms, adp); 1494 return avc_has_perm_flags(sid, isec->sid, isec->sclass, perms, adp, flags);
1490} 1495}
1491 1496
1492/* Same as inode_has_perm, but pass explicit audit data containing 1497/* Same as inode_has_perm, but pass explicit audit data containing
@@ -1503,7 +1508,7 @@ static inline int dentry_has_perm(const struct cred *cred,
1503 COMMON_AUDIT_DATA_INIT(&ad, FS); 1508 COMMON_AUDIT_DATA_INIT(&ad, FS);
1504 ad.u.fs.path.mnt = mnt; 1509 ad.u.fs.path.mnt = mnt;
1505 ad.u.fs.path.dentry = dentry; 1510 ad.u.fs.path.dentry = dentry;
1506 return inode_has_perm(cred, inode, av, &ad); 1511 return inode_has_perm(cred, inode, av, &ad, 0);
1507} 1512}
1508 1513
1509/* Check whether a task can use an open file descriptor to 1514/* Check whether a task can use an open file descriptor to
@@ -1539,7 +1544,7 @@ static int file_has_perm(const struct cred *cred,
1539 /* av is zero if only checking access to the descriptor. */ 1544 /* av is zero if only checking access to the descriptor. */
1540 rc = 0; 1545 rc = 0;
1541 if (av) 1546 if (av)
1542 rc = inode_has_perm(cred, inode, av, &ad); 1547 rc = inode_has_perm(cred, inode, av, &ad, 0);
1543 1548
1544out: 1549out:
1545 return rc; 1550 return rc;
@@ -1846,11 +1851,11 @@ static int selinux_capset(struct cred *new, const struct cred *old,
1846 */ 1851 */
1847 1852
1848static int selinux_capable(struct task_struct *tsk, const struct cred *cred, 1853static int selinux_capable(struct task_struct *tsk, const struct cred *cred,
1849 int cap, int audit) 1854 struct user_namespace *ns, int cap, int audit)
1850{ 1855{
1851 int rc; 1856 int rc;
1852 1857
1853 rc = cap_capable(tsk, cred, cap, audit); 1858 rc = cap_capable(tsk, cred, ns, cap, audit);
1854 if (rc) 1859 if (rc)
1855 return rc; 1860 return rc;
1856 1861
@@ -1931,7 +1936,8 @@ static int selinux_vm_enough_memory(struct mm_struct *mm, long pages)
1931{ 1936{
1932 int rc, cap_sys_admin = 0; 1937 int rc, cap_sys_admin = 0;
1933 1938
1934 rc = selinux_capable(current, current_cred(), CAP_SYS_ADMIN, 1939 rc = selinux_capable(current, current_cred(),
1940 &init_user_ns, CAP_SYS_ADMIN,
1935 SECURITY_CAP_NOAUDIT); 1941 SECURITY_CAP_NOAUDIT);
1936 if (rc == 0) 1942 if (rc == 0)
1937 cap_sys_admin = 1; 1943 cap_sys_admin = 1;
@@ -2101,7 +2107,7 @@ static inline void flush_unauthorized_files(const struct cred *cred,
2101 file = file_priv->file; 2107 file = file_priv->file;
2102 inode = file->f_path.dentry->d_inode; 2108 inode = file->f_path.dentry->d_inode;
2103 if (inode_has_perm(cred, inode, 2109 if (inode_has_perm(cred, inode,
2104 FILE__READ | FILE__WRITE, NULL)) { 2110 FILE__READ | FILE__WRITE, NULL, 0)) {
2105 drop_tty = 1; 2111 drop_tty = 1;
2106 } 2112 }
2107 } 2113 }
@@ -2633,7 +2639,7 @@ static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *na
2633 return dentry_has_perm(cred, NULL, dentry, FILE__READ); 2639 return dentry_has_perm(cred, NULL, dentry, FILE__READ);
2634} 2640}
2635 2641
2636static int selinux_inode_permission(struct inode *inode, int mask) 2642static int selinux_inode_permission(struct inode *inode, int mask, unsigned flags)
2637{ 2643{
2638 const struct cred *cred = current_cred(); 2644 const struct cred *cred = current_cred();
2639 struct common_audit_data ad; 2645 struct common_audit_data ad;
@@ -2655,7 +2661,7 @@ static int selinux_inode_permission(struct inode *inode, int mask)
2655 2661
2656 perms = file_mask_to_av(inode->i_mode, mask); 2662 perms = file_mask_to_av(inode->i_mode, mask);
2657 2663
2658 return inode_has_perm(cred, inode, perms, &ad); 2664 return inode_has_perm(cred, inode, perms, &ad, flags);
2659} 2665}
2660 2666
2661static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr) 2667static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
@@ -2723,7 +2729,7 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name,
2723 if (!(sbsec->flags & SE_SBLABELSUPP)) 2729 if (!(sbsec->flags & SE_SBLABELSUPP))
2724 return -EOPNOTSUPP; 2730 return -EOPNOTSUPP;
2725 2731
2726 if (!is_owner_or_cap(inode)) 2732 if (!inode_owner_or_capable(inode))
2727 return -EPERM; 2733 return -EPERM;
2728 2734
2729 COMMON_AUDIT_DATA_INIT(&ad, FS); 2735 COMMON_AUDIT_DATA_INIT(&ad, FS);
@@ -2834,7 +2840,8 @@ static int selinux_inode_getsecurity(const struct inode *inode, const char *name
2834 * and lack of permission just means that we fall back to the 2840 * and lack of permission just means that we fall back to the
2835 * in-core context value, not a denial. 2841 * in-core context value, not a denial.
2836 */ 2842 */
2837 error = selinux_capable(current, current_cred(), CAP_MAC_ADMIN, 2843 error = selinux_capable(current, current_cred(),
2844 &init_user_ns, CAP_MAC_ADMIN,
2838 SECURITY_CAP_NOAUDIT); 2845 SECURITY_CAP_NOAUDIT);
2839 if (!error) 2846 if (!error)
2840 error = security_sid_to_context_force(isec->sid, &context, 2847 error = security_sid_to_context_force(isec->sid, &context,
@@ -2968,7 +2975,7 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd,
2968 case KDSKBENT: 2975 case KDSKBENT:
2969 case KDSKBSENT: 2976 case KDSKBSENT:
2970 error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG, 2977 error = task_has_capability(current, cred, CAP_SYS_TTY_CONFIG,
2971 SECURITY_CAP_AUDIT); 2978 SECURITY_CAP_AUDIT);
2972 break; 2979 break;
2973 2980
2974 /* default case assumes that the command will go 2981 /* default case assumes that the command will go
@@ -3202,7 +3209,7 @@ static int selinux_dentry_open(struct file *file, const struct cred *cred)
3202 * new inode label or new policy. 3209 * new inode label or new policy.
3203 * This check is not redundant - do not remove. 3210 * This check is not redundant - do not remove.
3204 */ 3211 */
3205 return inode_has_perm(cred, inode, open_file_to_av(file), NULL); 3212 return inode_has_perm(cred, inode, open_file_to_av(file), NULL, 0);
3206} 3213}
3207 3214
3208/* task security operations */ 3215/* task security operations */
diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h
index 5615081b73ec..e77b2ac2908b 100644
--- a/security/selinux/include/avc.h
+++ b/security/selinux/include/avc.h
@@ -54,11 +54,11 @@ struct avc_cache_stats {
54 54
55void __init avc_init(void); 55void __init avc_init(void);
56 56
57void avc_audit(u32 ssid, u32 tsid, 57int avc_audit(u32 ssid, u32 tsid,
58 u16 tclass, u32 requested, 58 u16 tclass, u32 requested,
59 struct av_decision *avd, 59 struct av_decision *avd,
60 int result, 60 int result,
61 struct common_audit_data *a); 61 struct common_audit_data *a, unsigned flags);
62 62
63#define AVC_STRICT 1 /* Ignore permissive mode. */ 63#define AVC_STRICT 1 /* Ignore permissive mode. */
64int avc_has_perm_noaudit(u32 ssid, u32 tsid, 64int avc_has_perm_noaudit(u32 ssid, u32 tsid,
@@ -66,9 +66,17 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
66 unsigned flags, 66 unsigned flags,
67 struct av_decision *avd); 67 struct av_decision *avd);
68 68
69int avc_has_perm(u32 ssid, u32 tsid, 69int avc_has_perm_flags(u32 ssid, u32 tsid,
70 u16 tclass, u32 requested, 70 u16 tclass, u32 requested,
71 struct common_audit_data *auditdata); 71 struct common_audit_data *auditdata,
72 unsigned);
73
74static inline int avc_has_perm(u32 ssid, u32 tsid,
75 u16 tclass, u32 requested,
76 struct common_audit_data *auditdata)
77{
78 return avc_has_perm_flags(ssid, tsid, tclass, requested, auditdata, 0);
79}
72 80
73u32 avc_policy_seqno(void); 81u32 avc_policy_seqno(void);
74 82
diff --git a/security/selinux/netlabel.c b/security/selinux/netlabel.c
index 1c2fc46544bf..c3bf3ed07b06 100644
--- a/security/selinux/netlabel.c
+++ b/security/selinux/netlabel.c
@@ -151,7 +151,7 @@ void selinux_netlbl_sk_security_free(struct sk_security_struct *sksec)
151 * 151 *
152 * Description: 152 * Description:
153 * Called when the NetLabel state of a sk_security_struct needs to be reset. 153 * Called when the NetLabel state of a sk_security_struct needs to be reset.
154 * The caller is responsibile for all the NetLabel sk_security_struct locking. 154 * The caller is responsible for all the NetLabel sk_security_struct locking.
155 * 155 *
156 */ 156 */
157void selinux_netlbl_sk_security_reset(struct sk_security_struct *sksec) 157void selinux_netlbl_sk_security_reset(struct sk_security_struct *sksec)
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 3e7544d2a07b..6ef4af47dac4 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -213,7 +213,7 @@ static u16 map_class(u16 pol_value)
213 return i; 213 return i;
214 } 214 }
215 215
216 return pol_value; 216 return SECCLASS_NULL;
217} 217}
218 218
219static void map_decision(u16 tclass, struct av_decision *avd, 219static void map_decision(u16 tclass, struct av_decision *avd,
@@ -2806,7 +2806,7 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2806 case AUDIT_SUBJ_CLR: 2806 case AUDIT_SUBJ_CLR:
2807 case AUDIT_OBJ_LEV_LOW: 2807 case AUDIT_OBJ_LEV_LOW:
2808 case AUDIT_OBJ_LEV_HIGH: 2808 case AUDIT_OBJ_LEV_HIGH:
2809 /* we do not allow a range, indicated by the presense of '-' */ 2809 /* we do not allow a range, indicated by the presence of '-' */
2810 if (strchr(rulestr, '-')) 2810 if (strchr(rulestr, '-'))
2811 return -EINVAL; 2811 return -EINVAL;
2812 break; 2812 break;
@@ -3075,7 +3075,7 @@ static void security_netlbl_cache_add(struct netlbl_lsm_secattr *secattr,
3075 * Description: 3075 * Description:
3076 * Convert the given NetLabel security attributes in @secattr into a 3076 * Convert the given NetLabel security attributes in @secattr into a
3077 * SELinux SID. If the @secattr field does not contain a full SELinux 3077 * SELinux SID. If the @secattr field does not contain a full SELinux
3078 * SID/context then use SECINITSID_NETMSG as the foundation. If possibile the 3078 * SID/context then use SECINITSID_NETMSG as the foundation. If possible the
3079 * 'cache' field of @secattr is set and the CACHE flag is set; this is to 3079 * 'cache' field of @secattr is set and the CACHE flag is set; this is to
3080 * allow the @secattr to be used by NetLabel to cache the secattr to SID 3080 * allow the @secattr to be used by NetLabel to cache the secattr to SID
3081 * conversion for future lookups. Returns zero on success, negative values on 3081 * conversion for future lookups. Returns zero on success, negative values on