Messages in this thread Patch in this message | | | From | Roman Gushchin <> | Subject | [PATCH v2 bpf 5/5] bpf: add missing rcu_dereference() in bpf_prog_array_copy() | Date | Fri, 13 Jul 2018 12:41:14 -0700 |
| |
The old_array argument in bpf_prog_array_copy() is marked as __rcu, so the dereferencing should be performed using rcu_dereference(). As we do this a couple of times, and we want to be sure, that we copy a single array, let's safe the result of dereferencing in a local variable and use it further.
This fixes the following sparse warnings: kernel/bpf/core.c:1653:31: warning: incorrect type in assignment (different address spaces) kernel/bpf/core.c:1681:15: warning: incorrect type in assignment (different address spaces) kernel/bpf/core.c:1687:31: warning: incorrect type in assignment (different address spaces)
Fixes: e87c6bc3852b ("bpf: permit multiple bpf attachments for a single perf event") 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 +- kernel/bpf/core.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 329026baef6e..3cfc8095d2e0 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -363,7 +363,7 @@ void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs, int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array, u32 *prog_ids, u32 request_cnt, u32 *prog_cnt); -int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, +int bpf_prog_array_copy(struct bpf_prog_array __rcu *__old_array, struct bpf_prog *exclude_prog, struct bpf_prog *include_prog, struct bpf_prog_array **new_array); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 722ae6913dc0..26bdc99fc807 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1634,11 +1634,12 @@ void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs, } } -int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array, +int bpf_prog_array_copy(struct bpf_prog_array __rcu *__old_array, struct bpf_prog *exclude_prog, struct bpf_prog *include_prog, struct bpf_prog_array **new_array) { + struct bpf_prog_array *old_array = rcu_dereference(__old_array); int new_prog_cnt, carry_prog_cnt = 0; struct bpf_prog **existing_prog; struct bpf_prog_array *array; -- 2.14.4
| |