diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-08-15 18:32:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-08-15 18:32:13 -0400 |
commit | 71ef2a46fce43042a60d7ccbf55ecbd789c03c2e (patch) | |
tree | 247c3e25958ff362b8a7b5b735a1e7d2ef6842c7 | |
parent | d121db94eb50b29a202b5f6a8671cbebdf2c4142 (diff) | |
parent | 5cd9c58fbe9ec92b45b27e131719af4f2bd9eb40 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6:
security: Fix setting of PF_SUPERPRIV by __capable()
-rw-r--r-- | include/linux/capability.h | 15 | ||||
-rw-r--r-- | include/linux/security.h | 39 | ||||
-rw-r--r-- | kernel/capability.c | 21 | ||||
-rw-r--r-- | kernel/ptrace.c | 5 | ||||
-rw-r--r-- | mm/oom_kill.c | 6 | ||||
-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 |
11 files changed, 137 insertions, 63 deletions
diff --git a/include/linux/capability.h b/include/linux/capability.h index 02673846d205..9d1fe30b6f6c 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h | |||
@@ -503,8 +503,19 @@ extern const kernel_cap_t __cap_init_eff_set; | |||
503 | 503 | ||
504 | kernel_cap_t cap_set_effective(const kernel_cap_t pE_new); | 504 | kernel_cap_t cap_set_effective(const kernel_cap_t pE_new); |
505 | 505 | ||
506 | int capable(int cap); | 506 | /** |
507 | int __capable(struct task_struct *t, int cap); | 507 | * has_capability - Determine if a task has a superior capability available |
508 | * @t: The task in question | ||
509 | * @cap: The capability to be tested for | ||
510 | * | ||
511 | * Return true if the specified task has the given superior capability | ||
512 | * currently in effect, false if not. | ||
513 | * | ||
514 | * Note that this does not set PF_SUPERPRIV on the task. | ||
515 | */ | ||
516 | #define has_capability(t, cap) (security_capable((t), (cap)) == 0) | ||
517 | |||
518 | extern int capable(int cap); | ||
508 | 519 | ||
509 | #endif /* __KERNEL__ */ | 520 | #endif /* __KERNEL__ */ |
510 | 521 | ||
diff --git a/include/linux/security.h b/include/linux/security.h index fd96e7f8a6f9..2ee5ecfb2393 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -46,8 +46,8 @@ struct audit_krule; | |||
46 | */ | 46 | */ |
47 | extern int cap_capable(struct task_struct *tsk, int cap); | 47 | extern int cap_capable(struct task_struct *tsk, int cap); |
48 | extern int cap_settime(struct timespec *ts, struct timezone *tz); | 48 | extern int cap_settime(struct timespec *ts, struct timezone *tz); |
49 | extern int cap_ptrace(struct task_struct *parent, struct task_struct *child, | 49 | extern int cap_ptrace_may_access(struct task_struct *child, unsigned int mode); |
50 | unsigned int mode); | 50 | extern int cap_ptrace_traceme(struct task_struct *parent); |
51 | extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); | 51 | extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); |
52 | extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); | 52 | extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); |
53 | extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); | 53 | extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); |
@@ -1157,17 +1157,24 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1157 | * @alter contains the flag indicating whether changes are to be made. | 1157 | * @alter contains the flag indicating whether changes are to be made. |
1158 | * Return 0 if permission is granted. | 1158 | * Return 0 if permission is granted. |
1159 | * | 1159 | * |
1160 | * @ptrace: | 1160 | * @ptrace_may_access: |
1161 | * Check permission before allowing the @parent process to trace the | 1161 | * Check permission before allowing the current process to trace the |
1162 | * @child process. | 1162 | * @child process. |
1163 | * Security modules may also want to perform a process tracing check | 1163 | * Security modules may also want to perform a process tracing check |
1164 | * during an execve in the set_security or apply_creds hooks of | 1164 | * during an execve in the set_security or apply_creds hooks of |
1165 | * binprm_security_ops if the process is being traced and its security | 1165 | * binprm_security_ops if the process is being traced and its security |
1166 | * attributes would be changed by the execve. | 1166 | * attributes would be changed by the execve. |
1167 | * @parent contains the task_struct structure for parent process. | 1167 | * @child contains the task_struct structure for the target process. |
1168 | * @child contains the task_struct structure for child process. | ||
1169 | * @mode contains the PTRACE_MODE flags indicating the form of access. | 1168 | * @mode contains the PTRACE_MODE flags indicating the form of access. |
1170 | * Return 0 if permission is granted. | 1169 | * Return 0 if permission is granted. |
1170 | * @ptrace_traceme: | ||
1171 | * Check that the @parent process has sufficient permission to trace the | ||
1172 | * current process before allowing the current process to present itself | ||
1173 | * to the @parent process for tracing. | ||
1174 | * The parent process will still have to undergo the ptrace_may_access | ||
1175 | * checks before it is allowed to trace this one. | ||
1176 | * @parent contains the task_struct structure for debugger process. | ||
1177 | * Return 0 if permission is granted. | ||
1171 | * @capget: | 1178 | * @capget: |
1172 | * Get the @effective, @inheritable, and @permitted capability sets for | 1179 | * Get the @effective, @inheritable, and @permitted capability sets for |
1173 | * the @target process. The hook may also perform permission checking to | 1180 | * the @target process. The hook may also perform permission checking to |
@@ -1287,8 +1294,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) | |||
1287 | struct security_operations { | 1294 | struct security_operations { |
1288 | char name[SECURITY_NAME_MAX + 1]; | 1295 | char name[SECURITY_NAME_MAX + 1]; |
1289 | 1296 | ||
1290 | int (*ptrace) (struct task_struct *parent, struct task_struct *child, | 1297 | int (*ptrace_may_access) (struct task_struct *child, unsigned int mode); |
1291 | unsigned int mode); | 1298 | int (*ptrace_traceme) (struct task_struct *parent); |
1292 | int (*capget) (struct task_struct *target, | 1299 | int (*capget) (struct task_struct *target, |
1293 | kernel_cap_t *effective, | 1300 | kernel_cap_t *effective, |
1294 | kernel_cap_t *inheritable, kernel_cap_t *permitted); | 1301 | kernel_cap_t *inheritable, kernel_cap_t *permitted); |
@@ -1560,8 +1567,8 @@ extern struct dentry *securityfs_create_dir(const char *name, struct dentry *par | |||
1560 | extern void securityfs_remove(struct dentry *dentry); | 1567 | extern void securityfs_remove(struct dentry *dentry); |
1561 | 1568 | ||
1562 | /* Security operations */ | 1569 | /* Security operations */ |
1563 | int security_ptrace(struct task_struct *parent, struct task_struct *child, | 1570 | int security_ptrace_may_access(struct task_struct *child, unsigned int mode); |
1564 | unsigned int mode); | 1571 | int security_ptrace_traceme(struct task_struct *parent); |
1565 | int security_capget(struct task_struct *target, | 1572 | int security_capget(struct task_struct *target, |
1566 | kernel_cap_t *effective, | 1573 | kernel_cap_t *effective, |
1567 | kernel_cap_t *inheritable, | 1574 | kernel_cap_t *inheritable, |
@@ -1742,11 +1749,15 @@ static inline int security_init(void) | |||
1742 | return 0; | 1749 | return 0; |
1743 | } | 1750 | } |
1744 | 1751 | ||
1745 | static inline int security_ptrace(struct task_struct *parent, | 1752 | static inline int security_ptrace_may_access(struct task_struct *child, |
1746 | struct task_struct *child, | 1753 | unsigned int mode) |
1747 | unsigned int mode) | 1754 | { |
1755 | return cap_ptrace_may_access(child, mode); | ||
1756 | } | ||
1757 | |||
1758 | static inline int security_ptrace_traceme(struct task_struct *child) | ||
1748 | { | 1759 | { |
1749 | return cap_ptrace(parent, child, mode); | 1760 | return cap_ptrace_traceme(parent); |
1750 | } | 1761 | } |
1751 | 1762 | ||
1752 | static inline int security_capget(struct task_struct *target, | 1763 | static inline int security_capget(struct task_struct *target, |
diff --git a/kernel/capability.c b/kernel/capability.c index 0101e847603e..33e51e78c2d8 100644 --- a/kernel/capability.c +++ b/kernel/capability.c | |||
@@ -486,17 +486,22 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data) | |||
486 | return ret; | 486 | return ret; |
487 | } | 487 | } |
488 | 488 | ||
489 | int __capable(struct task_struct *t, int cap) | 489 | /** |
490 | * capable - Determine if the current task has a superior capability in effect | ||
491 | * @cap: The capability to be tested for | ||
492 | * | ||
493 | * Return true if the current task has the given superior capability currently | ||
494 | * available for use, false if not. | ||
495 | * | ||
496 | * This sets PF_SUPERPRIV on the task if the capability is available on the | ||
497 | * assumption that it's about to be used. | ||
498 | */ | ||
499 | int capable(int cap) | ||
490 | { | 500 | { |
491 | if (security_capable(t, cap) == 0) { | 501 | if (has_capability(current, cap)) { |
492 | t->flags |= PF_SUPERPRIV; | 502 | current->flags |= PF_SUPERPRIV; |
493 | return 1; | 503 | return 1; |
494 | } | 504 | } |
495 | return 0; | 505 | return 0; |
496 | } | 506 | } |
497 | |||
498 | int capable(int cap) | ||
499 | { | ||
500 | return __capable(current, cap); | ||
501 | } | ||
502 | EXPORT_SYMBOL(capable); | 507 | EXPORT_SYMBOL(capable); |
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 082b3fcb32a0..356699a96d56 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -140,7 +140,7 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode) | |||
140 | if (!dumpable && !capable(CAP_SYS_PTRACE)) | 140 | if (!dumpable && !capable(CAP_SYS_PTRACE)) |
141 | return -EPERM; | 141 | return -EPERM; |
142 | 142 | ||
143 | return security_ptrace(current, task, mode); | 143 | return security_ptrace_may_access(task, mode); |
144 | } | 144 | } |
145 | 145 | ||
146 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) | 146 | bool ptrace_may_access(struct task_struct *task, unsigned int mode) |
@@ -499,8 +499,7 @@ repeat: | |||
499 | goto repeat; | 499 | goto repeat; |
500 | } | 500 | } |
501 | 501 | ||
502 | ret = security_ptrace(current->parent, current, | 502 | ret = security_ptrace_traceme(current->parent); |
503 | PTRACE_MODE_ATTACH); | ||
504 | 503 | ||
505 | /* | 504 | /* |
506 | * Set the ptrace bit in the process ptrace flags. | 505 | * Set the ptrace bit in the process ptrace flags. |
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8a5467ee6265..64e5b4bcd964 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/notifier.h> | 27 | #include <linux/notifier.h> |
28 | #include <linux/memcontrol.h> | 28 | #include <linux/memcontrol.h> |
29 | #include <linux/security.h> | ||
29 | 30 | ||
30 | int sysctl_panic_on_oom; | 31 | int sysctl_panic_on_oom; |
31 | int sysctl_oom_kill_allocating_task; | 32 | int sysctl_oom_kill_allocating_task; |
@@ -128,7 +129,8 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
128 | * Superuser processes are usually more important, so we make it | 129 | * Superuser processes are usually more important, so we make it |
129 | * less likely that we kill those. | 130 | * less likely that we kill those. |
130 | */ | 131 | */ |
131 | if (__capable(p, CAP_SYS_ADMIN) || __capable(p, CAP_SYS_RESOURCE)) | 132 | if (has_capability(p, CAP_SYS_ADMIN) || |
133 | has_capability(p, CAP_SYS_RESOURCE)) | ||
132 | points /= 4; | 134 | points /= 4; |
133 | 135 | ||
134 | /* | 136 | /* |
@@ -137,7 +139,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
137 | * tend to only have this flag set on applications they think | 139 | * tend to only have this flag set on applications they think |
138 | * of as important. | 140 | * of as important. |
139 | */ | 141 | */ |
140 | if (__capable(p, CAP_SYS_RAWIO)) | 142 | if (has_capability(p, CAP_SYS_RAWIO)) |
141 | points /= 4; | 143 | points /= 4; |
142 | 144 | ||
143 | /* | 145 | /* |
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 ff7068727757..3a4b4f55b33f 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 3ae9bec5a508..03fc6a81ae32 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -1738,24 +1738,34 @@ static inline u32 file_to_av(struct file *file) | |||
1738 | 1738 | ||
1739 | /* Hook functions begin here. */ | 1739 | /* Hook functions begin here. */ |
1740 | 1740 | ||
1741 | static int selinux_ptrace(struct task_struct *parent, | 1741 | static int selinux_ptrace_may_access(struct task_struct *child, |
1742 | struct task_struct *child, | 1742 | unsigned int mode) |
1743 | unsigned int mode) | ||
1744 | { | 1743 | { |
1745 | int rc; | 1744 | int rc; |
1746 | 1745 | ||
1747 | rc = secondary_ops->ptrace(parent, child, mode); | 1746 | rc = secondary_ops->ptrace_may_access(child, mode); |
1748 | if (rc) | 1747 | if (rc) |
1749 | return rc; | 1748 | return rc; |
1750 | 1749 | ||
1751 | if (mode == PTRACE_MODE_READ) { | 1750 | if (mode == PTRACE_MODE_READ) { |
1752 | struct task_security_struct *tsec = parent->security; | 1751 | struct task_security_struct *tsec = current->security; |
1753 | struct task_security_struct *csec = child->security; | 1752 | struct task_security_struct *csec = child->security; |
1754 | return avc_has_perm(tsec->sid, csec->sid, | 1753 | return avc_has_perm(tsec->sid, csec->sid, |
1755 | SECCLASS_FILE, FILE__READ, NULL); | 1754 | SECCLASS_FILE, FILE__READ, NULL); |
1756 | } | 1755 | } |
1757 | 1756 | ||
1758 | return task_has_perm(parent, child, PROCESS__PTRACE); | 1757 | return task_has_perm(current, child, PROCESS__PTRACE); |
1758 | } | ||
1759 | |||
1760 | static int selinux_ptrace_traceme(struct task_struct *parent) | ||
1761 | { | ||
1762 | int rc; | ||
1763 | |||
1764 | rc = secondary_ops->ptrace_traceme(parent); | ||
1765 | if (rc) | ||
1766 | return rc; | ||
1767 | |||
1768 | return task_has_perm(parent, current, PROCESS__PTRACE); | ||
1759 | } | 1769 | } |
1760 | 1770 | ||
1761 | static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, | 1771 | static int selinux_capget(struct task_struct *target, kernel_cap_t *effective, |
@@ -5346,7 +5356,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) | |||
5346 | static struct security_operations selinux_ops = { | 5356 | static struct security_operations selinux_ops = { |
5347 | .name = "selinux", | 5357 | .name = "selinux", |
5348 | 5358 | ||
5349 | .ptrace = selinux_ptrace, | 5359 | .ptrace_may_access = selinux_ptrace_may_access, |
5360 | .ptrace_traceme = selinux_ptrace_traceme, | ||
5350 | .capget = selinux_capget, | 5361 | .capget = selinux_capget, |
5351 | .capset_check = selinux_capset_check, | 5362 | .capset_check = selinux_capset_check, |
5352 | .capset_set = selinux_capset_set, | 5363 | .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 | |||