diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-30 21:07:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-30 21:07:13 -0400 |
commit | 3a0d1849432461eec1321f8918c6c13497d390c9 (patch) | |
tree | 694bafcc856b38ba99eb2172c8c5b061cfa0d529 /kernel | |
parent | 623ff7739e7c00fa3d55dbfd42a492a68298fd7a (diff) | |
parent | ec0c4274e33c0373e476b73e01995c53128f1257 (diff) |
Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull core locking updates from Thomas Gleixner.
* 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
futex: Mark get_robust_list as deprecated
futex: Do not leak robust list to unprivileged process
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/futex.c | 38 | ||||
-rw-r--r-- | kernel/futex_compat.c | 38 |
2 files changed, 30 insertions, 46 deletions
diff --git a/kernel/futex.c b/kernel/futex.c index 72efa1e4359a..e2b0fb9a0b3b 100644 --- a/kernel/futex.c +++ b/kernel/futex.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <linux/magic.h> | 59 | #include <linux/magic.h> |
60 | #include <linux/pid.h> | 60 | #include <linux/pid.h> |
61 | #include <linux/nsproxy.h> | 61 | #include <linux/nsproxy.h> |
62 | #include <linux/ptrace.h> | ||
62 | 63 | ||
63 | #include <asm/futex.h> | 64 | #include <asm/futex.h> |
64 | 65 | ||
@@ -2443,40 +2444,31 @@ SYSCALL_DEFINE3(get_robust_list, int, pid, | |||
2443 | { | 2444 | { |
2444 | struct robust_list_head __user *head; | 2445 | struct robust_list_head __user *head; |
2445 | unsigned long ret; | 2446 | unsigned long ret; |
2446 | const struct cred *cred = current_cred(), *pcred; | 2447 | struct task_struct *p; |
2447 | 2448 | ||
2448 | if (!futex_cmpxchg_enabled) | 2449 | if (!futex_cmpxchg_enabled) |
2449 | return -ENOSYS; | 2450 | return -ENOSYS; |
2450 | 2451 | ||
2452 | WARN_ONCE(1, "deprecated: get_robust_list will be deleted in 2013.\n"); | ||
2453 | |||
2454 | rcu_read_lock(); | ||
2455 | |||
2456 | ret = -ESRCH; | ||
2451 | if (!pid) | 2457 | if (!pid) |
2452 | head = current->robust_list; | 2458 | p = current; |
2453 | else { | 2459 | else { |
2454 | struct task_struct *p; | ||
2455 | |||
2456 | ret = -ESRCH; | ||
2457 | rcu_read_lock(); | ||
2458 | p = find_task_by_vpid(pid); | 2460 | p = find_task_by_vpid(pid); |
2459 | if (!p) | 2461 | if (!p) |
2460 | goto err_unlock; | 2462 | goto err_unlock; |
2461 | ret = -EPERM; | ||
2462 | pcred = __task_cred(p); | ||
2463 | /* If victim is in different user_ns, then uids are not | ||
2464 | comparable, so we must have CAP_SYS_PTRACE */ | ||
2465 | if (cred->user->user_ns != pcred->user->user_ns) { | ||
2466 | if (!ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE)) | ||
2467 | goto err_unlock; | ||
2468 | goto ok; | ||
2469 | } | ||
2470 | /* If victim is in same user_ns, then uids are comparable */ | ||
2471 | if (cred->euid != pcred->euid && | ||
2472 | cred->euid != pcred->uid && | ||
2473 | !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE)) | ||
2474 | goto err_unlock; | ||
2475 | ok: | ||
2476 | head = p->robust_list; | ||
2477 | rcu_read_unlock(); | ||
2478 | } | 2463 | } |
2479 | 2464 | ||
2465 | ret = -EPERM; | ||
2466 | if (!ptrace_may_access(p, PTRACE_MODE_READ)) | ||
2467 | goto err_unlock; | ||
2468 | |||
2469 | head = p->robust_list; | ||
2470 | rcu_read_unlock(); | ||
2471 | |||
2480 | if (put_user(sizeof(*head), len_ptr)) | 2472 | if (put_user(sizeof(*head), len_ptr)) |
2481 | return -EFAULT; | 2473 | return -EFAULT; |
2482 | return put_user(head, head_ptr); | 2474 | return put_user(head, head_ptr); |
diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c index 5f9e689dc8f0..83e368b005fc 100644 --- a/kernel/futex_compat.c +++ b/kernel/futex_compat.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <linux/compat.h> | 10 | #include <linux/compat.h> |
11 | #include <linux/nsproxy.h> | 11 | #include <linux/nsproxy.h> |
12 | #include <linux/futex.h> | 12 | #include <linux/futex.h> |
13 | #include <linux/ptrace.h> | ||
13 | 14 | ||
14 | #include <asm/uaccess.h> | 15 | #include <asm/uaccess.h> |
15 | 16 | ||
@@ -136,40 +137,31 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr, | |||
136 | { | 137 | { |
137 | struct compat_robust_list_head __user *head; | 138 | struct compat_robust_list_head __user *head; |
138 | unsigned long ret; | 139 | unsigned long ret; |
139 | const struct cred *cred = current_cred(), *pcred; | 140 | struct task_struct *p; |
140 | 141 | ||
141 | if (!futex_cmpxchg_enabled) | 142 | if (!futex_cmpxchg_enabled) |
142 | return -ENOSYS; | 143 | return -ENOSYS; |
143 | 144 | ||
145 | WARN_ONCE(1, "deprecated: get_robust_list will be deleted in 2013.\n"); | ||
146 | |||
147 | rcu_read_lock(); | ||
148 | |||
149 | ret = -ESRCH; | ||
144 | if (!pid) | 150 | if (!pid) |
145 | head = current->compat_robust_list; | 151 | p = current; |
146 | else { | 152 | else { |
147 | struct task_struct *p; | ||
148 | |||
149 | ret = -ESRCH; | ||
150 | rcu_read_lock(); | ||
151 | p = find_task_by_vpid(pid); | 153 | p = find_task_by_vpid(pid); |
152 | if (!p) | 154 | if (!p) |
153 | goto err_unlock; | 155 | goto err_unlock; |
154 | ret = -EPERM; | ||
155 | pcred = __task_cred(p); | ||
156 | /* If victim is in different user_ns, then uids are not | ||
157 | comparable, so we must have CAP_SYS_PTRACE */ | ||
158 | if (cred->user->user_ns != pcred->user->user_ns) { | ||
159 | if (!ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE)) | ||
160 | goto err_unlock; | ||
161 | goto ok; | ||
162 | } | ||
163 | /* If victim is in same user_ns, then uids are comparable */ | ||
164 | if (cred->euid != pcred->euid && | ||
165 | cred->euid != pcred->uid && | ||
166 | !ns_capable(pcred->user->user_ns, CAP_SYS_PTRACE)) | ||
167 | goto err_unlock; | ||
168 | ok: | ||
169 | head = p->compat_robust_list; | ||
170 | rcu_read_unlock(); | ||
171 | } | 156 | } |
172 | 157 | ||
158 | ret = -EPERM; | ||
159 | if (!ptrace_may_access(p, PTRACE_MODE_READ)) | ||
160 | goto err_unlock; | ||
161 | |||
162 | head = p->compat_robust_list; | ||
163 | rcu_read_unlock(); | ||
164 | |||
173 | if (put_user(sizeof(*head), len_ptr)) | 165 | if (put_user(sizeof(*head), len_ptr)) |
174 | return -EFAULT; | 166 | return -EFAULT; |
175 | return put_user(ptr_to_compat(head), head_ptr); | 167 | return put_user(ptr_to_compat(head), head_ptr); |