diff options
| author | Peter Zijlstra <peterz@infradead.org> | 2019-01-28 20:21:52 -0500 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-02-19 15:53:07 -0500 |
| commit | 568f196756ad9fe2b49c46bbf6a9de1b190438b4 (patch) | |
| tree | a8c84a1e56786296cd005d6c7ca7ad741c2367ea /kernel | |
| parent | a5d9265e017f081f0dc133c0e2f45103d027b874 (diff) | |
bpf: check that BPF programs run with preemption disabled
Introduce cant_sleep() macro for annotation of functions that
cannot sleep.
Use it in BPF_PROG_RUN to catch execution of BPF programs in
preemptable context.
Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/sched/core.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d8d76a65cfdd..7cbb5658be80 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
| @@ -6162,6 +6162,34 @@ void ___might_sleep(const char *file, int line, int preempt_offset) | |||
| 6162 | add_taint(TAINT_WARN, LOCKDEP_STILL_OK); | 6162 | add_taint(TAINT_WARN, LOCKDEP_STILL_OK); |
| 6163 | } | 6163 | } |
| 6164 | EXPORT_SYMBOL(___might_sleep); | 6164 | EXPORT_SYMBOL(___might_sleep); |
| 6165 | |||
| 6166 | void __cant_sleep(const char *file, int line, int preempt_offset) | ||
| 6167 | { | ||
| 6168 | static unsigned long prev_jiffy; | ||
| 6169 | |||
| 6170 | if (irqs_disabled()) | ||
| 6171 | return; | ||
| 6172 | |||
| 6173 | if (!IS_ENABLED(CONFIG_PREEMPT_COUNT)) | ||
| 6174 | return; | ||
| 6175 | |||
| 6176 | if (preempt_count() > preempt_offset) | ||
| 6177 | return; | ||
| 6178 | |||
| 6179 | if (time_before(jiffies, prev_jiffy + HZ) && prev_jiffy) | ||
| 6180 | return; | ||
| 6181 | prev_jiffy = jiffies; | ||
| 6182 | |||
| 6183 | printk(KERN_ERR "BUG: assuming atomic context at %s:%d\n", file, line); | ||
| 6184 | printk(KERN_ERR "in_atomic(): %d, irqs_disabled(): %d, pid: %d, name: %s\n", | ||
| 6185 | in_atomic(), irqs_disabled(), | ||
| 6186 | current->pid, current->comm); | ||
| 6187 | |||
| 6188 | debug_show_held_locks(current); | ||
| 6189 | dump_stack(); | ||
| 6190 | add_taint(TAINT_WARN, LOCKDEP_STILL_OK); | ||
| 6191 | } | ||
| 6192 | EXPORT_SYMBOL_GPL(__cant_sleep); | ||
| 6165 | #endif | 6193 | #endif |
| 6166 | 6194 | ||
| 6167 | #ifdef CONFIG_MAGIC_SYSRQ | 6195 | #ifdef CONFIG_MAGIC_SYSRQ |
