mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
bpf: add missing rcu protection when releasing programs from prog_array
Normally the program attachment place (like sockets, qdiscs) takes
care of rcu protection and calls bpf_prog_put() after a grace period.
The programs stored inside prog_array may not be attached anywhere,
so prog_array needs to take care of preserving rcu protection.
Otherwise bpf_tail_call() will race with bpf_prog_put().
To solve that introduce bpf_prog_put_rcu() helper function and use
it in 3 places where unattached program can decrement refcnt:
closing program fd, deleting/replacing program in prog_array.
Fixes: 04fd61ab36
("bpf: allow bpf programs to tail-call other bpf programs")
Reported-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
d1f5f2bb91
commit
abf2e7d6e2
3 changed files with 25 additions and 4 deletions
|
@ -202,7 +202,7 @@ static int prog_array_map_update_elem(struct bpf_map *map, void *key,
|
|||
|
||||
old_prog = xchg(array->prog + index, prog);
|
||||
if (old_prog)
|
||||
bpf_prog_put(old_prog);
|
||||
bpf_prog_put_rcu(old_prog);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static int prog_array_map_delete_elem(struct bpf_map *map, void *key)
|
|||
|
||||
old_prog = xchg(array->prog + index, NULL);
|
||||
if (old_prog) {
|
||||
bpf_prog_put(old_prog);
|
||||
bpf_prog_put_rcu(old_prog);
|
||||
return 0;
|
||||
} else {
|
||||
return -ENOENT;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue