Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3960f4fd authored by Roman Gushchin's avatar Roman Gushchin Committed by Daniel Borkmann
Browse files

bpf: fix rcu annotations in compute_effective_progs()



The progs local variable in compute_effective_progs() is marked
as __rcu, which is not correct. This is a local pointer, which
is initialized by bpf_prog_array_alloc(), which also now
returns a generic non-rcu pointer.

The real rcu-protected pointer is *array (array is a pointer
to an RCU-protected pointer), so the assignment should be performed
using rcu_assign_pointer().

Fixes: 324bda9e ("bpf: multi program support for cgroup+bpf")
Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent d29ab6e1
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -95,7 +95,7 @@ static int compute_effective_progs(struct cgroup *cgrp,
				   enum bpf_attach_type type,
				   enum bpf_attach_type type,
				   struct bpf_prog_array __rcu **array)
				   struct bpf_prog_array __rcu **array)
{
{
	struct bpf_prog_array __rcu *progs;
	struct bpf_prog_array *progs;
	struct bpf_prog_list *pl;
	struct bpf_prog_list *pl;
	struct cgroup *p = cgrp;
	struct cgroup *p = cgrp;
	int cnt = 0;
	int cnt = 0;
@@ -120,13 +120,12 @@ static int compute_effective_progs(struct cgroup *cgrp,
					    &p->bpf.progs[type], node) {
					    &p->bpf.progs[type], node) {
				if (!pl->prog)
				if (!pl->prog)
					continue;
					continue;
				rcu_dereference_protected(progs, 1)->
				progs->progs[cnt++] = pl->prog;
					progs[cnt++] = pl->prog;
			}
			}
		p = cgroup_parent(p);
		p = cgroup_parent(p);
	} while (p);
	} while (p);


	*array = progs;
	rcu_assign_pointer(*array, progs);
	return 0;
	return 0;
}
}