Repository navigation
Commit 709c162
kthread: Fix PF_KTHREAD vs to_kthread() race
commit 3a7956e upstream.
The kthread_is_per_cpu() construct relies on only being called on
PF_KTHREAD tasks (per the WARN in to_kthread). This gives rise to the
following usage pattern:
if ((p->flags & PF_KTHREAD) && kthread_is_per_cpu(p))
However, as reported by syzcaller, this is broken. The scenario is:
CPU0 CPU1 (running p)
(p->flags & PF_KTHREAD) // true
begin_new_exec()
me->flags &= ~(PF_KTHREAD|...);
kthread_is_per_cpu(p)
to_kthread(p)
WARN(!(p->flags & PF_KTHREAD) <-- *SPLAT*
Introduce __to_kthread() that omits the WARN and is sure to check both
values.
Use this to remove the problematic pattern for kthread_is_per_cpu()
and fix a number of other kthread_*() functions that have similar
issues but are currently not used in ways that would expose the
problem.
Notably kthread_func() is only ever called on 'current', while
kthread_probe_data() is only used for PF_WQ_WORKER, which implies the
task is from kthread_create*().
Fixes: ac687e6 ("kthread: Extract KTHREAD_IS_PER_CPU")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <Valentin.Schneider@arm.com>
Link: https://lkml.kernel.org/r/YH6WJc825C4P0FCK@hirez.programming.kicks-ass.net
[ Drop the balance_push() hunk as it is not needed. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent c43add2 commit 709c162
2 files changed
Lines changed: 28 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
87 | 106 | | |
88 | 107 | | |
89 | 108 | | |
| |||
168 | 187 | | |
169 | 188 | | |
170 | 189 | | |
171 | | - | |
172 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
173 | 193 | | |
174 | 194 | | |
175 | 195 | | |
| |||
199 | 219 | | |
200 | 220 | | |
201 | 221 | | |
202 | | - | |
| 222 | + | |
203 | 223 | | |
204 | 224 | | |
205 | | - | |
| 225 | + | |
| 226 | + | |
206 | 227 | | |
207 | 228 | | |
208 | 229 | | |
| |||
514 | 535 | | |
515 | 536 | | |
516 | 537 | | |
517 | | - | |
| 538 | + | |
518 | 539 | | |
519 | | - | |
| 540 | + | |
520 | 541 | | |
521 | 542 | | |
522 | 543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7569 | 7569 | | |
7570 | 7570 | | |
7571 | 7571 | | |
7572 | | - | |
| 7572 | + | |
7573 | 7573 | | |
7574 | 7574 | | |
7575 | 7575 | | |
| |||
0 commit comments