* [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY
@ 2018-04-23 17:09 Roman Gushchin
2018-04-23 20:05 ` Alexei Starovoitov
2018-04-23 21:28 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Roman Gushchin @ 2018-04-23 17:09 UTC (permalink / raw)
To: netdev; +Cc: kernel-team, Roman Gushchin, Alexei Starovoitov, Daniel Borkmann
Running bpf programs requires disabled preemption,
however at least some* of the BPF_PROG_RUN_ARRAY users
do not follow this rule.
To fix this bug, and also to make it not happen in the future,
let's add explicit preemption disabling/re-enabling
to the __BPF_PROG_RUN_ARRAY code.
* for example:
[ 17.624472] RIP: 0010:__cgroup_bpf_run_filter_sk+0x1c4/0x1d0
...
[ 17.640890] inet6_create+0x3eb/0x520
[ 17.641405] __sock_create+0x242/0x340
[ 17.641939] __sys_socket+0x57/0xe0
[ 17.642370] ? trace_hardirqs_off_thunk+0x1a/0x1c
[ 17.642944] SyS_socket+0xa/0x10
[ 17.643357] do_syscall_64+0x79/0x220
[ 17.643879] entry_SYSCALL_64_after_hwframe+0x42/0xb7
Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
---
include/linux/bpf.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 486e65e3db26..dc586cc64bc2 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -351,6 +351,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
struct bpf_prog **_prog, *__prog; \
struct bpf_prog_array *_array; \
u32 _ret = 1; \
+ preempt_disable(); \
rcu_read_lock(); \
_array = rcu_dereference(array); \
if (unlikely(check_non_null && !_array))\
@@ -362,6 +363,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
} \
_out: \
rcu_read_unlock(); \
+ preempt_enable_no_resched(); \
_ret; \
})
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY
2018-04-23 17:09 [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY Roman Gushchin
@ 2018-04-23 20:05 ` Alexei Starovoitov
2018-04-23 21:28 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2018-04-23 20:05 UTC (permalink / raw)
To: Roman Gushchin; +Cc: netdev, kernel-team, Alexei Starovoitov, Daniel Borkmann
On Mon, Apr 23, 2018 at 06:09:21PM +0100, Roman Gushchin wrote:
> Running bpf programs requires disabled preemption,
> however at least some* of the BPF_PROG_RUN_ARRAY users
> do not follow this rule.
>
> To fix this bug, and also to make it not happen in the future,
> let's add explicit preemption disabling/re-enabling
> to the __BPF_PROG_RUN_ARRAY code.
>
> * for example:
> [ 17.624472] RIP: 0010:__cgroup_bpf_run_filter_sk+0x1c4/0x1d0
> ...
> [ 17.640890] inet6_create+0x3eb/0x520
> [ 17.641405] __sock_create+0x242/0x340
> [ 17.641939] __sys_socket+0x57/0xe0
> [ 17.642370] ? trace_hardirqs_off_thunk+0x1a/0x1c
> [ 17.642944] SyS_socket+0xa/0x10
> [ 17.643357] do_syscall_64+0x79/0x220
> [ 17.643879] entry_SYSCALL_64_after_hwframe+0x42/0xb7
>
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY
2018-04-23 17:09 [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY Roman Gushchin
2018-04-23 20:05 ` Alexei Starovoitov
@ 2018-04-23 21:28 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-04-23 21:28 UTC (permalink / raw)
To: Roman Gushchin, netdev; +Cc: kernel-team, Alexei Starovoitov
On 04/23/2018 07:09 PM, Roman Gushchin wrote:
> Running bpf programs requires disabled preemption,
> however at least some* of the BPF_PROG_RUN_ARRAY users
> do not follow this rule.
>
> To fix this bug, and also to make it not happen in the future,
> let's add explicit preemption disabling/re-enabling
> to the __BPF_PROG_RUN_ARRAY code.
>
> * for example:
> [ 17.624472] RIP: 0010:__cgroup_bpf_run_filter_sk+0x1c4/0x1d0
> ...
> [ 17.640890] inet6_create+0x3eb/0x520
> [ 17.641405] __sock_create+0x242/0x340
> [ 17.641939] __sys_socket+0x57/0xe0
> [ 17.642370] ? trace_hardirqs_off_thunk+0x1a/0x1c
> [ 17.642944] SyS_socket+0xa/0x10
> [ 17.643357] do_syscall_64+0x79/0x220
> [ 17.643879] entry_SYSCALL_64_after_hwframe+0x42/0xb7
>
> Signed-off-by: Roman Gushchin <guro@fb.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
Applied to bpf, thanks Roman.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-23 21:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-23 17:09 [PATCH bpf] bpf: disable and restore preemption in __BPF_PROG_RUN_ARRAY Roman Gushchin
2018-04-23 20:05 ` Alexei Starovoitov
2018-04-23 21:28 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.