diff options
author | David Howells <dhowells@redhat.com> | 2008-08-14 06:37:28 -0400 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2008-08-14 08:59:43 -0400 |
commit | 5cd9c58fbe9ec92b45b27e131719af4f2bd9eb40 (patch) | |
tree | 8573db001b4dc3c2ad97102dda42b841c40b5f6c /security/selinux/hooks.c | |
parent | 8d0968abd03ec6b407df117adc773562386702fa (diff) |
security: Fix setting of PF_SUPERPRIV by __capable()
Fix the setting of PF_SUPERPRIV by __capable() as it could corrupt the flags
the target process if that is not the current process and it is trying to
change its own flags in a different way at the same time.
__capable() is using neither atomic ops nor locking to protect t->flags. This
patch removes __capable() and introduces has_capability() that doesn't set
PF_SUPERPRIV on the process being queried.
This patch further splits security_ptrace() in two:
(1) security_ptrace_may_access(). This passes judgement on whether one
process may access another only (PTRACE_MODE_ATTACH for ptrace() and
PTRACE_MODE_READ for /proc), and takes a pointer to the child process.
current is the parent.
(2) security_ptrace_traceme(). This passes judgement on PTRACE_TRACEME only,
and takes only a pointer to the parent process. current is the child.
In Smack and commoncap, this uses has_capability() to determine whether
the parent will be permitted to use PTRACE_ATTACH if normal checks fail.
This does not set PF_SUPERPRIV.
Two of the instances of __capable() actually only act on current, and so have
been changed to calls to capable().
Of the places that were using __capable():
(1) The OOM killer calls __capable() thrice when weighing the killability of a
process. All of these now use has_capability().
(2) cap_ptrace() and smack_ptrace() were using __capable() to check to see
whether the parent was allowed to trace any process. As mentioned above,
these have been split. For PTRACE_ATTACH and /proc, capable() is now
used, and for PTRACE_TRACEME, has_capability() is used.
(3) cap_safe_nice() only ever saw current, so now uses capable().
(4) smack_setprocattr() rejected accesses to tasks other than current just
after calling __capable(), so the order of these two tests have been
switched and capable() is used instead.
(5) In smack_file_send_sigiotask(), we need to allow privileged processes to
receive SIGIO on files they're manipulating.
(6) In smack_task_wait(), we let a process wait for a privileged process,
whether or not the process doing the waiting is privileged.
I've tested this with the LTP SELinux and syscalls testscripts.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Acked-by: Andrew G. Morgan <morgan@kernel.org>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 25 |
1 files changed, 18 insertions, 7 deletions
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, |