mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-27 00:51:35 +00:00
bpf: harden sockmap program attach to ensure correct map type
When attaching a program to sockmap we need to check map type
is correct.
Fixes: 174a79ff95
("bpf: sockmap with sk redirect support")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ed85054d34
commit
81374aaa26
3 changed files with 33 additions and 4 deletions
|
@ -794,6 +794,9 @@ int sock_map_attach_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type)
|
|||
struct bpf_stab *stab = container_of(map, struct bpf_stab, map);
|
||||
struct bpf_prog *orig;
|
||||
|
||||
if (unlikely(map->map_type != BPF_MAP_TYPE_SOCKMAP))
|
||||
return -EINVAL;
|
||||
|
||||
switch (type) {
|
||||
case BPF_SK_SKB_STREAM_PARSER:
|
||||
orig = xchg(&stab->bpf_parse, prog);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue