diff options
author | Greg Thelen <gthelen@google.com> | 2010-11-15 04:20:52 -0500 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2010-11-15 04:23:31 -0500 |
commit | d69b78ba1deaaa95ffa8dac5a9ca819ce454d52e (patch) | |
tree | 75b6df8731e08a102d54163b196835e189978fc1 /fs/ioprio.c | |
parent | 1ff5125fb85a46279421350eeaf812f728784d35 (diff) |
ioprio: grab rcu_read_lock in sys_ioprio_{set,get}()
Using:
- CONFIG_LOCKUP_DETECTOR=y
- CONFIG_PREEMPT=y
- CONFIG_LOCKDEP=y
- CONFIG_PROVE_LOCKING=y
- CONFIG_PROVE_RCU=y
found a missing rcu lock during boot on a 512 MiB x86_64 ubuntu vm:
===================================================
[ INFO: suspicious rcu_dereference_check() usage. ]
---------------------------------------------------
kernel/pid.c:419 invoked rcu_dereference_check() without protection!
other info that might help us debug this:
rcu_scheduler_active = 1, debug_locks = 0
1 lock held by ureadahead/1355:
#0: (tasklist_lock){.+.+..}, at: [<ffffffff8115bc09>] sys_ioprio_set+0x7f/0x29e
stack backtrace:
Pid: 1355, comm: ureadahead Not tainted 2.6.37-dbg-DEV #1
Call Trace:
[<ffffffff8109c10c>] lockdep_rcu_dereference+0xaa/0xb3
[<ffffffff81088cbf>] find_task_by_pid_ns+0x44/0x5d
[<ffffffff81088cfa>] find_task_by_vpid+0x22/0x24
[<ffffffff8115bc3e>] sys_ioprio_set+0xb4/0x29e
[<ffffffff8147cf21>] ? trace_hardirqs_off_thunk+0x3a/0x3c
[<ffffffff8105c409>] sysenter_dispatch+0x7/0x2c
[<ffffffff8147cee2>] ? trace_hardirqs_on_thunk+0x3a/0x3f
The fix is to:
a) grab rcu lock in sys_ioprio_{set,get}() and
b) avoid grabbing tasklist_lock.
Discussion in: http://marc.info/?l=linux-kernel&m=128951324702889
Signed-off-by: Greg Thelen <gthelen@google.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Modified by Jens to remove the now redundant inner rcu lock and
unlock since they are now protected by the outer lock.
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
Diffstat (limited to 'fs/ioprio.c')
-rw-r--r-- | fs/ioprio.c | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/fs/ioprio.c b/fs/ioprio.c index 2f7d05c89922..7da2a06508e5 100644 --- a/fs/ioprio.c +++ b/fs/ioprio.c | |||
@@ -103,22 +103,15 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio) | |||
103 | } | 103 | } |
104 | 104 | ||
105 | ret = -ESRCH; | 105 | ret = -ESRCH; |
106 | /* | 106 | rcu_read_lock(); |
107 | * We want IOPRIO_WHO_PGRP/IOPRIO_WHO_USER to be "atomic", | ||
108 | * so we can't use rcu_read_lock(). See re-copy of ->ioprio | ||
109 | * in copy_process(). | ||
110 | */ | ||
111 | read_lock(&tasklist_lock); | ||
112 | switch (which) { | 107 | switch (which) { |
113 | case IOPRIO_WHO_PROCESS: | 108 | case IOPRIO_WHO_PROCESS: |
114 | rcu_read_lock(); | ||
115 | if (!who) | 109 | if (!who) |
116 | p = current; | 110 | p = current; |
117 | else | 111 | else |
118 | p = find_task_by_vpid(who); | 112 | p = find_task_by_vpid(who); |
119 | if (p) | 113 | if (p) |
120 | ret = set_task_ioprio(p, ioprio); | 114 | ret = set_task_ioprio(p, ioprio); |
121 | rcu_read_unlock(); | ||
122 | break; | 115 | break; |
123 | case IOPRIO_WHO_PGRP: | 116 | case IOPRIO_WHO_PGRP: |
124 | if (!who) | 117 | if (!who) |
@@ -141,12 +134,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio) | |||
141 | break; | 134 | break; |
142 | 135 | ||
143 | do_each_thread(g, p) { | 136 | do_each_thread(g, p) { |
144 | int match; | 137 | if (__task_cred(p)->uid != who) |
145 | |||
146 | rcu_read_lock(); | ||
147 | match = __task_cred(p)->uid == who; | ||
148 | rcu_read_unlock(); | ||
149 | if (!match) | ||
150 | continue; | 138 | continue; |
151 | ret = set_task_ioprio(p, ioprio); | 139 | ret = set_task_ioprio(p, ioprio); |
152 | if (ret) | 140 | if (ret) |
@@ -160,7 +148,7 @@ free_uid: | |||
160 | ret = -EINVAL; | 148 | ret = -EINVAL; |
161 | } | 149 | } |
162 | 150 | ||
163 | read_unlock(&tasklist_lock); | 151 | rcu_read_unlock(); |
164 | return ret; | 152 | return ret; |
165 | } | 153 | } |
166 | 154 | ||
@@ -204,17 +192,15 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who) | |||
204 | int ret = -ESRCH; | 192 | int ret = -ESRCH; |
205 | int tmpio; | 193 | int tmpio; |
206 | 194 | ||
207 | read_lock(&tasklist_lock); | 195 | rcu_read_lock(); |
208 | switch (which) { | 196 | switch (which) { |
209 | case IOPRIO_WHO_PROCESS: | 197 | case IOPRIO_WHO_PROCESS: |
210 | rcu_read_lock(); | ||
211 | if (!who) | 198 | if (!who) |
212 | p = current; | 199 | p = current; |
213 | else | 200 | else |
214 | p = find_task_by_vpid(who); | 201 | p = find_task_by_vpid(who); |
215 | if (p) | 202 | if (p) |
216 | ret = get_task_ioprio(p); | 203 | ret = get_task_ioprio(p); |
217 | rcu_read_unlock(); | ||
218 | break; | 204 | break; |
219 | case IOPRIO_WHO_PGRP: | 205 | case IOPRIO_WHO_PGRP: |
220 | if (!who) | 206 | if (!who) |
@@ -241,12 +227,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who) | |||
241 | break; | 227 | break; |
242 | 228 | ||
243 | do_each_thread(g, p) { | 229 | do_each_thread(g, p) { |
244 | int match; | 230 | if (__task_cred(p)->uid != user->uid) |
245 | |||
246 | rcu_read_lock(); | ||
247 | match = __task_cred(p)->uid == user->uid; | ||
248 | rcu_read_unlock(); | ||
249 | if (!match) | ||
250 | continue; | 231 | continue; |
251 | tmpio = get_task_ioprio(p); | 232 | tmpio = get_task_ioprio(p); |
252 | if (tmpio < 0) | 233 | if (tmpio < 0) |
@@ -264,6 +245,6 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who) | |||
264 | ret = -EINVAL; | 245 | ret = -EINVAL; |
265 | } | 246 | } |
266 | 247 | ||
267 | read_unlock(&tasklist_lock); | 248 | rcu_read_unlock(); |
268 | return ret; | 249 | return ret; |
269 | } | 250 | } |