Commit 876736a
random: add a spinlock_t to struct batched_entropy
[ Upstream commit b7d5dc21072cda7124d13eae2aefb7343ef94197 ]
The per-CPU variable batched_entropy_uXX is protected by get_cpu_var().
This is just a preempt_disable() which ensures that the variable is only
from the local CPU. It does not protect against users on the same CPU
from another context. It is possible that a preemptible context reads
slot 0 and then an interrupt occurs and the same value is read again.
The above scenario is confirmed by lockdep if we add a spinlock:
| ================================
| WARNING: inconsistent lock state
| 5.1.0-rc3+ #42 Not tainted
| --------------------------------
| inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
| ksoftirqd/9/56 [HC0[0]:SC1[1]:HE0:SE0] takes:
| (____ptrval____) (batched_entropy_u32.lock){+.?.}, at: get_random_u32+0x3e/0xe0
| {SOFTIRQ-ON-W} state was registered at:
| _raw_spin_lock+0x2a/0x40
| get_random_u32+0x3e/0xe0
| new_slab+0x15c/0x7b0
| ___slab_alloc+0x492/0x620
| __slab_alloc.isra.73+0x53/0xa0
| kmem_cache_alloc_node+0xaf/0x2a0
| copy_process.part.41+0x1e1/0x2370
| _do_fork+0xdb/0x6d0
| kernel_thread+0x20/0x30
| kthreadd+0x1ba/0x220
| ret_from_fork+0x3a/0x50
…
| other info that might help us debug this:
| Possible unsafe locking scenario:
|
| CPU0
| ----
| lock(batched_entropy_u32.lock);
| <Interrupt>
| lock(batched_entropy_u32.lock);
|
| *** DEADLOCK ***
|
| stack backtrace:
| Call Trace:
…
| kmem_cache_alloc_trace+0x20e/0x270
| ipmi_alloc_recv_msg+0x16/0x40
…
| __do_softirq+0xec/0x48d
| run_ksoftirqd+0x37/0x60
| smpboot_thread_fn+0x191/0x290
| kthread+0xfe/0x130
| ret_from_fork+0x3a/0x50
Add a spinlock_t to the batched_entropy data structure and acquire the
lock while accessing it. Acquire the lock with disabled interrupts
because this function may be used from interrupt context.
Remove the batched_entropy_reset_lock lock. Now that we have a lock for
the data scructure, we can access it from a remote CPU.
Signed-off-by: Sebastian Andrzej Siewior <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent 44ea43b commit 876736a
1 file changed
+27
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2228 | 2228 | | |
2229 | 2229 | | |
2230 | 2230 | | |
| 2231 | + | |
2231 | 2232 | | |
2232 | | - | |
2233 | 2233 | | |
2234 | 2234 | | |
2235 | 2235 | | |
| |||
2239 | 2239 | | |
2240 | 2240 | | |
2241 | 2241 | | |
2242 | | - | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
2243 | 2246 | | |
2244 | 2247 | | |
2245 | 2248 | | |
2246 | | - | |
2247 | | - | |
| 2249 | + | |
2248 | 2250 | | |
2249 | 2251 | | |
2250 | 2252 | | |
| |||
2259 | 2261 | | |
2260 | 2262 | | |
2261 | 2263 | | |
2262 | | - | |
2263 | | - | |
2264 | | - | |
2265 | | - | |
| 2264 | + | |
| 2265 | + | |
2266 | 2266 | | |
2267 | 2267 | | |
2268 | 2268 | | |
2269 | 2269 | | |
2270 | 2270 | | |
2271 | | - | |
2272 | | - | |
2273 | | - | |
| 2271 | + | |
2274 | 2272 | | |
2275 | 2273 | | |
2276 | 2274 | | |
2277 | 2275 | | |
2278 | | - | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
2279 | 2279 | | |
2280 | 2280 | | |
2281 | 2281 | | |
2282 | | - | |
2283 | | - | |
| 2282 | + | |
2284 | 2283 | | |
2285 | 2284 | | |
2286 | 2285 | | |
| |||
2289 | 2288 | | |
2290 | 2289 | | |
2291 | 2290 | | |
2292 | | - | |
2293 | | - | |
2294 | | - | |
2295 | | - | |
| 2291 | + | |
| 2292 | + | |
2296 | 2293 | | |
2297 | 2294 | | |
2298 | 2295 | | |
2299 | 2296 | | |
2300 | 2297 | | |
2301 | | - | |
2302 | | - | |
2303 | | - | |
| 2298 | + | |
2304 | 2299 | | |
2305 | 2300 | | |
2306 | 2301 | | |
| |||
2314 | 2309 | | |
2315 | 2310 | | |
2316 | 2311 | | |
2317 | | - | |
2318 | 2312 | | |
2319 | | - | |
2320 | | - | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
2321 | 2324 | | |
2322 | | - | |
2323 | 2325 | | |
2324 | 2326 | | |
2325 | 2327 | | |
| |||
0 commit comments