diff options
author | Yonghong Song <yhs@fb.com> | 2018-08-14 14:01:12 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-08-16 15:55:32 -0400 |
commit | 965931e3a803a506482616f89239eff6901c17b8 (patch) | |
tree | 22c2ccac1861446a76c794422aa6a57a7c360b69 | |
parent | 817b89beb9d8876450fcde9155e17425c329569d (diff) |
bpf: fix a rcu usage warning in bpf_prog_array_copy_core()
Commit 394e40a29788 ("bpf: extend bpf_prog_array to store pointers
to the cgroup storage") refactored the bpf_prog_array_copy_core()
to accommodate new structure bpf_prog_array_item which contains
bpf_prog array itself.
In the old code, we had
perf_event_query_prog_array():
mutex_lock(...)
bpf_prog_array_copy_call():
prog = rcu_dereference_check(array, 1)->progs
bpf_prog_array_copy_core(prog, ...)
mutex_unlock(...)
With the above commit, we had
perf_event_query_prog_array():
mutex_lock(...)
bpf_prog_array_copy_call():
bpf_prog_array_copy_core(array, ...):
item = rcu_dereference(array)->items;
...
mutex_unlock(...)
The new code will trigger a lockdep rcu checking warning.
The fix is to change rcu_dereference() to rcu_dereference_check()
to prevent such a warning.
Reported-by: syzbot+6e72317008eef84a216b@syzkaller.appspotmail.com
Fixes: 394e40a29788 ("bpf: extend bpf_prog_array to store pointers to the cgroup storage")
Cc: Roman Gushchin <guro@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | kernel/bpf/core.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 4d09e610777f..3f5bf1af0826 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
@@ -1579,7 +1579,7 @@ static bool bpf_prog_array_copy_core(struct bpf_prog_array __rcu *array, | |||
1579 | struct bpf_prog_array_item *item; | 1579 | struct bpf_prog_array_item *item; |
1580 | int i = 0; | 1580 | int i = 0; |
1581 | 1581 | ||
1582 | item = rcu_dereference(array)->items; | 1582 | item = rcu_dereference_check(array, 1)->items; |
1583 | for (; item->prog; item++) { | 1583 | for (; item->prog; item++) { |
1584 | if (item->prog == &dummy_bpf_prog.prog) | 1584 | if (item->prog == &dummy_bpf_prog.prog) |
1585 | continue; | 1585 | continue; |