bpf: Fix preempt_enable_no_resched() abuse [Linux 5.1]

bpf: Fix preempt_enable_no_resched() abuse [Linux 5.1]

This Linux kernel change "bpf: Fix preempt_enable_no_resched() abuse" is included in the Linux 5.1 release. This change is authored by Peter Zijlstra <peterz [at] infradead.org> on Tue Apr 23 21:55:59 2019 +0200. The commit for this change in Linux stable tree is 0edd6b6 (patch).

bpf: Fix preempt_enable_no_resched() abuse

Unless the very next line is schedule(), or implies it, one must not use
preempt_enable_no_resched(). It can cause a preemption to go missing and
thereby cause arbitrary delays, breaking the PREEMPT=y invariant.

Cc: Roman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 include/linux/bpf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index f02367f..944ccc3 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -510,7 +510,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
        }                   \
 _out:                          \
        rcu_read_unlock();          \
-       preempt_enable_no_resched();        \
+       preempt_enable();           \
        _ret;                   \

Leave a Reply

Your email address will not be published. Required fields are marked *