Skip to content

Commit d0f1a45

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: use array_index_nospec in find_prog_type
Commit 9ef09e3 ("bpf: fix possible spectre-v1 in find_and_alloc_map()") converted find_and_alloc_map() over to use array_index_nospec() to sanitize map type that user space passes on map creation, and this patch does an analogous conversion for progs in find_prog_type() as it's also passed from user space when loading progs as attr->prog_type. Signed-off-by: Daniel Borkmann <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 9ef09e3 commit d0f1a45

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel/bpf/syscall.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,17 @@ static const struct bpf_prog_ops * const bpf_prog_types[] = {
874874

875875
static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
876876
{
877-
if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type])
877+
const struct bpf_prog_ops *ops;
878+
879+
if (type >= ARRAY_SIZE(bpf_prog_types))
880+
return -EINVAL;
881+
type = array_index_nospec(type, ARRAY_SIZE(bpf_prog_types));
882+
ops = bpf_prog_types[type];
883+
if (!ops)
878884
return -EINVAL;
879885

880886
if (!bpf_prog_is_dev_bound(prog->aux))
881-
prog->aux->ops = bpf_prog_types[type];
887+
prog->aux->ops = ops;
882888
else
883889
prog->aux->ops = &bpf_offload_prog_ops;
884890
prog->type = type;

0 commit comments

Comments
 (0)