bpf: Fix bpf_attr.attach_btf_id check
Only raw_tracepoint program type can have bpf_attr.attach_btf_id >= 0.
Make sure to reject other program types that accidentally set it to non-zero.
Fixes: ccfe29eb29
("bpf: Add attach_btf_id attribute to program load")
Reported-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20191018060933.2950231-1-ast@kernel.org
This commit is contained in:
parent
47a92ae074
commit
c108e3c1bd
|
@ -1570,6 +1570,17 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
|
||||||
enum bpf_attach_type expected_attach_type,
|
enum bpf_attach_type expected_attach_type,
|
||||||
u32 btf_id)
|
u32 btf_id)
|
||||||
{
|
{
|
||||||
|
switch (prog_type) {
|
||||||
|
case BPF_PROG_TYPE_RAW_TRACEPOINT:
|
||||||
|
if (btf_id > BTF_MAX_TYPE)
|
||||||
|
return -EINVAL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (btf_id)
|
||||||
|
return -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (prog_type) {
|
switch (prog_type) {
|
||||||
case BPF_PROG_TYPE_CGROUP_SOCK:
|
case BPF_PROG_TYPE_CGROUP_SOCK:
|
||||||
switch (expected_attach_type) {
|
switch (expected_attach_type) {
|
||||||
|
@ -1610,13 +1621,7 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
case BPF_PROG_TYPE_RAW_TRACEPOINT:
|
|
||||||
if (btf_id > BTF_MAX_TYPE)
|
|
||||||
return -EINVAL;
|
|
||||||
return 0;
|
|
||||||
default:
|
default:
|
||||||
if (btf_id)
|
|
||||||
return -EINVAL;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue