diff options
Diffstat (limited to 'security')
-rw-r--r-- | security/capability.c | 3 | ||||
-rw-r--r-- | security/commoncap.c | 24 | ||||
-rw-r--r-- | security/root_plug.c | 3 | ||||
-rw-r--r-- | security/security.c | 10 | ||||
-rw-r--r-- | security/selinux/hooks.c | 25 | ||||
-rw-r--r-- | security/smack/smack_lsm.c | 49 |
6 files changed, 80 insertions, 34 deletions
diff --git a/security/capability.c b/security/capability.c index 63d10da515a5..245874819036 100644 --- a/security/capability.c +++ b/security/capability.c | |||
@@ -811,7 +811,8 @@ struct security_operations default_security_ops = { | |||
811 | 811 | ||
812 | void security_fixup_ops(struct security_operations *ops) | 812 | void security_fixup_ops(struct security_operations *ops) |
813 | { | 813 | { |
814 | set_to_cap_if_null(ops, ptrace); | 814 | set_to_cap_if_null(ops, ptrace_may_access); |
815 | set_to_cap_if_null(ops, ptrace_traceme); | ||
815 | set_to_cap_if_null(ops, capget); | 816 | set_to_cap_if_null(ops, capget); |
816 | set_to_cap_if_null(ops, capset_check); | 817 | set_to_cap_if_null(ops, capset_check); |
817 | set_to_cap_if_null(ops, capset_set); | 818 | set_to_cap_if_null(ops, capset_set); |
diff --git a/security/commoncap.c b/security/commoncap.c index 4afbece37a08..e4c4b3fc0c04 100644 --- a/security/commoncap.c +++ b/security/commoncap.c | |||
@@ -63,14 +63,24 @@ int cap_settime(struct timespec *ts, struct timezone *tz) | |||
63 | return 0; | 63 | return 0; |
64 | } | 64 | } |
65 | 65 | ||
66 | int cap_ptrace (struct task_struct *parent, struct task_struct *child, | 66 | int cap_ptrace_may_access(struct task_struct *child, unsigned int mode) |
67 | unsigned int mode) | ||
68 | { | 67 | { |
69 | /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */ | 68 | /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */ |
70 | if (!cap_issubset(child->cap_permitted, parent->cap_permitted) && | 69 | if (cap_issubset(child->cap_permitted, current->cap_permitted)) |
71 | !__capable(parent, CAP_SYS_PTRACE)) | 70 | return 0; |
72 | return -EPERM; | 71 | if (capable(CAP_SYS_PTRACE)) |
73 | return 0; | 72 | return 0; |
73 | return -EPERM; | ||
74 | } | ||
75 | |||
76 | int cap_ptrace_traceme(struct task_struct *parent) | ||
77 | { | ||
78 | /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */ | ||
79 | if (cap_issubset(current->cap_permitted, parent->cap_permitted)) | ||
80 | return 0; | ||
81 | if (has_capability(parent, CAP_SYS_PTRACE)) | ||
82 | return 0; | ||
83 | return -EPERM; | ||
74 | } | 84 | } |
75 | 85 | ||
76 | int cap_capget (struct task_struct *target, kernel_cap_t *effective, | 86 | int cap_capget (struct task_struct *target, kernel_cap_t *effective, |
@@ -534,7 +544,7 @@ int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, | |||
534 | static inline int cap_safe_nice(struct task_struct *p) | 544 | static inline int cap_safe_nice(struct task_struct *p) |
535 | { | 545 | { |
536 | if (!cap_issubset(p->cap_permitted, current->cap_permitted) && | 546 | if (!cap_issubset(p->cap_permitted, current->cap_permitted) && |
537 | !__capable(current, CAP_SYS_NICE)) | 547 | !capable(CAP_SYS_NICE)) |
538 | return -EPERM; | 548 | return -EPERM; |
539 | return 0; | 549 | return 0; |
540 | } | 550 | } |
diff --git a/security/root_plug.c b/security/root_plug.c index be0ebec2580b..c3f68b5b372d 100644 --- a/security/root_plug.c +++ b/security/root_plug.c | |||
@@ -72,7 +72,8 @@ static int rootplug_bprm_check_security (struct linux_binprm *bprm) | |||
72 | 72 | ||
73 | static struct security_operations rootplug_security_ops = { | 73 | static struct security_operations rootplug_security_ops = { |
74 | /* Use the capability functions for some of the hooks */ | 74 | /* Use the capability functions for some of the hooks */ |
75 | .ptrace = cap_ptrace, | 75 | .ptrace_may_access = cap_ptrace_may_access, |
76 | .ptrace_traceme = cap_ptrace_traceme, | ||
76 | .capget = cap_capget, | 77 | .capget = cap_capget, |
77 | .capset_check = cap_capset_check, | 78 | .capset_check = cap_capset_check, |
78 | .capset_set = cap_capset_set, | 79 | .capset_set = cap_capset_set, |
diff --git a/security/security.c b/security/security.c index d953d251fdca..255b08559b2b 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -127,10 +127,14 @@ int register_security(struct security_operations *ops) | |||
127 | 127 | ||
128 | /* Security operations */ | 128 | /* Security operations */ |
129 | 129 | ||
130 | int security_ptrace(struct task_struct *parent, struct task_struct *child, | 130 | int security_ptrace_may_access(struct task_struct *child, unsigned int mode) |
131 | unsigned int mode) | ||
132 | { | 131 | { |
133 | return security_ops->ptrace(parent, child, mode); | 132 | return security_ops->ptrace_may_access(child, mode); |
133 | } | ||
134 | |||
135 | int security_ptrace_traceme(struct task_struct *parent) | ||
136 | { | ||
137 | return security_ops->ptrace_traceme(parent); | ||
134 | } | 138 | } |
135 | 139 | ||
136 | int security_capget(struct task_struct *target, | 140 | int security_capget(struct task_struct *target, |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 3eae30609702..6b5790bba8f9 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -1739,24 +1739,34 @@ static inline u32 file_to_av(struct file *file) | |||
1739 | 1739 | ||
1740 | /* Hook functions begin here. */ | 1740 | /* Hook functions begin here. */ |
1741 | 1741 | ||
1742 | static int selinux_ptrace(struct task_struct *parent, | 1742 | static int selinux_ptrace_may_access(struct task_struct *child, |
1743 | struct task_struct *child, | 1743 | unsigned int mode) |
1744 | unsigned int mode) | ||
1745 | { | 1744 | { |
1746 | int rc; | 1745 | int rc; |
1747 | 1746 | ||
1748 | rc = secondary_ops->ptrace(parent, child, mode); | 1747 | rc = secondary_ops->ptrace_may_access(child, mode); |
1749 | if (rc) | 1748 | if (rc) |
1750 | return rc; | 1749 | return rc; |
1751 | 1750 | ||
1752 | if (mode == PTRACE_MODE_READ) { | 1751 | if (mode == PTRACE_MODE_READ) { |
1753 | struct task_security_struct *tsec = parent->security; | 1752 | struct task_security_struct *tsec = current->security; |
1754 | struct task_security_struct *csec = child->security; | 1753 | struct task_security_struct *csec = child->security; |
1755 | return avc_has_perm(tsec->sid, csec->sid, | 1754 | return avc_has_perm(tsec->sid, csec->sid, |
1756 | SECCLASS_FILE, FILE__READ, NULL); | 1755 | SECCLASS_FILE, FILE__READ, NULL); |
1757 | } | 1756 | } |
1758 | 1757 | ||
1759 | return task_has_perm(parent, child, PROCESS__PTRACE); | 1758 | return task_has_perm(current, child, PROCESS__PTRACE); |
1759 | } | ||
1760 | |||
1761 | static int selinux_ptrace_traceme(struct task_struct *parent) | ||
1762 | { | ||
1763 | int rc; | ||
1764 | |||
1765 | rc = secondary_ops->ptrace_traceme(parent); | ||
1766 | if (rc) | ||
1767 | return rc; | ||
1768 | |||
1769 | return task_has_perm(parent, current, PROCESS__PTRACE); | ||
1760 | } | 1770 | } |
1761 | 1771 | ||
1762 | static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, | 1772 | static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, |
@@ -5353,7 +5363,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) | |||
5353 | static struct security_operations selinux_ops = { | 5363 | static struct security_operations selinux_ops = { |
5354 | .name = "selinux", | 5364 | .name = "selinux", |
5355 | 5365 | ||
5356 | .ptrace = selinux_ptrace, | 5366 | .ptrace_may_access = selinux_ptrace_may_access, |
5367 | .ptrace_traceme = selinux_ptrace_traceme, | ||
5357 | .capget = selinux_capget, | 5368 | .capget = selinux_capget, |
5358 | .capset_check = selinux_capset_check, | 5369 | .capset_check = selinux_capset_check, |
5359 | .capset_set = selinux_capset_set, | 5370 | .capset_set = selinux_capset_set, |
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 1b40e558f983..87d75417ea93 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
@@ -87,27 +87,46 @@ struct inode_smack *new_inode_smack(char *smack) | |||
87 | */ | 87 | */ |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * smack_ptrace - Smack approval on ptrace | 90 | * smack_ptrace_may_access - Smack approval on PTRACE_ATTACH |
91 | * @ptp: parent task pointer | ||
92 | * @ctp: child task pointer | 91 | * @ctp: child task pointer |
93 | * | 92 | * |
94 | * Returns 0 if access is OK, an error code otherwise | 93 | * Returns 0 if access is OK, an error code otherwise |
95 | * | 94 | * |
96 | * Do the capability checks, and require read and write. | 95 | * Do the capability checks, and require read and write. |
97 | */ | 96 | */ |
98 | static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp, | 97 | static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode) |
99 | unsigned int mode) | ||
100 | { | 98 | { |
101 | int rc; | 99 | int rc; |
102 | 100 | ||
103 | rc = cap_ptrace(ptp, ctp, mode); | 101 | rc = cap_ptrace_may_access(ctp, mode); |
104 | if (rc != 0) | 102 | if (rc != 0) |
105 | return rc; | 103 | return rc; |
106 | 104 | ||
107 | rc = smk_access(ptp->security, ctp->security, MAY_READWRITE); | 105 | rc = smk_access(current->security, ctp->security, MAY_READWRITE); |
108 | if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE)) | 106 | if (rc != 0 && capable(CAP_MAC_OVERRIDE)) |
109 | return 0; | 107 | return 0; |
108 | return rc; | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME | ||
113 | * @ptp: parent task pointer | ||
114 | * | ||
115 | * Returns 0 if access is OK, an error code otherwise | ||
116 | * | ||
117 | * Do the capability checks, and require read and write. | ||
118 | */ | ||
119 | static int smack_ptrace_traceme(struct task_struct *ptp) | ||
120 | { | ||
121 | int rc; | ||
122 | |||
123 | rc = cap_ptrace_traceme(ptp); | ||
124 | if (rc != 0) | ||
125 | return rc; | ||
110 | 126 | ||
127 | rc = smk_access(ptp->security, current->security, MAY_READWRITE); | ||
128 | if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE)) | ||
129 | return 0; | ||
111 | return rc; | 130 | return rc; |
112 | } | 131 | } |
113 | 132 | ||
@@ -923,7 +942,7 @@ static int smack_file_send_sigiotask(struct task_struct *tsk, | |||
923 | */ | 942 | */ |
924 | file = container_of(fown, struct file, f_owner); | 943 | file = container_of(fown, struct file, f_owner); |
925 | rc = smk_access(file->f_security, tsk->security, MAY_WRITE); | 944 | rc = smk_access(file->f_security, tsk->security, MAY_WRITE); |
926 | if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE)) | 945 | if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE)) |
927 | return 0; | 946 | return 0; |
928 | return rc; | 947 | return rc; |
929 | } | 948 | } |
@@ -1164,12 +1183,12 @@ static int smack_task_wait(struct task_struct *p) | |||
1164 | * account for the smack labels having gotten to | 1183 | * account for the smack labels having gotten to |
1165 | * be different in the first place. | 1184 | * be different in the first place. |
1166 | * | 1185 | * |
1167 | * This breaks the strict subjet/object access | 1186 | * This breaks the strict subject/object access |
1168 | * control ideal, taking the object's privilege | 1187 | * control ideal, taking the object's privilege |
1169 | * state into account in the decision as well as | 1188 | * state into account in the decision as well as |
1170 | * the smack value. | 1189 | * the smack value. |
1171 | */ | 1190 | */ |
1172 | if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE)) | 1191 | if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE)) |
1173 | return 0; | 1192 | return 0; |
1174 | 1193 | ||
1175 | return rc; | 1194 | return rc; |
@@ -2016,9 +2035,6 @@ static int smack_setprocattr(struct task_struct *p, char *name, | |||
2016 | { | 2035 | { |
2017 | char *newsmack; | 2036 | char *newsmack; |
2018 | 2037 | ||
2019 | if (!__capable(p, CAP_MAC_ADMIN)) | ||
2020 | return -EPERM; | ||
2021 | |||
2022 | /* | 2038 | /* |
2023 | * Changing another process' Smack value is too dangerous | 2039 | * Changing another process' Smack value is too dangerous |
2024 | * and supports no sane use case. | 2040 | * and supports no sane use case. |
@@ -2026,6 +2042,9 @@ static int smack_setprocattr(struct task_struct *p, char *name, | |||
2026 | if (p != current) | 2042 | if (p != current) |
2027 | return -EPERM; | 2043 | return -EPERM; |
2028 | 2044 | ||
2045 | if (!capable(CAP_MAC_ADMIN)) | ||
2046 | return -EPERM; | ||
2047 | |||
2029 | if (value == NULL || size == 0 || size >= SMK_LABELLEN) | 2048 | if (value == NULL || size == 0 || size >= SMK_LABELLEN) |
2030 | return -EINVAL; | 2049 | return -EINVAL; |
2031 | 2050 | ||
@@ -2552,7 +2571,8 @@ static void smack_release_secctx(char *secdata, u32 seclen) | |||
2552 | struct security_operations smack_ops = { | 2571 | struct security_operations smack_ops = { |
2553 | .name = "smack", | 2572 | .name = "smack", |
2554 | 2573 | ||
2555 | .ptrace = smack_ptrace, | 2574 | .ptrace_may_access = smack_ptrace_may_access, |
2575 | .ptrace_traceme = smack_ptrace_traceme, | ||
2556 | .capget = cap_capget, | 2576 | .capget = cap_capget, |
2557 | .capset_check = cap_capset_check, | 2577 | .capset_check = cap_capset_check, |
2558 | .capset_set = cap_capset_set, | 2578 | .capset_set = cap_capset_set, |
@@ -2729,4 +2749,3 @@ static __init int smack_init(void) | |||
2729 | * all processes and objects when they are created. | 2749 | * all processes and objects when they are created. |
2730 | */ | 2750 | */ |
2731 | security_initcall(smack_init); | 2751 | security_initcall(smack_init); |
2732 | |||